- Add offline-first SQLite architecture with DatabaseHelper singleton, 12 CREATE TABLE statements and full seed data on first launch - Add 10 models (fromMap/toMap) and 12 DAOs with CRUD + getPendientes() - Add ApiAuthService (JWT via SharedPreferences) and Sincronizador skeleton - Move login auth from SQLite to SharedPreferences with SHA-256 PIN hash; default PIN 123456, platform-independent (no native plugin required) - Add seguridad_page.dart: change PIN form (current → new → confirm) - Add Cerrar Sesión with confirmation dialog and full stack clear - Redesign settings_page.dart with AppColors dark theme; add Sistema section with "Inicializar base de datos" and "Inicializar sincronización" - Fix Linux desktop: sqflite_common_ffi with platform detection in DatabaseHelper - Fix ScrollController conflict on Linux: primary: false on all IndexedStack pages - Update plan_proyecto.md with session 2–3 progress and auth roadmap Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.3 KiB
Dart
50 lines
1.3 KiB
Dart
import '../database_helper.dart';
|
|
import '../../models/acceso.dart';
|
|
|
|
class AccesosDao {
|
|
final _db = DatabaseHelper.instance;
|
|
|
|
Future<List<Acceso>> getAll() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('accesos', orderBy: 'timestamp DESC');
|
|
return rows.map(Acceso.fromMap).toList();
|
|
}
|
|
|
|
Future<List<Acceso>> getRecientes({int limit = 20}) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query(
|
|
'accesos',
|
|
orderBy: 'timestamp DESC',
|
|
limit: limit,
|
|
);
|
|
return rows.map(Acceso.fromMap).toList();
|
|
}
|
|
|
|
Future<List<Acceso>> getByPuerta(int puertaId) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query(
|
|
'accesos',
|
|
where: 'puerta_id = ?',
|
|
whereArgs: [puertaId],
|
|
orderBy: 'timestamp DESC',
|
|
);
|
|
return rows.map(Acceso.fromMap).toList();
|
|
}
|
|
|
|
Future<int> insert(Acceso a) async {
|
|
final db = await _db.db;
|
|
return db.insert('accesos', a.toMap());
|
|
}
|
|
|
|
Future<int> delete(int id) async {
|
|
final db = await _db.db;
|
|
return db.delete('accesos', where: 'id = ?', whereArgs: [id]);
|
|
}
|
|
|
|
Future<List<Acceso>> getPendientes() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('accesos', where: 'sincronizado = 0');
|
|
return rows.map(Acceso.fromMap).toList();
|
|
}
|
|
}
|