refactor repositories

This commit is contained in:
shenlong-tanwen
2024-09-21 20:04:05 +05:30
parent d6495f014d
commit e810512285
23 changed files with 142 additions and 127 deletions
@@ -1,27 +1,23 @@
import 'dart:async';
import 'package:immich_mobile/domain/models/asset.model.dart';
import 'package:immich_mobile/domain/models/render_list.model.dart';
abstract class IAssetRepository {
/// Batch insert asset
FutureOr<bool> addAll(Iterable<Asset> assets);
abstract interface class IAssetRepository {
/// Batch upsert asset
FutureOr<bool> upsertAll(Iterable<Asset> assets);
/// Removes assets with the [localIds]
FutureOr<List<Asset>> fetchLocalAssetsForIds(List<String> localIds);
FutureOr<List<Asset>> getForLocalIds(List<String> localIds);
/// Removes assets with the [remoteIds]
FutureOr<List<Asset>> fetchRemoteAssetsForIds(List<String> remoteIds);
/// Removes assets with the given [ids]
FutureOr<void> deleteAssetsForIds(List<int> ids);
/// Removes all assets
FutureOr<bool> clearAll();
FutureOr<List<Asset>> getForRemoteIds(List<String> remoteIds);
/// Fetch assets from the [offset] with the [limit]
FutureOr<List<Asset>> fetchAssets({int? offset, int? limit});
FutureOr<List<Asset>> getAll({int? offset, int? limit});
/// Streams assets as groups grouped by the group type passed
Stream<RenderList> watchRenderList();
/// Removes assets with the given [ids]
FutureOr<void> deleteIds(List<int> ids);
/// Removes all assets
FutureOr<bool> deleteAll();
}
@@ -2,19 +2,19 @@ import 'dart:async';
import 'package:immich_mobile/domain/models/log.model.dart';
abstract class ILogRepository {
/// Fetches all logs
FutureOr<List<LogMessage>> fetchAll();
abstract interface class ILogRepository {
/// Inserts a new log into the DB
FutureOr<bool> add(LogMessage log);
FutureOr<bool> create(LogMessage log);
/// Bulk insert logs into DB
FutureOr<bool> addAll(List<LogMessage> log);
FutureOr<bool> createAll(List<LogMessage> log);
/// Fetches all logs
FutureOr<List<LogMessage>> getAll();
/// Clears all logs
FutureOr<bool> clear();
FutureOr<bool> deleteAll();
/// Truncates the logs to the most recent [limit]. Defaults to recent 250 logs
FutureOr<void> truncateLogs({int limit = 250});
FutureOr<void> truncate({int limit = 250});
}
@@ -0,0 +1,6 @@
import 'package:immich_mobile/domain/models/render_list.model.dart';
abstract interface class IRenderListRepository {
/// Streams the [RenderList] for the main timeline
Stream<RenderList> watchAll();
}
@@ -12,16 +12,16 @@ abstract class IStoreConverter<T, U> {
FutureOr<T?> fromPrimitive(U value);
}
abstract class IStoreRepository {
FutureOr<T?> tryGet<T, U>(StoreKey<T, U> key);
abstract interface class IStoreRepository {
FutureOr<bool> upsert<T, U>(StoreKey<T, U> key, T value);
FutureOr<T> get<T, U>(StoreKey<T, U> key);
FutureOr<bool> set<T, U>(StoreKey<T, U> key, T value);
FutureOr<void> delete(StoreKey key);
FutureOr<T?> tryGet<T, U>(StoreKey<T, U> key);
Stream<T?> watch<T, U>(StoreKey<T, U> key);
FutureOr<void> clearStore();
FutureOr<void> delete(StoreKey key);
FutureOr<void> deleteAll();
}
@@ -2,10 +2,10 @@ import 'dart:async';
import 'package:immich_mobile/domain/models/user.model.dart';
abstract class IUserRepository {
/// Fetches user
FutureOr<User?> fetch(String userId);
abstract interface class IUserRepository {
/// Insert user
FutureOr<bool> add(User user);
FutureOr<bool> upsert(User user);
/// Fetches user
FutureOr<User?> getForId(String userId);
}