Overview
TheNegocioRepositorio defines the contract for restaurant business management, including registration, authentication, profile updates, and configuration. The Firestore implementation (NegocioRepositorioFirestore) provides persistent storage with built-in validation and safe type conversion.
Interface
lib/dominio/repositorios/negocio_repositorio.dart
Methods
registrarNegocio
Registers a new restaurant business in the system.The restaurant’s name.
The name of the person responsible for managing the restaurant.
The restaurant’s email address (must be unique).
The restaurant’s contact phone number.
The restaurant’s physical address.
The password for authentication (stored as plain text in this implementation - see security note).
Returns the created business entity with its assigned ID, or
null if registration fails (e.g., email already exists).descripcion: Empty stringespecialidad: Empty stringminHorasParaCancelar: 24 hoursmaxDiasAnticipacionReserva: 14 daysduracionPromedioMinutos: 60 minutes
Example Usage
autenticarNegocio
Authenticates a restaurant business using email and password.The restaurant’s email address.
The restaurant’s password.
Returns the business entity if authentication succeeds, or
null if credentials are invalid.- Queries Firestore for a business with the provided email
- Compares the stored password with the provided password (plain text comparison)
- Returns the business entity if credentials match
Example Usage
obtenerTodosLosNegocios
Retrieves all registered businesses, ordered alphabetically by name.Returns a list of all businesses. Returns an empty list on error.
Example Usage
obtenerNegocioPorId
Retrieves a specific business by its unique identifier.The business’s unique identifier.
Returns the business if found, or
null if it doesn’t exist or there’s an error.Example Usage
obtenerNegocioPorEmail
Retrieves a business by its email address.The business’s email address.
Returns the business if found, or
null if no business with that email exists.- Check if an email is already registered before creating a new account
- Password recovery flows
- Email uniqueness validation
Example Usage
actualizarNegocio
Updates a business’s complete profile information.The business entity with updated information. Must include a valid ID.
Returns
true if the update was successful, false otherwise.nombre- Restaurant namenombreResponsable- Manager nameemail- Contact emailtelefono- Phone numberdireccion- Physical addressdescripcion- Description textespecialidad- Cuisine specialtyicono- Icon identifierminHorasParaCancelar- Minimum cancellation notice (hours)maxDiasAnticipacionReserva- Maximum advance booking (days)duracionPromedioMinutos- Average reservation durationtelefonoVerificado- Phone verification statuszonas- Available seating zones
Example Usage
actualizarEmail
Updates a business’s email address with uniqueness validation.The business’s unique identifier.
The new email address to set.
Returns
true if the email was updated, false if the email is already in use by another business.- Checks if the new email is already used by another business
- Allows updating to the same email (no-op but returns true)
- Prevents email conflicts across different businesses
Example Usage
actualizarPassword
Updates a business’s password (for backup or legacy authentication).The business’s unique identifier.
The new password to set.
Returns
true if the password was updated successfully, false if the operation fails or the ID is empty.Example Usage
actualizarTelefono
Updates a business’s phone number and verification status.The business’s unique identifier.
The new phone number to set.
Whether the phone number has been verified.
Returns
true if the update was successful, false otherwise.Example Usage
actualizarZonas
Updates the list of available seating zones for a restaurant.The business’s unique identifier.
The new list of zone names (e.g., [“Salón”, “Terraza”, “VIP”]).
Returns
true if the zones were updated successfully, false otherwise.Example Usage
Firestore Implementation
Collection Structure
Businesses are stored in thenegocios collection:
Firestore Document
Safe Type Conversion
The implementation includes helper functions for safe type conversion when reading from Firestore:safeInt(value, defaultValue)
- Handles:
int,double,String,null - Converts doubles to integers
- Parses numeric strings
- Returns default value for invalid types
safeBool(value, defaultValue)
- Handles:
bool,String,null - Parses “true”/“false” strings (case-insensitive)
- Returns default value for invalid types
safeList(value, defaultValue)
- Handles:
List,null - Converts list elements to strings
- Returns default value for invalid types
Related Types
Negocio Entity
See Also
- MesaRepositorio - Uses zones configured in Negocio
- HorarioAperturaRepositorio - Business hours for the restaurant
- HistoriaRepositorio - Restaurant story and specialties