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 Reviews API manages user-submitted ratings and comments for cafeteria products on the UniSierra Eats platform. Each review carries a star rating between 1 and 5, a text comment, a timestamp, and a state field (activa or reportada). Public read endpoints filter to estado = 'activa' only — reported reviews are hidden from students until an admin takes action.

GET /api/resenas/usuario/:usuario_id

Returns all active reviews written by a specific user, newest first. The response joins the Productos table to include the product name and image alongside each review.

Path Parameter

ParameterTypeDescription
usuario_idintegerThe id of the user whose reviews to fetch.

Request Body

None required.

Response — 200 OK

Returns a JSON array. Each element has the following fields:
id
integer
Unique identifier of the review.
calificacion
integer
Star rating given by the user (1–5).
comentario
string
Text body of the review.
fecha
string
Timestamp of when the review was created, as stored by SQLite (e.g. "2024-11-15 10:32:00").
producto_nombre
string
Name of the reviewed product, joined from the Productos table.
producto_imagen
string
Image URL or path of the reviewed product, joined from the Productos table.

Response — 500 Internal Server Error

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

Example

curl http://localhost:3000/api/resenas/usuario/5
[
  {
    "id": 14,
    "calificacion": 5,
    "comentario": "Excelente, muy fresca y sin azúcar.",
    "fecha": "2024-11-15 10:32:00",
    "producto_nombre": "Agua de Jamaica",
    "producto_imagen": "/img/jamaica.jpg"
  }
]

GET /api/resenas/producto/:producto_id

Returns all active reviews for a specific product, newest first. The response joins the Usuarios table to include the reviewer’s display name.

Path Parameter

ParameterTypeDescription
producto_idintegerThe id_producto of the product whose reviews to fetch.

Request Body

None required.

Response — 200 OK

Returns a JSON array. Each element has the following fields:
id
integer
Unique identifier of the review.
calificacion
integer
Star rating given by the reviewer (1–5).
comentario
string
Text body of the review.
fecha
string
Timestamp of when the review was created.
usuario_nombre
string
Display name of the reviewer, joined from the Usuarios table.

Response — 500 Internal Server Error

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

Example

curl http://localhost:3000/api/resenas/producto/3
[
  {
    "id": 14,
    "calificacion": 5,
    "comentario": "Excelente, muy fresca y sin azúcar.",
    "fecha": "2024-11-15 10:32:00",
    "usuario_nombre": "Ana López"
  }
]

POST /api/resenas

Creates a new review linking a user to a product. The calificacion field is subject to a database-level CHECK constraint that restricts values to the range 1–5; values outside this range will trigger a 500 error.

Request Body

usuario_id
integer
required
The id of the user submitting the review.
producto_id
integer
required
The id_producto of the product being reviewed.
calificacion
integer
required
Star rating. Must be an integer between 1 and 5 inclusive.
comentario
string
required
Text body of the review.

Response — 200 OK

mensaje
string
Confirmation message: "Reseña guardada con éxito".
id
integer
The lastID of the newly created review row.

Response — 500 Internal Server Error

{ "error": "<sqlite error message>" }
A calificacion value outside the 1–5 range will be rejected by the SQLite CHECK constraint and surface as a 500 error with the constraint violation message.

Example

curl -X POST http://localhost:3000/api/resenas \
  -H "Content-Type: application/json" \
  -d '{
    "usuario_id": 5,
    "producto_id": 3,
    "calificacion": 5,
    "comentario": "Excelente, muy fresca y sin azúcar."
  }'
{ "mensaje": "Reseña guardada con éxito", "id": 14 }

PUT /api/resenas/:id

Updates the star rating and comment text of an existing review identified by its id.

Path Parameter

ParameterTypeDescription
idintegerThe id of the review to update.

Request Body

calificacion
integer
required
Updated star rating (1–5).
comentario
string
required
Updated text body of the review.

Response — 200 OK

mensaje
string
Confirmation message: "Reseña actualizada".

Response — 500 Internal Server Error

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

Example

curl -X PUT http://localhost:3000/api/resenas/14 \
  -H "Content-Type: application/json" \
  -d '{
    "calificacion": 4,
    "comentario": "Muy buena, aunque un poco dulce."
  }'
{ "mensaje": "Reseña actualizada" }

DELETE /api/resenas/:id

Permanently deletes a review from the database by its id. This action is irreversible. For admin-driven moderation deletion, see DELETE /api/admin/resenas/:id.

Path Parameter

ParameterTypeDescription
idintegerThe id of the review to delete.

Request Body

None required.

Response — 200 OK

mensaje
string
Confirmation message: "Reseña eliminada".

Response — 500 Internal Server Error

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

Example

curl -X DELETE http://localhost:3000/api/resenas/14
{ "mensaje": "Reseña eliminada" }

PUT /api/resenas/:id/reportar

Flags a review as reported by setting its estado to 'reportada'. Once flagged, the review no longer appears in the public GET /api/resenas/usuario/:usuario_id or GET /api/resenas/producto/:producto_id responses, and it becomes visible only through the admin moderation endpoint.

Path Parameter

ParameterTypeDescription
idintegerThe id of the review to flag.

Request Body

None required.

Response — 200 OK

mensaje
string
Confirmation message: "Reseña reportada.".

Response — 500 Internal Server Error

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

Example

curl -X PUT http://localhost:3000/api/resenas/14/reportar
{ "mensaje": "Reseña reportada." }

Build docs developers (and LLMs) love