Tienda de Playeras includes a built-in sell workflow that lets you record sales directly from the product catalog. When a sale is confirmed, the system atomically decrements the product’s stock in MySQL using a guardedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/LucaXGit/proyecto-final-jaz/llms.txt
Use this file to discover all available pages before exploring further.
UPDATE statement, ensuring the count can never drop below zero — even under concurrent requests.
Processing a Sale
Locate the product card
Navigate to the catalog at
http://localhost:8000. Find the product you want to sell in the card grid. Each card displays the current stock count (“X piezas”) so you can confirm availability at a glance.Enter the sale quantity
In the card footer, type the desired quantity into the numeric input field. The input enforces
min=1 and max=current stock, so you cannot accidentally enter a value that exceeds available inventory from the UI.Confirm the sale
Click ”🛒 Confirmar Venta” to submit the sale. If stock is zero, this button is replaced by an “Agotado” label and is disabled — no action can be taken until the product is restocked.
Request reaches Laravel
The form
POSTs to /vender/{id} with the cantidad field. Laravel’s PlayerasController forwards the request to the Java backend:Backend processes the transaction
ProductoServlet receives accion=vender, id, and cantidad, then delegates to ProductoDAO, which executes an atomic SQL update against the MySQL database:AND stock >= ? condition is the server-side guard — the row is only updated when sufficient stock exists. If the condition is not met, zero rows are affected and the stock remains unchanged.Inventory Guard
The core of oversell prevention is a single atomic SQL statement executed byProductoDAO:
UPDATE, the database engine handles the atomicity — there is no window between a SELECT and an UPDATE where a concurrent request could read the same stock value and both succeed. If two sale requests for the last unit arrive simultaneously, only one will match the AND stock >= ? condition; the other will affect zero rows and leave the stock at zero without going negative.
The sell button is also disabled in the UI whenever a product’s stock reaches zero, using the following Blade expression:This client-side guard provides immediate visual feedback and prevents accidental form submissions, complementing the server-side SQL check.
Out-of-Stock Behavior
When a product’s stock reaches0, the catalog card changes automatically:
- The sell button label changes to “Agotado” and becomes disabled.
- The quantity input is also disabled, preventing any input.
- No sale can be submitted from the UI until stock is replenished.