mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
Update provider controller
This commit is contained in:
parent
1647763c94
commit
eaaffaeeae
@ -125,7 +125,7 @@ namespace MyCore.Controllers
|
||||
/// <param name="userId">User Id</param>
|
||||
/// <param name="providerId">Id of Provider</param>
|
||||
[ProducesResponseType(typeof(List<DeviceDetailDTO>), 200)]
|
||||
[HttpPost("fromProvider/{userId}")]
|
||||
[HttpPost("{userId}/fromProvider/{providerId}")]
|
||||
public async Task<ObjectResult> CreateDevicesFromProvider(string userId, string providerId)
|
||||
{
|
||||
try
|
||||
|
||||
@ -38,7 +38,7 @@ namespace MyCore.Controllers
|
||||
/// Get all user providers
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<ProviderDTO>), 200)]
|
||||
[HttpGet]
|
||||
[HttpGet("{userId}")]
|
||||
public ObjectResult GetAll(string userId)
|
||||
{
|
||||
try
|
||||
@ -72,28 +72,27 @@ namespace MyCore.Controllers
|
||||
/// <summary>
|
||||
/// Create a provider
|
||||
/// </summary>
|
||||
/// <param name="userId">User Id</param>
|
||||
/// <param name="providerDTO">Provider to create</param>
|
||||
[ProducesResponseType(typeof(ProviderDTO), 200)]
|
||||
[HttpPost]
|
||||
public ObjectResult Create(string userId, [FromBody] ProviderDTO providerDTO)
|
||||
public ObjectResult Create([FromBody] ProviderDTO providerDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (userId == null)
|
||||
if (providerDTO.UserId == null)
|
||||
throw new InvalidOperationException("User not found");
|
||||
|
||||
if (!UserService.IsExist(_UserDatabaseService, userId))
|
||||
if (!UserService.IsExist(_UserDatabaseService, providerDTO.UserId))
|
||||
throw new KeyNotFoundException("User not found");
|
||||
|
||||
if (providerDTO == null)
|
||||
throw new KeyNotFoundException("Provider is null");
|
||||
|
||||
if (_ProviderDatabaseService.AlreadyExistForUser(userId, providerDTO.Name))
|
||||
if (_ProviderDatabaseService.AlreadyExistForUser(providerDTO.UserId, providerDTO.Name))
|
||||
throw new ArgumentException("Provider already exists");
|
||||
|
||||
ProviderDTO providerCreated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, userId, providerDTO, true);
|
||||
ProviderDTO providerCreated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, providerDTO.UserId, providerDTO, true);
|
||||
|
||||
return new OkObjectResult(providerCreated);
|
||||
|
||||
@ -119,24 +118,23 @@ namespace MyCore.Controllers
|
||||
/// <summary>
|
||||
/// Update a provider
|
||||
/// </summary>
|
||||
/// <param name="userId">User Id</param>
|
||||
/// <param name="providerDTO">Provider to update</param>
|
||||
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
||||
[HttpPut("{deviceId}")]
|
||||
public ObjectResult Update(string userId, [FromBody] ProviderDTO providerDTO)
|
||||
[HttpPut]
|
||||
public ObjectResult Update([FromBody] ProviderDTO providerDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (userId == null)
|
||||
if (providerDTO.UserId == null)
|
||||
throw new InvalidOperationException("User not found");
|
||||
|
||||
if (!UserService.IsExist(_UserDatabaseService, userId))
|
||||
if (!UserService.IsExist(_UserDatabaseService, providerDTO.UserId))
|
||||
throw new KeyNotFoundException("User not found");
|
||||
|
||||
if (!ProviderService.IsExist(this._ProviderDatabaseService, userId, providerDTO.Id))
|
||||
if (!ProviderService.IsExist(this._ProviderDatabaseService, providerDTO.UserId, providerDTO.Id))
|
||||
throw new KeyNotFoundException("Provider does not exist");
|
||||
|
||||
ProviderDTO providerUpdated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, userId, providerDTO, false);
|
||||
ProviderDTO providerUpdated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, providerDTO.UserId, providerDTO, false);
|
||||
|
||||
return new OkObjectResult(providerUpdated);
|
||||
}
|
||||
@ -163,11 +161,15 @@ namespace MyCore.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if exist
|
||||
// TODO
|
||||
// ProviderDatabaseService.Remove(providerId);
|
||||
if (providerId == null)
|
||||
throw new InvalidOperationException("Provider is null");
|
||||
|
||||
return new OkObjectResult(201);
|
||||
if (!_ProviderDatabaseService.IsExist(providerId))
|
||||
throw new InvalidOperationException("Provider is null");
|
||||
|
||||
_ProviderDatabaseService.Remove(providerId);
|
||||
|
||||
return new OkObjectResult(201);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user