Sending aDocumentation 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.
POST request with accion=vender decrements the stock of a product by a given quantity. The operation is atomic: the SQL statement only executes the decrement if the current stock is sufficient, preventing overselling even under concurrent requests. If the update affects zero rows — because the product does not exist or has insufficient stock — the servlet returns {"success": false}.
Request
Method:POSTURL:
http://localhost:8080/ServidorTiendaPlayeras/ProductoServletContent-Type:
application/x-www-form-urlencoded
Parameters
Dispatch key for the POST handler. Must be exactly
"vender" to reach the sell branch.The primary-key ID of the product to sell.
The number of units to sell. Defaults to
1 if this parameter is omitted or not provided.curl Example
PHP (Laravel) Example
ThePlayerasController::vender() method casts both id and cantidad to integers before sending to avoid type coercion issues:
SQL Executed
Response
true if the stock was decremented successfully (the sale was recorded); false if the product was not found or did not have enough stock to fulfill the requested quantity.Atomic Stock Guard
The sell operation uses a singleUPDATE statement with a conditional WHERE clause to prevent overselling without requiring a separate read or a transaction lock:
AND stock >= ? condition means the database will only modify the row if the current stock value is greater than or equal to the requested cantidad. If the condition is not met, the statement updates zero rows, and the DAO layer interprets that as a failed sale, returning false to the servlet which then responds with {"success": false}.
This approach is race-condition safe: because the check and the decrement happen inside a single atomic SQL statement, two concurrent requests cannot both read the same stock value and both succeed when only one unit remains.
If
cantidad is omitted from the request, the servlet defaults it to 1. You can therefore sell a single unit by sending only accion=vender&id={id} without specifying cantidad.