Middle
Task: develop a backend method for updating order status, accessible only to administrators. Create a technical specification for the developer.
sobes.tech AI
Answer from AI
Technical specifications for the backend method of updating order status (admin only):
-
Description: The method updates the order status by its identifier. Accessible only to users with the administrator role.
-
URL and method:
- URL:
/api/orders/{orderId}/status - HTTP method:
PATCHorPUT(preferably PATCH for partial updates)
- URL:
-
Authentication and authorization:
- The method requires authentication.
- Role check: only administrators have access.
- If access is denied, return 403 Forbidden.
-
Input data:
- Path parameter:
orderId— the order identifier. - Request body (JSON):
{ "status": "new_status" } - Valid status values should be predefined (e.g., "pending", "shipped", "cancelled", etc.).
- Path parameter:
-
Processing:
- Verify the existence of the order with the given
orderId. - Validate the new status.
- Update the order status in the database.
- Log the status change (who, when, from what to what).
- Verify the existence of the order with the given
-
Response:
- On success: HTTP 200 OK with the updated order object or message.
- On errors (e.g., order not found, invalid status, insufficient rights) — appropriate error codes (404, 400, 403).
-
Security:
- CSRF protection (if applicable).
- Validation and sanitization of input data.
-
Example request:
PATCH /api/orders/123/status HTTP/1.1 Authorization: Bearer <token> Content-Type: application/json { "status": "shipped" } -
Logging and monitoring:
- Log successful and unsuccessful attempts to update the status.
-
Tests:
- Verify status update with valid and invalid data.
- Check access for different roles.
This technical specification will enable the developer to implement a secure and correct method for updating order status, considering business logic and security requirements.