Imported from Vgoloshivskiy/BookingSystem (
.claude/skills/add-booking-endpoint/SKILL.md). Install upstream withnpx skills add Vgoloshivskiy/BookingSystem --skill add-booking-endpoint. Copyright stays with the author.
Adding a new endpoint to BookingSystem.Api
Follow this sequence so new endpoints match the codebase's conventions (see CLAUDE.md):
- DTOs first. Add request/response
recordtypes to the relevant file inDTOs/(e.g.BookingDtos.cs). Never expose an EF entity directly from a controller. - Service method. If the endpoint does anything beyond a simple CRUD read, add the
logic to the matching interface + implementation in
Services/(e.g.IBookingService/BookingService), not directly in the controller.- If the new logic reads then writes state that another request could also be
writing concurrently, do NOT use a plain read-then-write. Use an atomic
conditional
UPDATE ... WHERE(seeBookingService.CreateBookingAsync) or an EF Core concurrency token, and return a distinguishable "conflict" outcome rather than throwing.
- If the new logic reads then writes state that another request could also be
writing concurrently, do NOT use a plain read-then-write. Use an atomic
conditional
- Controller action. Thin method: model-bind the request DTO, call the service,
map the result to the response DTO / appropriate status code
(
Ok/Created/Conflict/NotFound— never a bare 500 for an expected outcome like "lost the race"). - Authorization. Add
[Authorize](already on the controller by default) and[Authorize(Roles = Roles.Admin)]on the action if it's an admin-only operation. - Test. Add an xUnit test in
BookingSystem.Testsfor the happy path and for the conflict/error path. If the endpoint touches shared mutable state (like a booking or slot), add or extend a concurrency test modeled onConcurrencyTests.cs: fire several requests withTask.WhenAlland assert exactly one wins. - Frontend (optional). If the endpoint needs a UI, add a small function to
frontend/app.jsfollowing the existingapi()helper pattern — no new frontend framework or build step.
Run dotnet build && dotnet test before considering the change done.