Sobes.tech
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 1
  • pageSize (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 filters
  • totalPages — total number of pages
  • currentPage — current page number

Working logic:

  1. Receive request parameters.
  2. Validate parameters (page > 0, pageSize within reasonable limits).
  3. Formulate a database query considering filters and sorting.
  4. Count total number of items for pagination.
  5. Retrieve data for the current page using LIMIT and OFFSET (or equivalents).
  6. 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
}