namespace IOL.BookmarkThing.Server.Api.V1.Entries; public class DeleteEntryRoute : RouteBaseV1Sync.WithRequest.WithActionResult { private readonly AppDbContext _context; public DeleteEntryRoute(AppDbContext context) { _context = context; } /// /// Delete a entry /// /// The guid id of the entry to delete /// Entry deleted successfully /// Entry not found [ProducesResponseType(typeof(ErrorResult), 404)] [ApiVersion(ApiSpecV1.VERSION_STRING)] [HttpDelete("~/v{version:apiVersion}/entries/{entryId:guid}")] public override ActionResult Handle(Guid entryId) { if (IsApiCall() && !HasApiPermission(Constants.TOKEN_ALLOW_DELETE)) { return StatusCode(403, "Your token does not permit access to this resource"); } var entry = _context.Entries.SingleOrDefault(c => c.Id == entryId && c.UserId == LoggedInUser.Id); if (entry == default) { return NotFound(new ErrorResult("Entry does not exist")); } _context.Remove(entry); _context.SaveChanges(); return Ok(); } }