Saltar al contenido principal
Versión: v0.8.0 🚧

Ingredients

Gestión de Ingredientes​

Los endpoints de ingredientes permiten administrar el inventario de materias primas.

Convención de nombres

Los campos JSON usan camelCase (categoryId, lowStockThreshold, costPerUnit).

GET /ingredients​

Obtiene todos los ingredientes del inventario.

Authorization: ingredients_read

cURL Example:

curl -X GET "http://127.0.0.1:9154/ingredients" \
-H "Cookie: accessToken=$ACCESS_TOKEN" \
-H "Cookie: refreshToken=$REFRESH_TOKEN"

Response Body (Éxito - 200 OK):

[
{
"id": "9bd8a46f-9a41-40a7-bb7b-c31567cdc7c1",
"name": "Arroz",
"categoryId": "b80b3b3f-4fc4-4fab-a988-182de6985c27",
"quantity": 50.0,
"unit": "kg",
"lowStockThreshold": 10.0,
"costPerUnit": 2.50
}
]

Response Body (Lista vacía - 200 OK):

"No ingredients found"

GET /ingredients/{id}​

Obtiene un ingrediente específico por su ID.

Authorization: ingredients_read

Path Parameters:

  • id (string): ID del ingrediente a obtener.

cURL Example:

curl -X GET "http://127.0.0.1:9154/ingredients/abae1423-ba25-49c2-b54a-d0d55c727baf" \
-H "Cookie: accessToken=$ACCESS_TOKEN" \
-H "Cookie: refreshToken=$REFRESH_TOKEN"

Response Body (Éxito - 200 OK):

{
"id": "a9cf05f5-e99e-47a5-a50f-bb3546d75a50",
"name": "Arroz",
"categoryId": "8425ff0d-2322-4c92-875b-588002a8e0e9",
"quantity": 50.0,
"unit": "kg",
"lowStockThreshold": 10.0,
"costPerUnit": 2.50
}

GET /ingredients/low_stock/{threshold}​

Obtiene los ingredientes con stock bajo.

Authorization: ingredients_read

Path Parameters:

  • threshold (float): se valida que sea un número, pero ver la nota.

cURL Example:

curl -X GET "http://127.0.0.1:9154/ingredients/low_stock/15.0" \
-H "Cookie: accessToken=$ACCESS_TOKEN" \
-H "Cookie: refreshToken=$REFRESH_TOKEN"

Response Body (Éxito - 200 OK):

[
{
"id": "91b0df69-ee28-4e48-bd8f-419cb8fd184f",
"name": "Arroz",
"categoryId": "54d14313-badf-447c-88a6-5342f09cca22",
"quantity": 8.0,
"unit": "kg",
"lowStockThreshold": 10.0,
"costPerUnit": 2.50
}
]

Response Body (Lista vacía - 200 OK):

"No low stock ingredients found"
Parámetro ignorado

En esta versión, el valor {threshold} se valida (debe ser un número, de lo contrario 400) pero no se usa: el servicio devuelve los ingredientes por debajo de su propio lowStockThreshold por registro, sin considerar el parámetro de la ruta.

POST /ingredients​

Crea un nuevo ingrediente.

Authorization: ingredients_create

Request Body:

{
"name": "string",
"categoryId": "string",
"quantity": 0.0,
"unit": "string",
"lowStockThreshold": 0.0,
"costPerUnit": 0.0
}

cURL Example:

curl -X POST "http://127.0.0.1:9154/ingredients" \
-H "Cookie: accessToken=$ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Aceite de Oliva",
"categoryId": "e13018bf-ffa3-4b22-aa35-6e782f29302a",
"quantity": 20.0,
"unit": "litros",
"lowStockThreshold": 5.0,
"costPerUnit": 4.50
}'

Response Body (Éxito - 201 Created):

{
"id": "ab68898f-7f1a-4ecc-a7c4-40974727564c",
"message": "Ingredient added successfully"
}

PUT /ingredients/{id}​

Actualiza un ingrediente existente.

Authorization: ingredients_update

Path Parameters:

  • id (string): ID del ingrediente a actualizar.

Request Body:

{
"name": "string",
"categoryId": "string",
"quantity": 0.0,
"unit": "string",
"lowStockThreshold": 0.0,
"costPerUnit": 0.0
}

cURL Example:

curl -X PUT "http://127.0.0.1:9154/ingredients/11993e13-b748-4634-ab78-2080f212e98e" \
-H "Cookie: accessToken=$ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Arroz Bomba",
"categoryId": "e13018bf-ffa3-4b22-aa35-6e782f29302a",
"quantity": 60.0,
"unit": "kg",
"lowStockThreshold": 15.0,
"costPerUnit": 3.00
}'

Response Body (Éxito - 200 OK):

{
"id": "ab68898f-7f1a-4ecc-a7c4-40974727564c",
"message": "Ingredient updated successfully"
}

DELETE /ingredients/{id}​

Elimina un ingrediente del inventario.

Authorization: ingredients_delete

Path Parameters:

  • id (string): ID del ingrediente a eliminar.

cURL Example:

curl -X DELETE "http://127.0.0.1:9154/ingredients/e13018bf-ffa3-4b22-aa35-6e782f29302a" \
-H "Cookie: accessToken=$ACCESS_TOKEN"

Response: 204 No Content (sin cuerpo).

Notas​

información
  • Un ingrediente debe estar asociado a una categoría válida (categoryId).
  • Las unidades pueden ser: kg, litros, gramos, unidades, etc.
  • El costPerUnit se usa para el cálculo de costos de platos.