-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Implement a POST /book endpoint that creates a new book record in the database. The endpoint must validate input and persist valid data.
User Story
Given I hit the /book endpoint with a POST request
When I provide valid book data
Then it should create a record in the database
Request Body
{
"id": 1,
"name": "Book Name",
"author": ["Author One"],
"price": 100,
"publisher": "Publisher Name"
}Validation Rules
-
id- Must be a number
-
name- Must be a string
- Required
-
author- Must be an array
- Required
-
price- Must be a number
- Required
- Must be >= 0 (no negative values)
-
publisher- Must be a string
- Optional
Tasks
- Create
/bookPOST route - Implement input validation logic
- Handle validation errors (return 400 with message)
- Connect to database
- Insert record into
bookstable - Return success response (201 Created)
- Add Swagger documentation for endpoint
- Define request body schema
- Add example payload
- Define responses (201, 400)
Acceptance Criteria
- Endpoint accepts valid JSON input
- Invalid input returns
400 Bad Request - Negative price is rejected
- Valid request creates a record in DB
- Response returns
201 Created - Swagger UI allows testing the endpoint
Testing Steps
-
Open Swagger UI
-
Send POST request to
/bookwith valid payload -
Verify response is
201 Created -
Run SQL query:
SELECT * FROM books ORDER BY id DESC LIMIT 1;
-
Confirm returned record matches inserted data
Definition of Done
- Endpoint implemented and working
- Validation is enforced
- Data persists correctly in DB
- Swagger docs updated
- Code is linted and formatted
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Projects
Status
In progress