summaryrefslogtreecommitdiffstats
path: root/src/server/Api/V1/Entries/DeleteEntryRoute.cs
blob: fc790491bdf09c32139b3e501b405a6a534409ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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();
	}
}