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.

Reviews are the core feedback mechanism in UniSierra Eats. Logged-in students can rate any cafeteria product from 1 to 5 stars and leave a written comment. The average of all active reviews for a product is computed live and displayed wherever that product appears — in the catalog, search results, and the product detail page.

Data Model

Reviews are stored in the Resenas table:
FieldTypeConstraintsDescription
idINTEGERPRIMARY KEYAuto-incremented review identifier
usuario_idINTEGERFOREIGN KEY -> Usuarios.idThe student who wrote the review
producto_idINTEGERFOREIGN KEY -> Productos.id_productoThe product being reviewed
calificacionINTEGERCHECK (1 to 5)Star rating from 1 (lowest) to 5 (highest)
comentarioTEXTWritten review body
fechaDATETIMEDEFAULT CURRENT_TIMESTAMPTimestamp of submission
estadoTEXTDEFAULT 'activa'Review visibility state

Review States

StateMeaning
activaVisible to all users on the product detail page
reportadaFlagged by a student; hidden from public view, pending admin review

API Endpoints

Submit a Review

POST /api/resenas Creates a new review. The student must be logged in — the frontend reads usuario_id directly from the localStorage session. Request body:
{
  "usuario_id": 7,
  "producto_id": 3,
  "calificacion": 4,
  "comentario": "El café está muy bueno, siempre a buen precio."
}
Success response (200 OK):
{
  "mensaje": "Reseña guardada con éxito",
  "id": 42
}

Edit a Review

PUT /api/resenas/:id Updates the star rating and comment of an existing review. Only the fields calificacion and comentario are accepted.
{
  "calificacion": 5,
  "comentario": "Actualicé mi opinión — definitivamente 5 estrellas."
}

Delete a Review

DELETE /api/resenas/:id Permanently removes a review. No confirmation is performed server-side; the frontend presents a confirmation modal before calling this endpoint.

Flag a Review

PUT /api/resenas/:id/reportar Sets the review’s estado to 'reportada'. Reported reviews are immediately hidden from the product detail page and queued for admin review via GET /api/admin/resenas-reportadas. The request is sent with method: 'PUT' and no request body.
const res = await fetch(`/api/resenas/${id}/reportar`, { method: 'PUT' });

Fetch Reviews for a Product

GET /api/resenas/producto/:producto_id Returns all active reviews for a specific product, ordered newest first. Each row includes the reviewer’s display name joined from the Usuarios table.
[
  {
    "id": 42,
    "calificacion": 4,
    "comentario": "El café está muy bueno, siempre a buen precio.",
    "fecha": "2024-05-20 14:32:00",
    "usuario_nombre": "Ana López"
  }
]

Fetch Reviews by User

GET /api/resenas/usuario/:usuario_id Returns all active reviews written by a specific student, ordered newest first. Each row includes the product name and image joined from the Productos table — used to render the profile page’s “Mis Reseñas” tab.
[
  {
    "id": 42,
    "calificacion": 4,
    "comentario": "El café está muy bueno, siempre a buen precio.",
    "fecha": "2024-05-20 14:32:00",
    "producto_nombre": "Café Americano",
    "producto_imagen": "https://..."
  }
]

Submitting a Review

1

Browse to a Product

Navigate to the product catalog or search results and click any product card to open detalle_producto.html?id=<id_producto>.
2

Click 'Escribir Reseña'

On the product detail page, click the Escribir Reseña button. If you are not logged in, an alert prompts you to sign in first. Authenticated users are redirected to escribir_resena.html?id=<id_producto>.
3

Select a Star Rating

Click one of the five interactive star icons to set your rating. The label below the stars updates to confirm your selection, e.g. “3 estrellas”.
4

Write Your Comment

Enter your review text in the comment field. The comment field is required — the form will not submit without it.
5

Submit

Click Enviar Reseña. On success you are redirected back to the product detail page where your new review appears immediately.

Fetch Code — Submitting a Review

The following code from manejarEscrituraResena() in app.js shows how the review form posts to the API:
const payload = {
    usuario_id: sesion.id,
    producto_id: prodId,
    calificacion: calificacionSeleccionada,
    comentario: comentario
};

const res = await fetch('/api/resenas', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload)
});

if (res.ok) {
    alert("¡Gracias por tu opinión!");
    window.location.href = `detalle_producto.html?id=${prodId}`;
}

Star Rating Display

The generarEstrellas() helper in app.js renders a row of Font Awesome icons for any numeric rating. It supports full, half, and empty stars:
function generarEstrellas(calificacion) {
    let html = '';
    for (let i = 1; i <= 5; i++) {
        if (calificacion >= i)         html += '<i class="fas fa-star"></i>';
        else if (calificacion >= i - 0.5) html += '<i class="fas fa-star-half-alt"></i>';
        else                           html += '<i class="far fa-star"></i>';
    }
    return html;
}
This function is called in every view that displays a rating: the homepage top-3 cards, catalog cards, search results, and the product detail header.

Rating Distribution Bars

The product detail page shows a 5-row progress bar breakdown of ratings. The bars are computed entirely in the frontend after fetching reviews from /api/resenas/producto/:producto_id:
  • Each row corresponds to a star level (5 down to 1).
  • The filled width is (count for that star / total reviews) × 100%.
  • A smooth CSS transition (0.8s ease-out) animates the bars on load.
Students can only view, edit, and delete their own reviews. The profile page at perfil.html fetches reviews via GET /api/resenas/usuario/:usuario_id using the ID stored in the session, so only that user’s reviews are ever loaded. Editing and deleting controls appear exclusively on the profile page, not on public product pages.

Build docs developers (and LLMs) love