using IOL.BookmarkThing.Server.Api.V1.Entries.Dtos; namespace IOL.BookmarkThing.Server.Api.V1.Entries; public class CreateEntryRoute : RouteBaseV1Sync.WithRequest.WithActionResult { private readonly AppDbContext _context; public CreateEntryRoute(AppDbContext context) { _context = context; } /// /// Create a new entry /// /// The entry to create /// Entry created successfully /// Invalid entry [ProducesResponseType(typeof(EntryDto), 200)] [ProducesResponseType(typeof(List), 400)] [ApiVersion(ApiSpecV1.VERSION_STRING)] [HttpPost("~/v{version:apiVersion}/entries/create")] public override ActionResult Handle(CreateEntryRequest entry) { if (IsApiCall() && !HasApiPermission(Constants.TOKEN_ALLOW_CREATE)) { return StatusCode(403, "Your token does not permit access to this resource"); } var errors = entry.GetErrors(); if (errors.Count != 0) { return BadRequest(errors); } var dbEntry = entry.AsDbEntity(LoggedInUser.Id); _context.Entries.Add(dbEntry); _context.SaveChanges(); return Ok(new EntryDto(dbEntry)); } }