Complete API documentation for the Orders endpoints of the PC Components Store API.
All order endpoints require authentication. Include the token in the Authorization header:
Authorization: Bearer YOUR_JWT_TOKEN
Customers: Can only view and create their own orders
Admins: Can view all orders and update order statuses
GET /api/orders
Retrieve orders. Admin sees all orders; customers see only their own.
Authorization: Bearer token required
HTTP/1.1 200 OK
[
{
"id": 1,
"userId": 5,
"userEmail": "customer@example.com",
"orderDate": "2024-01-10T14:30:00Z",
"totalAmount": 1299.98,
"status": "processing",
"shippedAt": null,
"deliveredAt": null,
"orderItems": [
{
"id": 1,
"productId": 1,
"productName": "Intel Core i7-12700K",
"quantity": 1,
"unitPrice": 409.99,
"subtotal": 409.99
},
{
"id": 2,
"productId": 5,
"productName": "NVIDIA GeForce RTX 3080",
"quantity": 1,
"unitPrice": 699.99,
"subtotal": 699.99
}
]
}
]
Success Response (Customer)
HTTP/1.1 200 OK
[
{
"id": 1,
"userId": 5,
"userEmail": "customer@example.com",
"orderDate": "2024-01-10T14:30:00Z",
"totalAmount": 1299.98,
"status": "processing",
"shippedAt": null,
"deliveredAt": null,
"orderItems": [
{
"id": 1,
"productId": 1,
"productName": "Intel Core i7-12700K",
"quantity": 1,
"unitPrice": 409.99,
"subtotal": 409.99
}
]
}
]
Response Schema (OrderDto)
Field
Type
Description
id
int
Order ID
userId
int
User ID who placed the order
userEmail
string?
User email
orderDate
DateTime
Order creation timestamp
totalAmount
decimal
Total order amount
status
string
Order status (see Status Values below)
shippedAt
DateTime?
Shipment timestamp (null if not shipped)
deliveredAt
DateTime?
Delivery timestamp (null if not delivered)
orderItems
OrderItemDto[]
List of order items
Response Schema (OrderItemDto)
Field
Type
Description
id
int
Order item ID
productId
int
Product ID
productName
string?
Product name
quantity
int
Quantity ordered
unitPrice
decimal
Price per unit at order time
subtotal
decimal
Computed: quantity × unitPrice
# Admin: View all orders
curl http://localhost:8080/api/orders \
-H " Authorization: Bearer YOUR_ADMIN_TOKEN"
# Customer: View own orders
curl http://localhost:8080/api/orders \
-H " Authorization: Bearer YOUR_CUSTOMER_TOKEN"
GET /api/orders/{id}
Retrieve a specific order. Admin can access any order; customers can only access their own.
Authorization: Bearer token required
Parameter
Type
Required
Description
id
int
Yes
Order ID
HTTP/1.1 200 OK
{
"id": 1,
"userId": 5,
"userEmail": "customer@example.com",
"orderDate": "2024-01-10T14:30:00Z",
"totalAmount": 1299.98,
"status": "processing",
"shippedAt": null,
"deliveredAt": null,
"orderItems": [
{
"id": 1,
"productId": 1,
"productName": "Intel Core i7-12700K",
"quantity": 1,
"unitPrice": 409.99,
"subtotal": 409.99
}
]
}
Status Code
Description
404 Not Found
Order does not exist
401 Unauthorized
Missing or invalid token
403 Forbidden
Customer trying to access another user's order
curl http://localhost:8080/api/orders/1 \
-H " Authorization: Bearer YOUR_TOKEN"
POST /api/orders
Create a new order. Requires authentication.
Authorization: Bearer token required
{
"items" : [
{
"productId" : 1 ,
"quantity" : 2
},
{
"productId" : 5 ,
"quantity" : 1
}
]
}
Request Schema (CreateOrderRequest)
Field
Type
Required
Description
items
OrderItemRequest[]
Yes
List of items to order
Request Schema (OrderItemRequest)
Field
Type
Required
Description
productId
int
Yes
Product ID
quantity
int
Yes
Quantity to order (must be > 0)
HTTP/1.1 201 Created
{
"id": 10,
"userId": 5,
"userEmail": "customer@example.com",
"orderDate": "2024-01-15T10:30:00Z",
"totalAmount": 1219.97,
"status": "pending",
"shippedAt": null,
"deliveredAt": null,
"orderItems": [
{
"id": 20,
"productId": 1,
"productName": "Intel Core i7-12700K",
"quantity": 2,
"unitPrice": 409.99,
"subtotal": 819.98
},
{
"id": 21,
"productId": 5,
"productName": "NVIDIA GeForce RTX 3080",
"quantity": 1,
"unitPrice": 699.99,
"subtotal": 699.99
}
]
}
Status Code
Description
400 Bad Request
Product not found, insufficient stock, or invalid quantity
401 Unauthorized
Missing or invalid token
Stock is automatically decremented when order is created
If any product has insufficient stock, the entire order is rejected
curl -X POST http://localhost:8080/api/orders \
-H " Content-Type: application/json" \
-H " Authorization: Bearer YOUR_CUSTOMER_TOKEN" \
-d ' {
"items": [
{
"productId": 1,
"quantity": 2
},
{
"productId": 5,
"quantity": 1
}
]
}'
Update Order Status (Admin Only)
PATCH /api/orders/{id}/status
Update the status of an order. Requires admin role.
Authorization: Bearer token with "admin" role
Parameter
Type
Required
Description
id
int
Yes
Order ID
Request Schema (UpdateOrderStatusRequest)
Field
Type
Required
Description
status
string
Yes
New order status
Status
Description
pending
Order received, awaiting processing
processing
Order is being prepared
shipped
Order has been shipped
delivered
Order has been delivered
cancelled
Order has been cancelled
Setting status to shipped automatically sets shippedAt to current UTC time
Setting status to delivered automatically sets deliveredAt to current UTC time
HTTP/1.1 200 OK
{
"message": "Order status updated successfully"
}
Status Code
Description
404 Not Found
Order does not exist
400 Bad Request
Invalid status value
401 Unauthorized
Missing or invalid token
403 Forbidden
User is not an admin
# Update order status to shipped
curl -X PATCH http://localhost:8080/api/orders/1/status \
-H " Content-Type: application/json" \
-H " Authorization: Bearer YOUR_ADMIN_TOKEN" \
-d ' {
"status": "shipped"
}'
{
"items" : [
{
"productId" : 1 ,
"quantity" : 2
},
{
"productId" : 5 ,
"quantity" : 1
}
]
}
Field
Type
Required
Description
items
OrderItemRequest[]
Yes
List of items to order
{
"productId" : 1 ,
"quantity" : 2
}
Field
Type
Required
Validation
productId
int
Yes
Must exist
quantity
int
Yes
Must be > 0
Field
Type
Required
Validation
status
string
Yes
One of: pending, processing, shipped, delivered, cancelled
{
"id" : 1 ,
"userId" : 5 ,
"userEmail" : " customer@example.com" ,
"orderDate" : " 2024-01-10T14:30:00Z" ,
"totalAmount" : 1299.98 ,
"status" : " processing" ,
"shippedAt" : null ,
"deliveredAt" : null ,
"orderItems" : [
{
"id" : 1 ,
"productId" : 1 ,
"productName" : " Intel Core i7-12700K" ,
"quantity" : 1 ,
"unitPrice" : 409.99 ,
"subtotal" : 409.99
}
]
}
Field
Type
Description
id
int
Order ID
userId
int
User ID who placed the order
userEmail
string?
User email
orderDate
DateTime
Order creation timestamp
totalAmount
decimal
Total order amount
status
string
Order status
shippedAt
DateTime?
Shipment timestamp (null if not shipped)
deliveredAt
DateTime?
Delivery timestamp (null if not delivered)
orderItems
OrderItemDto[]
List of order items
{
"id" : 1 ,
"productId" : 1 ,
"productName" : " Intel Core i7-12700K" ,
"quantity" : 1 ,
"unitPrice" : 409.99 ,
"subtotal" : 409.99
}
Field
Type
Description
id
int
Order item ID
productId
int
Product ID
productName
string?
Product name
quantity
int
Quantity ordered
unitPrice
decimal
Price per unit at order time
subtotal
decimal
Computed: quantity × unitPrice
{
"error" : " Error message description"
}
Code
Description
200 OK
Request successful
201 Created
Resource created successfully
204 No Content
Request successful, no content to return
400 Bad Request
Invalid input or validation failed
401 Unauthorized
Missing or invalid authentication
403 Forbidden
User lacks required permissions
404 Not Found
Resource does not exist