All HTTP communication between the SmartStock360 React frontend and the Spring Boot backend is handled by a single thin service module located atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/JoseOlivares19/Proyecto-PC3-JavaScript-Avanzado/llms.txt
Use this file to discover all available pages before exploring further.
src/services/api.ts. The file exports two async functions — one for fetching the product list and one for submitting a prediction payload — keeping the transport logic cleanly separated from the UI component in App.tsx.
The Complete Service File
The entiresrc/services/api.ts module is shown below exactly as it appears in the repository:
obtenerProductos()
Performs a GET request to the base API_URL and returns the response body directly.
- Endpoint:
GET /api/productos - Returns: An array of product objects from the MySQL database, each containing at minimum
id,nombre,precio, andstockActualfields - Called by:
cargarProductos()insideApp.tsx, triggered automatically on component mount viauseEffect
predecirDemanda(datosProducto)
Posts a structured prediction payload to the /predict sub-resource and returns the AI model’s response.
- Endpoint:
POST /api/productos/predict - Accepts: A
datosProductoobject (see payload shape below) - Returns: The AI prediction response object (see response shape below)
- Called by:
manejarPrediccion()insideApp.tsx, triggered when the user clicks “Ejecutar Predicción IA”
Changing the Base URL for Local Development
By default the service targets the deployed production backend. To run against a local Spring Boot instance, opensrc/services/api.ts and replace the API_URL constant:
Prediction Request Payload Shape
ThedatosProducto object passed to predecirDemanda() must match the fields expected by the backend PredictDto.java and the Python StockRequest model:
App.tsx provides a concrete example:
Prediction Response Shape
A successful call topredecirDemanda() returns a JSON object with the following structure:
| Field | Type | Description |
|---|---|---|
caso | string | Identifies the project — always "SmartStock360" |
prediccion | string | The raw ML class label (DEMANDA_ALTA_REABASTECER, DEMANDA_MEDIA_MONITOREAR, or similar) |
confianza | number | Model confidence score between 0 and 1 |
ranking | array | Class probability ranking from the model |
recomendaciones | string[] | Human-readable action recommendations to display in the UI |
entrada | object | Echo of the input payload as received by the backend |
prediccion and recomendaciones fields are the ones actively consumed and displayed by App.tsx. The confianza field is returned in the response and available on the resultado object in state if you wish to surface it in the UI.
Neither
predecirDemanda nor obtenerProductos perform internal error handling — both are bare async/await functions that let exceptions propagate to the caller. Error handling lives in App.tsx: both manejarPrediccion() and cargarProductos() wrap their calls in try/catch blocks that log failures to the browser console via console.error(). No error state is surfaced in the UI beyond the empty inventory table shown when productos remains an empty array.