Middle+
Design a service for displaying a paginated list of inventory items: input parameters, output parameters, and logic.
sobes.tech AI
Answer from AI
For a service displaying a paginated list of inventory (goods and materials), the following interface can be defined:
Input parameters:
page(int) — page number, starting from 1pageSize(int) — number of items per page- (optional)
sortBy(string) — sorting field, e.g., "name" or "date" - (optional)
sortOrder(string) — "asc" or "desc" - (optional) filters, e.g., by category, availability, price
Output parameters:
items— array of inventory objects with required fields (id, name, quantity, price, etc.)totalItems— total number of inventory items matching filterstotalPages— total number of pagescurrentPage— current page number
Working logic:
- Receive request parameters.
- Validate parameters (page > 0, pageSize within reasonable limits).
- Formulate a database query considering filters and sorting.
- Count total number of items for pagination.
- Retrieve data for the current page using LIMIT and OFFSET (or equivalents).
- Formulate a response with data and pagination metadata.
Example of a simplified API:
GET /api/tmc?page=2&pageSize=20&sortBy=name&sortOrder=asc
Response:
{
"items": [
{"id": 101, "name": "Product A", "quantity": 50},
...
],
"totalItems": 150,
"totalPages": 8,
"currentPage": 2
}