Update Book (v1.0.0)

Update a book

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
10 properties
id string <uuid>
required

Product ID

name string
required

Product name

Min length: 1
Max length: 100
description string
required

Product description

Max length: 500
price number
required

Product price

Minimum: 0
priceSale number

Product sale price

Minimum: 0
Maximum: ref:price
categoryId string <uuid>
required

Category ID

publisherId string <uuid>
required

Publisher ID

authorIds array [string]
required
image string <binary>

Product image

isRemoveImage boolean

Is remove image

6 properties
type string
title string
status integer <int32>
detail string
instance string
errors object