Problem statement
Connect the parts of a coffee shop ordering API using constructor injection.
Requirements
The receipt logic, request validation, the Menu and error handling are already provided. Your task is to connect the classes using constructor injection.
OrderService
- Inject Menu through the constructor
- The provided receipt logic uses the injected Menu to look up items and prices
OrderController
- Inject OrderService through the constructor
- Once it is injected, POST /orders returns the receipt
Sample Requests & Responses
POST /orders
Request:
{
"items": [
{ "name": "Espresso", "quantity": 2 },
{ "name": "Latte", "quantity": 1 }
]
}
Response (200 OK):
Espresso x2 $5.00 Latte x1 $3.75 TOTAL $8.75
POST /orders
Request:
{
"items": [
{ "name": "Americano", "quantity": 1 }
]
}
Response (200 OK):
Americano x1 $3.00 TOTAL $3.00
POST /orders
Request:
{
"items": [
{ "name": "Flat White", "quantity": 1 }
]
}
Response (400 Bad Request):
{
"error": "Unknown menu item: Flat White",
"timestamp": "2026-07-20T11:27:49.607337",
"path": "/orders"
}
POST /orders
Request:
{
"items": [
{ "name": "Espresso", "quantity": 0 }
]
}
Response (400 Bad Request):
{
"error": "Quantity must be at least 1",
"timestamp": "2026-07-20T11:27:49.628058",
"path": "/orders"
}
