This commit is contained in:
2020-07-21 14:07:47 +00:00
parent cd2c94b362
commit 42b9a59551
2 changed files with 25 additions and 1 deletions

View File

@@ -80,6 +80,30 @@ namespace AyaNova.Api.Controllers
return Ok(ApiOkResponse.Response(ret));
}
/// <summary>
/// Delete app Notification
/// </summary>
/// <param name="id"></param>
/// <returns>NoContent</returns>
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAppNotification([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var UserId = UserIdFromContext.Id(HttpContext.Items);
var n = await ct.Notification.FirstOrDefaultAsync(z => z.Id == id);
if (n == null)
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "id"));
if (n.UserId != UserId)
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_AUTHORIZED, "UserId", "Can't delete notification for another user"));
ct.Notification.Remove(n);
await ct.SaveChangesAsync();
return NoContent();
}
//------------