78 lines
2.2 KiB
Dart
78 lines
2.2 KiB
Dart
|
|
import '../datasources/local_database.dart';
|
||
|
|
import '../../domain/entities/destino.dart';
|
||
|
|
import '../../domain/entities/biblioteca.dart';
|
||
|
|
|
||
|
|
class ConfigRepository {
|
||
|
|
// Destinos
|
||
|
|
Future<List<Destino>> getDestinos() async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
final results = await db.query('destinos');
|
||
|
|
return results.map((m) => Destino.fromMap(m)).toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<Destino?> getDestinoActivo() async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
final results = await db.query(
|
||
|
|
'destinos',
|
||
|
|
where: 'activo = ?',
|
||
|
|
whereArgs: [1],
|
||
|
|
limit: 1,
|
||
|
|
);
|
||
|
|
if (results.isEmpty) return null;
|
||
|
|
return Destino.fromMap(results.first);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<int> insertDestino(Destino destino) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
return db.insert('destinos', destino.toMap());
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> updateDestino(Destino destino) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
await db.update(
|
||
|
|
'destinos',
|
||
|
|
destino.toMap(),
|
||
|
|
where: 'id = ?',
|
||
|
|
whereArgs: [destino.id],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> deleteDestino(int id) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
await db.delete('destinos', where: 'id = ?', whereArgs: [id]);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> setDestinoActivo(int id) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
await db.update('destinos', {'activo': 0});
|
||
|
|
await db.update('destinos', {'activo': 1}, where: 'id = ?', whereArgs: [id]);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Bibliotecas
|
||
|
|
Future<List<Biblioteca>> getBibliotecas() async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
final results = await db.query('bibliotecas');
|
||
|
|
return results.map((m) => Biblioteca.fromMap(m)).toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<int> insertBiblioteca(Biblioteca biblioteca) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
return db.insert('bibliotecas', biblioteca.toMap());
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> updateBiblioteca(Biblioteca biblioteca) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
await db.update(
|
||
|
|
'bibliotecas',
|
||
|
|
biblioteca.toMap(),
|
||
|
|
where: 'id = ?',
|
||
|
|
whereArgs: [biblioteca.id],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> deleteBiblioteca(int id) async {
|
||
|
|
final db = await LocalDatabase.database;
|
||
|
|
await db.delete('bibliotecas', where: 'id = ?', whereArgs: [id]);
|
||
|
|
}
|
||
|
|
}
|