2024-09-16 20:26:14 +00:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/entities/backup_album.entity.dart';
|
|
|
|
import 'package:immich_mobile/interfaces/backup.interface.dart';
|
|
|
|
import 'package:immich_mobile/providers/db.provider.dart';
|
2024-09-30 14:37:30 +00:00
|
|
|
import 'package:immich_mobile/repositories/database.repository.dart';
|
2024-09-16 20:26:14 +00:00
|
|
|
import 'package:isar/isar.dart';
|
|
|
|
|
|
|
|
final backupRepositoryProvider =
|
|
|
|
Provider((ref) => BackupRepository(ref.watch(dbProvider)));
|
|
|
|
|
2024-09-30 14:37:30 +00:00
|
|
|
class BackupRepository extends DatabaseRepository implements IBackupRepository {
|
|
|
|
BackupRepository(super.db);
|
2024-09-16 20:26:14 +00:00
|
|
|
|
2024-09-30 14:37:30 +00:00
|
|
|
@override
|
|
|
|
Future<List<BackupAlbum>> getAll({BackupAlbumSort? sort}) {
|
|
|
|
final baseQuery = db.backupAlbums.where();
|
|
|
|
final QueryBuilder<BackupAlbum, BackupAlbum, QAfterSortBy> query;
|
|
|
|
switch (sort) {
|
|
|
|
case null:
|
|
|
|
query = baseQuery.noOp();
|
|
|
|
case BackupAlbumSort.id:
|
|
|
|
query = baseQuery.sortById();
|
|
|
|
}
|
|
|
|
return query.findAll();
|
|
|
|
}
|
2024-09-16 20:26:14 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<List<String>> getIdsBySelection(BackupSelection backup) =>
|
2024-09-30 14:37:30 +00:00
|
|
|
db.backupAlbums.filter().selectionEqualTo(backup).idProperty().findAll();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<List<BackupAlbum>> getAllBySelection(BackupSelection backup) =>
|
|
|
|
db.backupAlbums.filter().selectionEqualTo(backup).findAll();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> deleteAll(List<int> ids) =>
|
|
|
|
txn(() => db.backupAlbums.deleteAll(ids));
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> updateAll(List<BackupAlbum> backupAlbums) =>
|
|
|
|
txn(() => db.backupAlbums.putAll(backupAlbums));
|
2024-09-16 20:26:14 +00:00
|
|
|
}
|