Remove PATCH
This commit is contained in:
@@ -143,67 +143,6 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Patch (update) UserOptions
|
||||
/// </summary>
|
||||
/// <param name="id">UserId</param>
|
||||
/// <param name="concurrencyToken"></param>
|
||||
/// <param name="objectPatch"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPatch("{id}/{concurrencyToken}")]
|
||||
public async Task<IActionResult> PatchUserOptions([FromRoute] long id, [FromRoute] uint concurrencyToken, [FromBody]JsonPatchDocument<UserOptions> objectPatch)
|
||||
{
|
||||
if (!serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
var UserId = UserIdFromContext.Id(HttpContext.Items);
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserOptionsBiz biz = new UserOptionsBiz(ct, UserId, UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
var o = await ct.UserOptions.SingleOrDefaultAsync(m => m.UserId == id);
|
||||
|
||||
if (o == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (id != UserId && !Authorized.HasModifyRole(HttpContext.Items, AyaType.UserOptions))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
//patch and validate
|
||||
if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!UserOptionsExists(id))
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
else
|
||||
{
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool UserOptionsExists(long id)
|
||||
{
|
||||
//NOTE: checks by UserId, NOT by Id as in most other objects
|
||||
|
||||
Reference in New Issue
Block a user