This endpoint performs an atomic, transactional decrement of available stock for a given product. It is the core write operation ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nelsoncg98/InnovaTech/llms.txt
Use this file to discover all available pages before exploring further.
servicio-inventario and is designed to be called as part of a larger SAGA transaction orchestrated by servicio-ventapos. The decrement only proceeds when the current stockDisponible is greater than or equal to the requested cantidad; otherwise the operation is rejected and no data is modified. Because the method is annotated with @Transactional, partial writes cannot occur even under concurrent load.
Endpoint
Path Parameters
The unique product identifier of the item whose stock should be decremented. Must correspond to an existing record in the
inventario table. Example: PROD-001.Query Parameters
The number of units to subtract from the product’s current
stockDisponible. Must be a positive integer. The operation is rejected if stockDisponible < cantidad.Responses
Returned when the stock decrement succeeds. Response body is the plain string:
Returned when the current
stockDisponible is less than the requested cantidad. The product exists in the database but does not have enough units to fulfil the request. Response body is the plain string:Returned when the
productoId does not exist in the inventario table. The service method throws an uncaught RuntimeException("Producto no encontrado en inventario"), which Spring Boot converts to an HTTP 500 response. The controller does not catch this exception.Example Request
Example Responses
Success (200 OK):RuntimeException thrown by the service is not caught by the controller, so no custom response body is produced for this case.
Business Rules
- Atomic operation: The service method is annotated
@Transactional, so the read-check-write sequence is executed within a single database transaction. If any step fails, the transaction is rolled back automatically. - Stock guard: The decrement only executes if
inventario.getStockDisponible() >= cantidad. If this condition is not met, the method returnsfalseand the controller responds with HTTP 400. No data is written. - Product not found: If
inventarioRepository.findByProductoId(productoId)returns an emptyOptional, the service throwsRuntimeException("Producto no encontrado en inventario"). This exception is not caught in the controller, so Spring Boot handles it as an unhandled exception and returns HTTP 500 Internal Server Error. - No fractional quantities:
cantidadis anInteger— decimal values are not accepted.
Source Implementation
The controller method inInventarioController.java:
InventarioService.java: