Overview
This endpoint enables the modification of an existing book entity in the catalog domain. Following Domain-Driven Design principles, it updates the aggregate root (Book) while maintaining its invariants and business rules. The operation is idempotent and will return appropriate error responses if the book ID does not exist or if business rules are violated. Updates will be propagated through domain events to maintain consistency across the system.
This endpoint respects the domain boundaries of the Catalog service and enables the modification of book attributes while preserving the entity’s identity and integrity.
Architecture
PUT (/api/v1/books/{id})
Parameters
- id (path) (required) - The unique identifier of the book to update (GUID format)
Request Body
The request should be sent as multipart/form-data
with the following fields:
Example Usage
curl -X PUT "https://api.bookworm.com/api/v1/books" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer <admin-token>" \
-F "Id=01961eb4-668d-7e7e-ae25-0fab379614f7" \
-F "name=Updated Book Name" \
-F "description=Updated Book Description" \
-F "price=19.99" \
-F "priceSale=14.99" \
-F "categoryId=123e4567-e89b-12d3-a456-426614174000" \
-F "publisherId=123e4567-e89b-12d3-a456-426614174000" \
-F "authorIds=123e4567-e89b-12d3-a456-426614174000,123e4567-e89b-12d3-a456-426614174001" \
-F "image=@/path/to/image.jpg"
Validation Rules
The following validation rules are applied to the request:
- Name: Required, maximum length of 100 characters
- Description: Optional, maximum length of 4000 characters
- Price: Required, must be greater than 0
- PriceSale: Optional, must be greater than 0 and less than or equal to the regular price
- CategoryId: Required, must be a valid GUID
- PublisherId: Required, must be a valid GUID
- AuthorIds: Required, must be a non-empty array of valid GUIDs
- Image: Optional, if provided:
- Maximum file size: 1MB (1048576 bytes)
- Allowed file types: JPEG and PNG only
Responses
204 No Content
The book was successfully updated. No content is returned in the response body.
400 Bad Request
The request is invalid. This can occur when:
- Validation rules are violated
- The provided data is in an incorrect format
- The image file exceeds size limits or is of an unsupported type
404 Not Found
The book with the specified ID does not exist in the system.
401 Unauthorized
The request is not authenticated. This endpoint requires admin privileges.
Domain Events
Upon successful update, the following domain events are triggered:
BookUpdatedEvent
: When the book’s name or description is modified- The book’s embedding in the vector database is automatically updated to reflect the changes
Product ID
Product name
1
100
Product description
500
Product price
0
Product sale price
0
ref:price
Category ID
Publisher ID
Product image
Is remove image
No properties match your search
Try a different search term or clear the search to see all properties
No properties match your search
Try a different search term or clear the search to see all properties