Primera app funcional
This commit is contained in:
126
lib/models/models.dart
Normal file
126
lib/models/models.dart
Normal file
@@ -0,0 +1,126 @@
|
||||
// ── USER ──────────────────────────────────────────────────────────────────
|
||||
class UserModel {
|
||||
final int? id;
|
||||
final String nombre;
|
||||
final String email;
|
||||
final String password;
|
||||
final String rol; // CIUDADANO | CONDUCTOR | ADMINISTRADOR
|
||||
|
||||
UserModel({this.id, required this.nombre, required this.email,
|
||||
required this.password, required this.rol});
|
||||
|
||||
Map<String, dynamic> toMap() =>
|
||||
{'id': id, 'nombre': nombre, 'email': email, 'password': password, 'rol': rol};
|
||||
|
||||
factory UserModel.fromMap(Map<String, dynamic> m) => UserModel(
|
||||
id: m['id'], nombre: m['nombre'], email: m['email'],
|
||||
password: m['password'], rol: m['rol']);
|
||||
}
|
||||
|
||||
// ── DOMICILIO (citizen) ───────────────────────────────────────────────────
|
||||
class DomicilioModel {
|
||||
final int? id;
|
||||
final int userId;
|
||||
final String calle;
|
||||
final String colonia;
|
||||
final String routeId;
|
||||
final String horarioEstimado;
|
||||
final bool isPrimary;
|
||||
|
||||
DomicilioModel({this.id, required this.userId, required this.calle,
|
||||
required this.colonia, required this.routeId,
|
||||
required this.horarioEstimado, this.isPrimary = true});
|
||||
|
||||
Map<String, dynamic> toMap() => {'id': id, 'user_id': userId, 'calle': calle,
|
||||
'colonia': colonia, 'route_id': routeId,
|
||||
'horario_estimado': horarioEstimado, 'is_primary': isPrimary ? 1 : 0};
|
||||
|
||||
factory DomicilioModel.fromMap(Map<String, dynamic> m) => DomicilioModel(
|
||||
id: m['id'], userId: m['user_id'], calle: m['calle'],
|
||||
colonia: m['colonia'], routeId: m['route_id'],
|
||||
horarioEstimado: m['horario_estimado'], isPrimary: m['is_primary'] == 1);
|
||||
}
|
||||
|
||||
// ── ASSIGNMENT (driver schedule) ──────────────────────────────────────────
|
||||
class AssignmentModel {
|
||||
final int? id;
|
||||
final int conductorId;
|
||||
final String routeId;
|
||||
final String diaSemana;
|
||||
final String turno; // MATUTINO | VESPERTINO | NOCTURNO
|
||||
|
||||
AssignmentModel({this.id, required this.conductorId, required this.routeId,
|
||||
required this.diaSemana, required this.turno});
|
||||
|
||||
Map<String, dynamic> toMap() => {'id': id, 'conductor_id': conductorId,
|
||||
'route_id': routeId, 'dia_semana': diaSemana, 'turno': turno};
|
||||
|
||||
factory AssignmentModel.fromMap(Map<String, dynamic> m) => AssignmentModel(
|
||||
id: m['id'], conductorId: m['conductor_id'], routeId: m['route_id'],
|
||||
diaSemana: m['dia_semana'], turno: m['turno']);
|
||||
}
|
||||
|
||||
// ── ROUTE STATUS ──────────────────────────────────────────────────────────
|
||||
class RouteStatusModel {
|
||||
final String routeId;
|
||||
final String status;
|
||||
final String? mensaje;
|
||||
final String updatedAt;
|
||||
|
||||
RouteStatusModel({required this.routeId, required this.status,
|
||||
this.mensaje, required this.updatedAt});
|
||||
|
||||
Map<String, dynamic> toMap() => {'route_id': routeId, 'status': status,
|
||||
'mensaje': mensaje, 'updated_at': updatedAt};
|
||||
|
||||
factory RouteStatusModel.fromMap(Map<String, dynamic> m) => RouteStatusModel(
|
||||
routeId: m['route_id'], status: m['status'],
|
||||
mensaje: m['mensaje'], updatedAt: m['updated_at']);
|
||||
}
|
||||
|
||||
// ── ALERTA ────────────────────────────────────────────────────────────────
|
||||
class AlertaModel {
|
||||
final int? id;
|
||||
final String tipo; // GPS_PERDIDO | CAMION_DETENIDO | FALLA_MECANICA
|
||||
final String routeId;
|
||||
final String mensaje;
|
||||
final String fecha;
|
||||
final bool resuelta;
|
||||
|
||||
AlertaModel({this.id, required this.tipo, required this.routeId,
|
||||
required this.mensaje, required this.fecha, this.resuelta = false});
|
||||
|
||||
Map<String, dynamic> toMap() => {'id': id, 'tipo': tipo, 'route_id': routeId,
|
||||
'mensaje': mensaje, 'fecha': fecha, 'resuelta': resuelta ? 1 : 0};
|
||||
|
||||
factory AlertaModel.fromMap(Map<String, dynamic> m) => AlertaModel(
|
||||
id: m['id'], tipo: m['tipo'], routeId: m['route_id'],
|
||||
mensaje: m['mensaje'], fecha: m['fecha'], resuelta: m['resuelta'] == 1);
|
||||
}
|
||||
|
||||
// ── REPORTE ───────────────────────────────────────────────────────────────
|
||||
class ReporteModel {
|
||||
final int? id;
|
||||
final int userId;
|
||||
final String tipo;
|
||||
final String descripcion;
|
||||
final String colonia;
|
||||
final String routeId;
|
||||
final String fecha;
|
||||
final String estado;
|
||||
final int calificacion;
|
||||
|
||||
ReporteModel({this.id, required this.userId, required this.tipo,
|
||||
required this.descripcion, required this.colonia, required this.routeId,
|
||||
required this.fecha, this.estado = 'PENDIENTE', this.calificacion = 5});
|
||||
|
||||
Map<String, dynamic> toMap() => {'id': id, 'user_id': userId, 'tipo': tipo,
|
||||
'descripcion': descripcion, 'colonia': colonia, 'route_id': routeId,
|
||||
'fecha': fecha, 'estado': estado, 'calificacion': calificacion};
|
||||
|
||||
factory ReporteModel.fromMap(Map<String, dynamic> m) => ReporteModel(
|
||||
id: m['id'], userId: m['user_id'], tipo: m['tipo'],
|
||||
descripcion: m['descripcion'], colonia: m['colonia'],
|
||||
routeId: m['route_id'] ?? '', fecha: m['fecha'],
|
||||
estado: m['estado'], calificacion: m['calificacion'] ?? 5);
|
||||
}
|
||||
39
lib/models/route_model.dart
Normal file
39
lib/models/route_model.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
class RoutePosition {
|
||||
final int positionId;
|
||||
final double lat;
|
||||
final double lng;
|
||||
final int speed;
|
||||
final String timestamp;
|
||||
|
||||
RoutePosition({required this.positionId, required this.lat,
|
||||
required this.lng, required this.speed, required this.timestamp});
|
||||
|
||||
LatLng get latLng => LatLng(lat, lng);
|
||||
}
|
||||
|
||||
class RouteModel {
|
||||
final String routeId;
|
||||
final String name;
|
||||
final int truckId;
|
||||
String status;
|
||||
final List<RoutePosition> positions;
|
||||
final String turno; // MATUTINO | VESPERTINO | NOCTURNO
|
||||
|
||||
RouteModel({required this.routeId, required this.name,
|
||||
required this.truckId, required this.status,
|
||||
required this.positions, this.turno = 'MATUTINO'});
|
||||
|
||||
List<LatLng> get polylinePoints =>
|
||||
positions.map((p) => LatLng(p.lat, p.lng)).toList();
|
||||
}
|
||||
|
||||
class ColonyModel {
|
||||
final String colonia;
|
||||
final String routeId;
|
||||
final String horarioEstimado;
|
||||
|
||||
ColonyModel({required this.colonia, required this.routeId,
|
||||
required this.horarioEstimado});
|
||||
}
|
||||
Reference in New Issue
Block a user