Overview
TheMesaRepositorio defines the contract for table management operations, including CRUD operations, zone management, and intelligent table availability search. The Firestore implementation (MesaRepositorioFirestore) integrates with ReservaRepositorio to check table availability.
Interface
lib/dominio/repositorios/mesa_repositorio.dart
Methods
obtenerMesas
Retrieves all tables from all restaurants, ordered by name.Returns a list of all tables sorted alphabetically by name. Returns an empty list if there’s an error.
Example Usage
obtenerMesaPorId
Retrieves a specific table by its unique identifier.The unique identifier of the table.
Returns the table if found, or
null if it doesn’t exist or there’s an error.Example Usage
obtenerMesasPorNegocio
Retrieves all tables belonging to a specific restaurant.The unique identifier of the restaurant.
Returns all tables for the restaurant, sorted by name. Returns an empty list if none found or error occurs.
- Uses Firestore
whereclause onnegocioIdfield - Sorts results in memory to avoid requiring composite indexes
- Includes debug logging for troubleshooting
Example Usage
agregarMesa
Adds a new table to the system.The table object to create. The ID will be auto-generated by Firestore.
Returns the created table with its assigned ID, or
null if the operation fails.Example Usage
actualizarMesa
Updates an existing table’s information.The table object with updated information. Must include a valid ID.
Returns
true if the update was successful, false otherwise.Example Usage
eliminarMesa
Deletes a table from the system.The ID of the table to delete.
Returns
true if the deletion was successful, false otherwise.Example Usage
obtenerZonasDisponibles
Retrieves all unique zone names used in a restaurant’s tables.The unique identifier of the restaurant.
Returns a list of unique zone names (e.g., [“Salón”, “Terraza”, “VIP”]). Returns an empty list on error.
- Fetches all tables for the restaurant
- Extracts unique zone values using a Set
- Useful for populating UI dropdowns and zone selectors
Example Usage
buscarMesaDisponibleEnZona
Intelligently searches for the best available table in a specific zone that can accommodate a group.The zone name to search in (e.g., “Salón”, “Terraza”).
The date of the reservation.
The start time of the reservation.
The number of guests to accommodate.
The restaurant’s unique identifier.
Returns the best available table, or
null if no suitable table is found.- Fetches all tables for the restaurant
- Filters tables by:
- Matching zone name
- Can accommodate the group (using
Mesa.puedeAcomodar()method)
- Sorts by capacity (ascending) to find the best-fitting table
- Iterates through sorted tables, checking availability via
ReservaRepositorio.mesaDisponible() - Returns the first available table found
- Prioritizes tables closest in size to the group
- Avoids wasting large tables on small groups
- Uses a fixed 60-minute duration for availability checking
Example Usage
Firestore Implementation
Collection Structure
Tables are stored in themesas collection:
Firestore Document
Zone Migration
The implementation includes automatic migration logic for legacy zone enum values:| Legacy Enum | Migrated Value |
|---|---|
"terraza" | "Terraza" |
"salon" | "Salón" |
"jardin" | "Jardín" |
"barrabar" | "Barra/Bar" |
Constructor Dependencies
ReservaRepositorio instance to check table availability.
Related Types
Mesa Entity
- A table with capacity 4 can accommodate: 1, 2, 3, 4, 5, 6, 7 people
- A table with capacity 4 cannot accommodate: 8+ people (too small) or 0 people (invalid)
- This prevents assigning 10-person tables to 2-person groups
See Also
- ReservaRepositorio - Reservation management and availability checking
- NegocioRepositorio - Restaurant management including zone configuration