This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
//------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user