API Integration - FactoriaF5-Asturias/project-p5-digital-academy-team1-restaurant-frontend GitHub Wiki
API Integration
All requests go through the shared Axios instance (src/services/api.js), with baseURL = VITE_API_BASE_URL. Every service declares its endpoints as constants.
Endpoints consumed
AUTH & USERS — authService.js
| Method |
Endpoint |
Used in |
Access |
| POST |
/api/v1/auth/login |
Login form |
Public |
| GET |
/api/v1/auth/me |
Load the current user and role |
Session |
| GET |
/api/v1/auth/refresh |
Automatic session renewal (api.js) |
Public |
| GET |
/api/v1/auth/logout |
User menu |
Session |
| POST |
/api/v1/users |
Registration form |
Public |
PRODUCTS — products.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/products?page={n}&size={n} |
Carta |
Public |
| GET |
/api/v1/products/administration |
Admin products (includes unavailable ones) |
ADMIN |
| POST |
/api/v1/products |
Admin: create product |
ADMIN |
| PATCH |
/api/v1/products/{id} |
Admin: edit / activate / deactivate |
ADMIN |
TABLES — tables.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/tables/by-device + header Device-Identifier |
Automatic table detection |
Session |
ORDERS — orders.service.js
| Method |
Endpoint |
Used in |
Access |
| POST |
/api/v1/orders + OrderDTORequest |
Order confirmation |
Public |
OFFERS — offers.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/offers |
Profile, cart discounts |
Customer |
| PATCH |
/api/v1/offers/consume/{coupon} |
After confirming an order |
Customer |
KITCHEN — kitchen.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/kitchen/orders |
Active orders list |
COOK, ADMIN |
| GET |
/api/v1/kitchen/metrics |
Kitchen metrics |
COOK, ADMIN |
| PATCH |
/api/v1/kitchen/orders/{id}/status + { "status": "READY" } |
Change order status (PROCESSING, DELAYED, READY) |
COOK, ADMIN |
DELIVERY — delivery.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/delivery/metrics |
Delivery summary (every 10 s) |
DELIVERY, ADMIN |
INVOICES — invoices.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/invoices |
Admin invoicing table |
ADMIN |
KPI & REPORTS — kpi.service.js, reports.service.js
| Method |
Endpoint |
Used in |
Access |
| GET |
/api/v1/kpi/sales |
Admin sales KPIs |
ADMIN |
| GET |
/api/v1/reports/sales?period={period} |
Admin sales summary |
ADMIN |
| GET |
/api/v1/reports/sales.pdf (responseType: 'blob') |
PDF download |
ADMIN |
Create order payload
{
"items": [
{ "productId": 1, "quantity": 2 },
{ "productId": 7, "quantity": 1 }
],
"chefNote": "Sin wasabi, palillos extra",
"channel": "ONSITE",
"paymentMethod": "CASH_ONSITE"
}
Frontend → backend mappings
Internal frontend values are translated in src/constants/ before being sent:
| Concept |
Frontend value |
Backend enum |
| Channel |
sala |
ONSITE |
| Channel |
domicilio |
ONLINE |
| Payment |
cashier (Pago en caja) |
CASH_ONSITE |
| Payment |
cardOnTable (Tarjeta en mesa) |
CARD_ONSITE |
| Payment |
onlineCard (Tarjeta online) |
ONLINE_CARD |
| Payment |
cashOnDelivery (Efectivo a la entrega) |
CASH_ON_DELIVERY |
Backend paymentStatus |
Label shown to the customer |
PENDING_CASH |
Pendiente de cobro en caja |
PENDING_CARD_TERMINAL |
Pago pendiente en mesa |
Pagination
The backend returns Spring's Page<T> (content, totalElements, totalPages, number — zero-based). Services normalize it into { items, page, size, totalItems, totalPages } so components don't depend on Spring's format; usePagination and PaginationControl.vue are reused by every paginated list.
Error handling
| Status |
Frontend behavior |
| Network error |
Error message in the view (e.g. "No se ha podido cargar la carta"), with retry where it makes sense |
400 |
Validation message, form data is kept |
401 |
Automatic session refresh; if it fails, session cleared and redirect to Login when needed |
403 |
Redirect to Acceso denegado (logged-in users) |
404 |
Specific message (e.g. no table linked to this device → manual input) |
Mocks still in use
| Mock |
Replaces |
Reason |
src/mocks/orderHistory.mock.js |
Order history and "repeat order" |
Backend endpoint not available yet |