Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ierinconc/billar-pro-backend/llms.txt

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

Consumptions (consumos) are the line items that link a product to a table during an active session. Each time a customer orders a drink or snack, staff register a consumption record pointing to the table and the product. Those records accumulate with sesion = null while the table is in use, and when the table is eventually closed via PUT /api/mesas/{id}/cerrar, the system automatically sums all open consumptions, computes the totalConsumos, and permanently attaches every pending record to the newly created Sesion — so the full bill is captured in one atomic operation.

Endpoints

GET /api/consumos

Returns every consumption record in the database, including those already linked to closed sessions. Authentication: Required — include a valid JWT Bearer token. Response: 200 OK — array of Consumo objects.
id
Long
Auto-generated primary key of the consumption record.
mesa
object
The table against which the sale was recorded.
producto
object
The product that was sold.
cantidad
Integer
Number of units sold in this consumption record.
subtotal
Double
Computed at registration time as producto.precio × cantidad. Not recalculated if the product price changes later.
fecha
String (ISO 8601 datetime)
Timestamp when the consumption was registered, e.g. "2025-06-01T15:22:45".
sesion
object | null
null while the consumption is open (table not yet closed). Once the table is closed, this field contains the full Sesion object to which this consumption was attached.

Request example

curl -X GET http://localhost:8080/api/consumos \
  -H "Authorization: Bearer <token>"

POST /api/consumos

Registers a new product sale against a table. The server looks up the product price and computes subtotal automatically. Authentication: Required — include a valid JWT Bearer token. Request body (JSON):
mesaId
Long
required
ID of the table to charge. The table must already exist in the database.
productoId
Long
required
ID of the product being sold. The product must exist and have disponible = true or the request will be rejected.
cantidad
Integer
required
Number of units being sold. The server multiplies this by the product’s current unit price to set subtotal.
Server-side computation:
subtotal = producto.precio × cantidad
The subtotal is persisted with the record and is not updated if the product price changes after registration. Response: 201 Created — the created Consumo object. Errors:
StatusMeaning
404mesaId does not exist ("Mesa no encontrada").
404productoId does not exist ("Producto no encontrado").
404Product exists but disponible = false ("Producto no disponible").

Request example

curl -X POST http://localhost:8080/api/consumos \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "mesaId": 1,
    "productoId": 2,
    "cantidad": 3
  }'

Response example

{
  "id": 47,
  "mesa": {
    "id": 1,
    "numero": 1,
    "estado": "OCUPADA",
    "precioPorHora": 8000.0
  },
  "producto": {
    "id": 2,
    "nombre": "Gaseosa",
    "categoria": "Bebidas",
    "precio": 2500.0,
    "disponible": true
  },
  "cantidad": 3,
  "subtotal": 7500.0,
  "fecha": "2025-06-01T15:22:45",
  "sesion": null
}

GET /api/consumos/mesa/{mesaId}

Returns only the open consumptions for a given table — that is, records where sesion IS NULL. These are the pending items that will be included in the bill when the table is eventually closed. Authentication: Required — include a valid JWT Bearer token. Path parameters:
mesaId
Long
required
Primary key of the table whose open consumptions should be retrieved.
Response: 200 OK — array of Consumo objects (may be empty if no open consumptions exist). Errors:
StatusMeaning
404No table with that mesaId exists ("Mesa no encontrada").

Request example

curl -X GET http://localhost:8080/api/consumos/mesa/1 \
  -H "Authorization: Bearer <token>"

Consumption lifecycle: A consumption is created with sesion = null, meaning it is unlinked and open. When PUT /api/mesas/{id}/cerrar is called, SesionService queries all records matching findByMesaAndSesionIsNull, totals their subtotals, saves the new Sesion, and then sets sesion on every matching Consumo. From that point the records become part of the immutable session history and will no longer appear in the /api/consumos/mesa/{mesaId} response.
The API does not check whether a table is currently OCUPADA before registering a consumption. If a consumption is posted against a table in the LIBRE state, the record is saved successfully with sesion = null. It will then be picked up and billed the next time that table is closed — which may be a completely different customer’s session. Always confirm the table is actively occupied before registering consumptions.

Build docs developers (and LLMs) love