Skip to content

Commit e971ae7

Browse files
committed
feat: add burger order limits
1 parent 829ad61 commit e971ae7

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

packages/burger-api/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ You can view the complete API documentation by opening the [Swagger Editor](http
5858

5959
### Order Limits
6060

61-
A user can have a maximum of **5 active orders** (status: `pending` or `in-preparation`) at a time. If you try to place more, the API will return:
61+
A user can have a maximum of **5 active orders** (status: `pending` or `in-preparation`) at a time. Additionally, a single order cannot exceed **50 burgers** in total across all items.
6262

63-
- HTTP 429 Too Many Requests
64-
- Body: `{ "error": "Too many active orders: limit is 5 per user" }`
65-
66-
This ensures fair use and prevents abuse.
63+
These limits ensure fair use and prevent abuse.
6764

6865
### Order Status Automation
6966

packages/burger-api/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ paths:
110110
description: |
111111
Places a new order with burgers (requires userId).
112112
French fries are included as a side for every burger order.
113+
114+
Limitations:
115+
- Maximum 5 active orders per user
116+
- Maximum 50 burgers total per order
113117
operationId: createOrder
114118
requestBody:
115119
required: true
@@ -536,6 +540,7 @@ components:
536540
example: "user123"
537541
items:
538542
type: array
543+
description: List of burger items (maximum 50 burgers total across all items)
539544
items:
540545
type: object
541546
properties:

packages/burger-api/src/functions/orders-post.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ app.http('orders-post', {
6767
const orderItems: OrderItem[] = [];
6868
let totalPrice = 0;
6969

70+
// Calculate total burger count and validate limit
71+
const totalBurgerCount = requestBody.items.reduce((sum, item) => sum + item.quantity, 0);
72+
if (totalBurgerCount > 50) {
73+
return {
74+
status: 400,
75+
jsonBody: { error: 'Order cannot exceed 50 burgers in total' }
76+
};
77+
}
78+
7079
for (const item of requestBody.items) {
7180

7281
// Validate quantity is a positive integer

0 commit comments

Comments
 (0)