summaryrefslogtreecommitdiffstats
path: root/src/server/Api/V1/Entries/DeleteEntryRoute.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-01-22 22:43:38 +0100
committerivarlovlie <git@ivarlovlie.no>2022-01-22 22:43:38 +0100
commit88110f536f9c3843ecf5016122e101f8a424af77 (patch)
treee8be4e77ccfb5ad37f49f89adad59ff12b4c85ea /src/server/Api/V1/Entries/DeleteEntryRoute.cs
downloadbookmark-thing-88110f536f9c3843ecf5016122e101f8a424af77.tar.xz
bookmark-thing-88110f536f9c3843ecf5016122e101f8a424af77.zip
Initial commit
Diffstat (limited to 'src/server/Api/V1/Entries/DeleteEntryRoute.cs')
-rw-r--r--src/server/Api/V1/Entries/DeleteEntryRoute.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/Api/V1/Entries/DeleteEntryRoute.cs b/src/server/Api/V1/Entries/DeleteEntryRoute.cs
new file mode 100644
index 0000000..fc79049
--- /dev/null
+++ b/src/server/Api/V1/Entries/DeleteEntryRoute.cs
@@ -0,0 +1,30 @@
+namespace IOL.BookmarkThing.Server.Api.V1.Entries;
+
+public class DeleteEntryRoute : RouteBaseV1Sync.WithRequest<Guid>.WithActionResult
+{
+ private readonly AppDbContext _context;
+
+ public DeleteEntryRoute(AppDbContext context) {
+ _context = context;
+ }
+
+ /// <summary>
+ /// Delete a entry
+ /// </summary>
+ /// <param name="entryId">The guid id of the entry to delete</param>
+ /// <response code="200">Entry deleted successfully</response>
+ /// <response code="404">Entry not found</response>
+ [ProducesResponseType(typeof(ErrorResult), 404)]
+ [ApiVersion(ApiSpecV1.VERSION_STRING)]
+ [HttpDelete("~/v{version:apiVersion}/entries/{entryId:guid}")]
+ public override ActionResult Handle(Guid entryId) {
+ 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();
+ }
+}