Update Buyer Address (v1.0.0)

Update buyer address by buyer id if exists

Overview

This endpoint allows authenticated users to update their address information within the Ordering bounded context. In DDD terms, the Buyer is an aggregate root within the Ordering domain that contains Address as a value object.

The operation respects the invariants of the Buyer aggregate by ensuring that address changes are validated and consistently applied. Address updates are significant domain events as they can affect shipping options, tax calculations, and order fulfillment processes.

Implementation Details

When a buyer’s address is updated:

  1. The system retrieves the buyer ID from the authenticated user’s claims
  2. The buyer entity is fetched from the repository
  3. If the buyer doesn’t exist, a NotFoundException is thrown
  4. The UpdateAddress method on the Buyer entity is called with the new address details
  5. Changes are persisted through the Unit of Work pattern

Validation Rules

  • Street is required (maximum length: 50 characters)
  • City is required (maximum length: 50 characters)
  • Province is required (maximum length: 50 characters)

Architecture

PATCH (/api/v1/buyers/address)

Request

Example Usage

curl -X PATCH "https://api.bookworm.com/api/v1/buyers/address" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer <your-jwt-token>" \
    -d '{
        "street": "123 Main Street",
        "city": "New York",
        "province": "NY"
    }'

Responses

200 OK

Return buyer details with updated address.

Example response:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "name": "John Doe",
  "email": "john.doe@example.com",
  "address": {
    "street": "123 Main Street",
    "city": "New York",
    "province": "NY"
  }
}

400 Bad Request

Returned when the request validation fails.

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "Bad Request",
  "status": 400,
  "errors": {
    "Street": ["The Street field is required."],
    "City": ["The City field is required."],
    "Province": ["The Province field is required."]
  }
}

404 Not Found

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
  "title": "Not Found",
  "status": 404,
  "detail": "Buyer with id {id} not found."
}

401 Unauthorized

Returned when the request lacks valid authentication credentials.

3 properties
street string
required

The street address of the buyer

Min length: 1
Max length: 50
city string
required

The city of the buyer

Min length: 1
Max length: 50
province string
required

The province of the buyer

Min length: 1
Max length: 50
3 properties
id string <uuid>

The unique identifier of the buyer

name string

The name of the buyer

address string

The address of the buyer