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:
- The system retrieves the buyer ID from the authenticated user’s claims
- The buyer entity is fetched from the repository
- If the buyer doesn’t exist, a
NotFoundException
is thrown - The
UpdateAddress
method on the Buyer entity is called with the new address details - 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.
The street address of the buyer
1
50
The city of the buyer
1
50
The province of the buyer
1
50
No properties match your search
Try a different search term or clear the search to see all properties
The unique identifier of the buyer
The name of the buyer
The address of the buyer
No properties match your search
Try a different search term or clear the search to see all properties