Skip to main content
The orders service (ms-pedidos) manages the full order lifecycle in SmartLogix. Orders begin in PENDIENTE status and progress through APROBADO → EN_ENVIO → ENTREGADO, or may be moved to CANCELADO. When creating an order, the service calls ms-inventario to verify stock; if the inventory service is unreachable, the circuit breaker opens and the request fails immediately rather than hanging. All endpoints require a valid JWT token in the Authorization header.
Order creation depends on the inventory service being available. If ms-inventario is down or unresponsive, the Resilience4j circuit breaker trips and POST /api/pedidos returns an error. Ensure ms-inventario is healthy before creating orders.

GET /api/pedidos

Return the complete list of orders across all users.

Status codes

CodeMeaning
200Success. Returns an array of OrderDTO objects.

Response fields

id
number
required
Auto-generated order identifier.
userId
number
required
Identifier of the user who placed the order.
userEmail
string
Email address of the user who placed the order.
clienteNombre
string
Full name of the end customer.
total
number
required
Order total amount.
status
string
required
Current order status. One of PENDIENTE, APROBADO, EN_ENVIO, ENTREGADO, or CANCELADO.
tipoPedido
string
required
Order type: NACIONAL or INTERNACIONAL.
destino
string
Destination city or country.
observaciones
string
Logistics notes. Auto-populated for INTERNACIONAL orders with customs information.
creadoEn
string
required
ISO-8601 timestamp of when the order was created.

Example

curl --request GET \
  --url http://localhost:8080/api/pedidos \
  --header 'Authorization: Bearer <token>'

POST /api/pedidos

Create a new order. Before persisting, the service calls GET /api/inventario/{productoId}/stock?cantidad={cantidad} on ms-inventario through a Resilience4j circuit breaker. If stock is insufficient or the circuit breaker is open, the request fails. For INTERNACIONAL orders, observaciones is automatically set to describe customs requirements. Orders are created with an initial status of PENDIENTE.

Request body

userId
number
required
The ID of the user placing the order.
userEmail
string
required
The email address of the user placing the order.
clienteNombre
string
required
Full name of the end customer.
total
number
required
Order total amount.
tipoPedido
string
required
Order type. Must be NACIONAL or INTERNACIONAL.
destino
string
required
Destination city or country for delivery.
productoId
number
required
ID of the product to verify stock for via the circuit breaker.
cantidad
number
required
Number of units required. Used for the stock check against ms-inventario.

Status codes

CodeMeaning
201Order created. Returns the new OrderDTO.
400Insufficient stock, validation error, or circuit breaker fallback triggered.
503Inventory service unavailable and circuit breaker is open.

Example

curl --request POST \
  --url http://localhost:8080/api/pedidos \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "userId": 1,
    "userEmail": "ana.garcia@smartlogix.io",
    "clienteNombre": "Carlos Mendez",
    "total": 125.00,
    "tipoPedido": "NACIONAL",
    "destino": "Bogotá",
    "productoId": 42,
    "cantidad": 10
  }'

GET /api/pedidos/

Retrieve a single order by its numeric ID.

Path parameters

id
number
required
The order’s auto-generated identifier.

Status codes

CodeMeaning
200Order found. Returns an OrderDTO.
404No order with the given ID.

Example

curl --request GET \
  --url http://localhost:8080/api/pedidos/7 \
  --header 'Authorization: Bearer <token>'