Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuseAR27/Unisierra-eats/llms.txt

Use this file to discover all available pages before exploring further.

The Products API provides four endpoints for managing cafeteria items in the UniSierra Eats platform. Products belong to one of four categories (comidas, bebidas, snacks, sanas) and carry a price level indicator alongside their numeric price. The list endpoint aggregates rating data from the Reviews table so callers always receive up-to-date average scores in a single request.

GET /api/productos

Returns every product in the database along with its computed average star rating and total number of reviews. Products that have never been reviewed receive a calificacion of 0 and a numResenas of 0.

SQL Query

The endpoint executes the following query internally:
SELECT p.*,
       IFNULL(AVG(r.calificacion), 0) AS calificacion,
       COUNT(r.id) AS numResenas
FROM Productos p
LEFT JOIN Resenas r ON p.id_producto = r.producto_id
GROUP BY p.id_producto

Request

No request body or query parameters are required.

Response — 200 OK

Returns a JSON array. Each element has the following fields:
id_producto
integer
Unique identifier for the product.
nombre
string
Display name of the product (e.g., "Torta de pierna").
precio
number
Numeric price of the product in Mexican pesos.
precioNivel
string
Human-readable price tier: $, $$, or $$$.
descripcion
string
Short description of the product.
imagen
string
URL or relative path to the product image.
categoria
string
Product category: comidas, bebidas, snacks, or sanas.
calificacion
number
Average star rating across all reviews (including reported ones). Returns 0 when no reviews exist.
numResenas
integer
Total count of reviews associated with the product.

Response — 500 Internal Server Error

{ "error": "<sqlite error message>" }

Example

curl http://localhost:3000/api/productos
[
  {
    "id_producto": 1,
    "nombre": "Torta de pierna",
    "precio": 35,
    "precioNivel": "$",
    "descripcion": "Torta con pierna, frijoles y jalapeños.",
    "imagen": "/img/torta.jpg",
    "categoria": "comidas",
    "calificacion": 4.3,
    "numResenas": 7
  }
]

POST /api/productos

Creates a new product record in the database.

Request Body

nombre
string
required
Display name of the new product.
precio
number
required
Numeric price in Mexican pesos.
precioNivel
string
required
Price tier indicator. Accepted values: $, $$, $$$.
descripcion
string
required
Short description of the product.
imagen
string
required
URL or relative path to the product image.
categoria
string
required
Product category. Accepted values: comidas, bebidas, snacks, sanas.

Response — 200 OK

message
string
Confirmation message: "Producto registrado con éxito".
id
integer
The lastID assigned to the newly created product row.

Response — 500 Internal Server Error

{ "error": "<sqlite error message>" }

Example

curl -X POST http://localhost:3000/api/productos \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Agua de Jamaica",
    "precio": 15,
    "precioNivel": "$",
    "descripcion": "Agua fresca de Jamaica sin azúcar añadida.",
    "imagen": "/img/jamaica.jpg",
    "categoria": "bebidas"
  }'
{ "message": "Producto registrado con éxito", "id": 12 }

PUT /api/productos/:id

Updates the name, description, price, image, and category of an existing product identified by its id_producto.
precioNivel is not updated by this endpoint. To change a product’s price tier, delete and recreate the product, or manage it directly in the database.

Path Parameter

ParameterTypeDescription
idintegerThe id_producto of the product to update.

Request Body

nombre
string
required
Updated display name of the product.
descripcion
string
required
Updated description of the product.
precio
number
required
Updated price in Mexican pesos.
imagen
string
Updated image URL or path. If omitted or null, an empty string is stored.
categoria
string
required
Updated category: comidas, bebidas, snacks, or sanas.

Response — 200 OK

mensaje
string
Confirmation message, e.g. "Producto 3 actualizado correctamente".

Response — 500 Internal Server Error

{ "error": "<sqlite error message>" }

Example

curl -X PUT http://localhost:3000/api/productos/3 \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Agua de Jamaica",
    "descripcion": "Agua fresca sin azúcar, 500 ml.",
    "precio": 18,
    "imagen": "/img/jamaica-nueva.jpg",
    "categoria": "bebidas"
  }'
{ "mensaje": "Producto 3 actualizado correctamente" }

DELETE /api/productos/:id

Permanently deletes a product from the database by its id_producto.

Path Parameter

ParameterTypeDescription
idintegerThe id_producto of the product to delete.

Request Body

None required.

Response — 200 OK

mensaje
string
Confirmation message, e.g. "Producto 3 eliminado correctamente".

Response — 500 Internal Server Error

{ "error": "<sqlite error message>" }

Example

curl -X DELETE http://localhost:3000/api/productos/3
{ "mensaje": "Producto 3 eliminado correctamente" }

Build docs developers (and LLMs) love