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="userId">User Id</param>
|
||||||
/// <param name="providerId">Id of Provider</param>
|
/// <param name="providerId">Id of Provider</param>
|
||||||
[ProducesResponseType(typeof(List<DeviceDetailDTO>), 200)]
|
[ProducesResponseType(typeof(List<DeviceDetailDTO>), 200)]
|
||||||
[HttpPost("fromProvider/{userId}")]
|
[HttpPost("{userId}/fromProvider/{providerId}")]
|
||||||
public async Task<ObjectResult> CreateDevicesFromProvider(string userId, string providerId)
|
public async Task<ObjectResult> CreateDevicesFromProvider(string userId, string providerId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace MyCore.Controllers
|
|||||||
/// Get all user providers
|
/// Get all user providers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ProducesResponseType(typeof(List<ProviderDTO>), 200)]
|
[ProducesResponseType(typeof(List<ProviderDTO>), 200)]
|
||||||
[HttpGet]
|
[HttpGet("{userId}")]
|
||||||
public ObjectResult GetAll(string userId)
|
public ObjectResult GetAll(string userId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -72,28 +72,27 @@ namespace MyCore.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a provider
|
/// Create a provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">User Id</param>
|
|
||||||
/// <param name="providerDTO">Provider to create</param>
|
/// <param name="providerDTO">Provider to create</param>
|
||||||
[ProducesResponseType(typeof(ProviderDTO), 200)]
|
[ProducesResponseType(typeof(ProviderDTO), 200)]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ObjectResult Create(string userId, [FromBody] ProviderDTO providerDTO)
|
public ObjectResult Create([FromBody] ProviderDTO providerDTO)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
if (userId == null)
|
if (providerDTO.UserId == null)
|
||||||
throw new InvalidOperationException("User not found");
|
throw new InvalidOperationException("User not found");
|
||||||
|
|
||||||
if (!UserService.IsExist(_UserDatabaseService, userId))
|
if (!UserService.IsExist(_UserDatabaseService, providerDTO.UserId))
|
||||||
throw new KeyNotFoundException("User not found");
|
throw new KeyNotFoundException("User not found");
|
||||||
|
|
||||||
if (providerDTO == null)
|
if (providerDTO == null)
|
||||||
throw new KeyNotFoundException("Provider is 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");
|
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);
|
return new OkObjectResult(providerCreated);
|
||||||
|
|
||||||
@ -119,24 +118,23 @@ namespace MyCore.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update a provider
|
/// Update a provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">User Id</param>
|
|
||||||
/// <param name="providerDTO">Provider to update</param>
|
/// <param name="providerDTO">Provider to update</param>
|
||||||
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
||||||
[HttpPut("{deviceId}")]
|
[HttpPut]
|
||||||
public ObjectResult Update(string userId, [FromBody] ProviderDTO providerDTO)
|
public ObjectResult Update([FromBody] ProviderDTO providerDTO)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (userId == null)
|
if (providerDTO.UserId == null)
|
||||||
throw new InvalidOperationException("User not found");
|
throw new InvalidOperationException("User not found");
|
||||||
|
|
||||||
if (!UserService.IsExist(_UserDatabaseService, userId))
|
if (!UserService.IsExist(_UserDatabaseService, providerDTO.UserId))
|
||||||
throw new KeyNotFoundException("User not found");
|
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");
|
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);
|
return new OkObjectResult(providerUpdated);
|
||||||
}
|
}
|
||||||
@ -163,11 +161,15 @@ namespace MyCore.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if exist
|
if (providerId == null)
|
||||||
// TODO
|
throw new InvalidOperationException("Provider is null");
|
||||||
// ProviderDatabaseService.Remove(providerId);
|
|
||||||
|
|
||||||
return new OkObjectResult(201);
|
if (!_ProviderDatabaseService.IsExist(providerId))
|
||||||
|
throw new InvalidOperationException("Provider is null");
|
||||||
|
|
||||||
|
_ProviderDatabaseService.Remove(providerId);
|
||||||
|
|
||||||
|
return new OkObjectResult(201);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user