From 692ccd2e9e8852ea819832b9b285e5fd91ad3ec4 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 4 May 2024 20:07:27 +0800 Subject: [PATCH] Add use case to list archived files --- app/lib/use_case/list_archived_file.dart | 13 +++++++++++++ np_db/lib/src/api.dart | 1 + np_db_sqlite/lib/src/database/file_extension.dart | 5 +++++ np_db_sqlite/lib/src/files_query_builder.dart | 14 ++++++++++++++ np_db_sqlite/lib/src/sqlite_api.dart | 2 ++ 5 files changed, 35 insertions(+) create mode 100644 app/lib/use_case/list_archived_file.dart diff --git a/app/lib/use_case/list_archived_file.dart b/app/lib/use_case/list_archived_file.dart new file mode 100644 index 00000000..3ce343a6 --- /dev/null +++ b/app/lib/use_case/list_archived_file.dart @@ -0,0 +1,13 @@ +import 'package:nc_photos/account.dart'; +import 'package:nc_photos/di_container.dart'; +import 'package:nc_photos/entity/file_descriptor.dart'; + +class ListArchivedFile { + const ListArchivedFile(this._c); + + /// Return list of archived files + Future> call(Account account, String shareDirPath) => + _c.fileRepo2.getFileDescriptors(account, shareDirPath, isArchived: true); + + final DiContainer _c; +} diff --git a/np_db/lib/src/api.dart b/np_db/lib/src/api.dart index 4124aee4..fa83ddf5 100644 --- a/np_db/lib/src/api.dart +++ b/np_db/lib/src/api.dart @@ -346,6 +346,7 @@ abstract class NpDb { List? relativePathKeywords, String? location, bool? isFavorite, + bool? isArchived, List? mimes, TimeRange? timeRange, int? offset, diff --git a/np_db_sqlite/lib/src/database/file_extension.dart b/np_db_sqlite/lib/src/database/file_extension.dart index 0dd25980..2871e51e 100644 --- a/np_db_sqlite/lib/src/database/file_extension.dart +++ b/np_db_sqlite/lib/src/database/file_extension.dart @@ -401,6 +401,7 @@ extension SqliteDbFileExtension on SqliteDb { List? relativePathKeywords, String? location, bool? isFavorite, + bool? isArchived, List? mimes, TimeRange? timeRange, int? offset, @@ -415,6 +416,7 @@ extension SqliteDbFileExtension on SqliteDb { "relativePathKeywords: $relativePathKeywords, " "location: $location, " "isFavorite: $isFavorite, " + "isArchived: $isArchived, " "mimes: $mimes, " "timeRange: $timeRange, " "offset: $offset, " @@ -477,6 +479,9 @@ extension SqliteDbFileExtension on SqliteDb { if (isFavorite != null) { q.byFavorite(isFavorite); } + if (isArchived != null) { + q.byArchived(isArchived); + } return q.build(); }); if (excludeRelativeRoots != null) { diff --git a/np_db_sqlite/lib/src/files_query_builder.dart b/np_db_sqlite/lib/src/files_query_builder.dart index 040d4f70..d903b35e 100644 --- a/np_db_sqlite/lib/src/files_query_builder.dart +++ b/np_db_sqlite/lib/src/files_query_builder.dart @@ -87,6 +87,10 @@ class FilesQueryBuilder { _byFavorite = favorite; } + void byArchived(bool archived) { + _byArchived = archived; + } + void byDirRowId(int dirRowId) { _byDirRowId = dirRowId; } @@ -188,6 +192,15 @@ class FilesQueryBuilder { db.accountFiles.isFavorite.isNull()); } } + if (_byArchived != null) { + if (_byArchived!) { + query.where(db.accountFiles.isArchived.equals(true)); + } else { + // null are treated as false + query.where(db.accountFiles.isArchived.equals(false) | + db.accountFiles.isArchived.isNull()); + } + } if (_byDirRowId != null) { query.where(db.dirFiles.dir.equals(_byDirRowId!)); } @@ -232,6 +245,7 @@ class FilesQueryBuilder { List? _byOrDirRowIds; List? _byMimePatterns; bool? _byFavorite; + bool? _byArchived; int? _byDirRowId; int? _byServerRowId; String? _byLocation; diff --git a/np_db_sqlite/lib/src/sqlite_api.dart b/np_db_sqlite/lib/src/sqlite_api.dart index 45bf688e..f2587c7b 100644 --- a/np_db_sqlite/lib/src/sqlite_api.dart +++ b/np_db_sqlite/lib/src/sqlite_api.dart @@ -443,6 +443,7 @@ class NpDbSqlite implements NpDb { List? relativePathKeywords, String? location, bool? isFavorite, + bool? isArchived, List? mimes, TimeRange? timeRange, int? offset, @@ -458,6 +459,7 @@ class NpDbSqlite implements NpDb { relativePathKeywords: relativePathKeywords, location: location, isFavorite: isFavorite, + isArchived: isArchived, mimes: mimes, timeRange: timeRange, offset: offset,