Delete Buyer (v1.0.0)

Delete buyer by buyer id if exists

Overview

This endpoint allows for the removal of a Buyer aggregate from the system. In the Ordering domain, a Buyer represents a customer who has placed one or more orders. This operation is restricted to administrators only.

Architecture

Domain Significance

Within the bounded context of the Ordering domain, the Buyer aggregate root contains important customer information related to ordering, including:

  • Address information
  • Order history references
  • Payment methods

Command Handling

When this endpoint is called:

  1. A DeleteBuyerCommand is dispatched via the CQRS pattern with the Buyer ID
  2. The command handler retrieves the Buyer aggregate from the repository
  3. If the Buyer is not found, a NotFoundException is thrown
  4. If found, the Buyer is marked for deletion in the repository
  5. Changes are persisted through the Unit of Work pattern

Security Considerations

This endpoint is protected by the Admin authorization policy, ensuring that only administrators can delete buyer records. This is implemented through the .RequireAuthorization(Authorization.Policies.Admin) middleware.

Consistency Considerations

This operation maintains aggregate consistency through the Unit of Work pattern, ensuring that all changes are committed atomically. The operation either succeeds completely or fails without partial updates.

Error Handling

  • If the buyer with the specified ID does not exist, a 404 Not Found response is returned
  • Authorization failures result in a 401 Unauthorized or 403 Forbidden response
  • Other exceptions are handled by the global exception handler

DELETE (/api/v1/buyers/{id})

Parameters

  • id (path) (required): The buyer’s unique identifier (GUID format)

Example Usage

curl -X DELETE "https://api.bookworm.com/api/v1/buyers/{id}" \
    -H "Authorization: Bearer <your-jwt-token>"

Responses

204 No Content

The buyer was successfully deleted. No content is returned in the response body.

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.

403 Forbidden

Returned when the authenticated user does not have administrator privileges.