API Architecture
The Ordering API uses:- Carter: Minimal API endpoint organization
- MediatR: Command/query dispatch
- Mapster: Object mapping
- FluentValidation: Automatic request validation
- Problem Details: Standardized error responses
Base URL
Authentication
The API currently does not require authentication. In production, integrate with identity service.Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
| POST | /orders | Create a new order |
| PUT | /orders | Update an existing order |
| DELETE | /orders/{id} | Delete an order |
| GET | /orders | Get all orders (paginated) |
| GET | /orders/customer/{customerId} | Get orders by customer ID |
| GET | /orders/{orderName} | Search orders by name |
Create Order
Creates a new order.Endpoint
Request Body
Response
Status:201 Created
Location Header: /orders/{id}
Implementation
See Ordering.API/Endpoints/CreateOrder.cs:13:Validation Rules
orderName: Required, not emptycustomerId: Required, not nullorderItems: Required, at least one item- Address fields validated by domain value objects
- Payment CVV must be 3 characters or less
Error Responses
400 Bad Request - Validation failure:Update Order
Updates an existing order.Endpoint
Request Body
Response
Status:200 OK
Implementation
See Ordering.API/Endpoints/UpdateOrder.cs:13:Validation Rules
id: Required, not emptyorderName: Required, not emptycustomerId: Required, not null
Error Responses
404 Not Found - Order does not exist:Delete Order
Deletes an order by ID.Endpoint
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | Guid | Order identifier |
Response
Status:200 OK
Implementation
See Ordering.API/Endpoints/DeleteOrder.cs:13:Validation Rules
id: Required, not empty
Error Responses
404 Not Found - Order does not exist:Get Orders (Paginated)
Retrieves all orders with pagination.Endpoint
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pageIndex | int | No | 0 | Zero-based page index |
pageSize | int | No | 10 | Number of items per page |
Response
Status:200 OK
Implementation
See Ordering.API/Endpoints/GetOrders.cs:13:Response Fields
PaginatedResult:pageIndex: Current page (zero-based)pageSize: Items per pagecount: Total number of ordersdata: Array of order DTOs
1: Draft2: Pending3: Completed4: Cancelled
Get Orders By Customer
Retrieves all orders for a specific customer.Endpoint
Path Parameters
| Parameter | Type | Description |
|---|---|---|
customerId | Guid | Customer identifier |
Response
Status:200 OK
Implementation
See Ordering.API/Endpoints/GetOrdersByCustomer.cs:12:Notes
- Returns empty array if customer has no orders
- Includes all order items
- Sorted by order name
Get Orders By Name
Searches orders by name (partial match).Endpoint
Path Parameters
| Parameter | Type | Description |
|---|---|---|
orderName | string | Order name search term (partial match) |
Response
Status:200 OK
Implementation
See Ordering.API/Endpoints/GetOrdersByName.cs:12:Notes
- Performs case-sensitive partial match (contains)
- Returns empty array if no matches found
- Includes all order items
- Sorted by order name
Data Models
OrderDto
AddressDto
PaymentDto
OrderItemDto
PaginatedResult
Error Handling
All endpoints return standardized Problem Details responses for errors.Validation Error (400)
Not Found Error (404)
Internal Server Error (500)
Rate Limiting
Currently not implemented. Consider adding rate limiting for production.Testing with cURL
Create Order
Get Orders
Get Orders By Customer
Delete Order
Integration Events
Consumed Events
BasketCheckoutEvent - Published by Basket service Triggered when customer completes checkout. Automatically creates an order. Event Structure:Published Events
OrderDto (Order Created) - Published to message broker Published when new order is created (feature flag controlled). Feature Flag:OrderFullfilment
Event Structure: Same as OrderDto model above
Performance Considerations
Query Optimization
- All queries use
AsNoTracking()for read operations - Related entities eager loaded with
Include() - Pagination prevents large result sets
Caching Strategy
Consider adding caching for:- Customer order lists
- Order details (short TTL)
- Product reference data
Database Indexing
Recommended indexes:Next Steps
- Overview - Architecture and service responsibilities
- Domain Model - Domain entities and business logic
- Application Layer - CQRS implementation details
