Implement an endpoint to fetch a single book by its ID. ### **User Story** **Given** a book exists **When** I request it by ID **Then** I should receive that book’s details ### **Endpoint** ``` GET /book/:id ``` ### **Tasks** * [x] Create `GET /book/:id` route * [x] Validate `id` param * [x] Fetch book from DB * [x] Handle not found case * [x] Return book data * [x] Add Swagger documentation * [x] Define path param * [x] Add responses (200, 404) ### **Acceptance Criteria** * [x] Valid ID returns `200 OK` with book * [x] Non-existent ID returns `404 Not Found` * [x] Invalid ID returns `400 Bad Request` * [x] Swagger UI supports testing ### **Testing Steps** * [x] Create a book * [x] Copy its `id` * [x] Send GET request: ``` /book/:id ``` * [x] Verify response is `200 OK` * [x] Test with invalid/non-existent ID → expect `404` ### **Definition of Done** * [x] Endpoint implemented * [x] Validation handled * [x] Error handling works * [x] Swagger docs updated * [x] Code linted and formatted
Implement an endpoint to fetch a single book by its ID.
User Story
Given a book exists
When I request it by ID
Then I should receive that book’s details
Endpoint
Tasks
Create
GET /book/:idrouteValidate
idparamFetch book from DB
Handle not found case
Return book data
Add Swagger documentation
Acceptance Criteria
200 OKwith book404 Not Found400 Bad RequestTesting Steps
Create a book
Copy its
idSend GET request:
Verify response is
200 OKTest with invalid/non-existent ID → expect
404Definition of Done