- ApiAuthService: login WebControl → guarda jwt + apiKey + db_tenant - Sincronizador: pull alarmas/zonas/usuarios/mensajes/banners + push pendientes - DAOs: métodos adicionales en alarmas, eventos, usuarios - Páginas actualizadas: ConectarProveedorPage, ControlAccesoPage, MensajeríaPage, MonitoreoAlarmaPage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
2.1 KiB
Dart
83 lines
2.1 KiB
Dart
import '../database_helper.dart';
|
|
import '../../models/evento.dart';
|
|
|
|
class EventosDao {
|
|
final _db = DatabaseHelper.instance;
|
|
|
|
Future<List<Evento>> getAll() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', orderBy: 'timestamp DESC');
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<List<Evento>> getRecientes({int limit = 10}) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query(
|
|
'eventos',
|
|
orderBy: 'timestamp DESC',
|
|
limit: limit,
|
|
);
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<Evento?> getById(int id) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', where: 'id = ?', whereArgs: [id]);
|
|
return rows.isEmpty ? null : Evento.fromMap(rows.first);
|
|
}
|
|
|
|
Future<int> insert(Evento e) async {
|
|
final db = await _db.db;
|
|
return db.insert('eventos', e.toMap());
|
|
}
|
|
|
|
Future<int> registrar({
|
|
required String tipo,
|
|
required String titulo,
|
|
String? descripcion,
|
|
}) async {
|
|
final db = await _db.db;
|
|
final now = DateTime.now();
|
|
final hora =
|
|
'${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
|
|
return db.insert('eventos', {
|
|
'tipo': tipo,
|
|
'titulo': titulo,
|
|
'descripcion': descripcion,
|
|
'hora': hora,
|
|
'timestamp': now.toIso8601String(),
|
|
'leido': 0,
|
|
'sincronizado': 0,
|
|
});
|
|
}
|
|
|
|
Future<int> marcarLeido(int id) async {
|
|
final db = await _db.db;
|
|
return db.update(
|
|
'eventos',
|
|
{'leido': 1, 'sincronizado': 0},
|
|
where: 'id = ?',
|
|
whereArgs: [id],
|
|
);
|
|
}
|
|
|
|
Future<int> delete(int id) async {
|
|
final db = await _db.db;
|
|
return db.delete('eventos', where: 'id = ?', whereArgs: [id]);
|
|
}
|
|
|
|
Future<List<Evento>> getPendientes() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', where: 'sincronizado = 0');
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<int> contarNoLeidos() async {
|
|
final db = await _db.db;
|
|
final result = await db.rawQuery(
|
|
'SELECT COUNT(*) as c FROM eventos WHERE leido = 0',
|
|
);
|
|
return result.first['c'] as int;
|
|
}
|
|
}
|