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
@@ -6,16 +6,16 @@ class AppSettingService {
const AppSettingService(this._store);
Future<T> getSetting<T>(AppSetting<T> setting) async {
Future<T> get<T>(AppSetting<T> setting) async {
final value = await _store.tryGet(setting.storeKey);
return value ?? setting.defaultValue;
}
Future<bool> setSetting<T>(AppSetting<T> setting, T value) async {
return await _store.set(setting.storeKey, value);
Future<bool> upsert<T>(AppSetting<T> setting, T value) async {
return await _store.upsert(setting.storeKey, value);
}
Stream<T> watchSetting<T>(AppSetting<T> setting) {
Stream<T> watch<T>(AppSetting<T> setting) {
return _store
.watch(setting.storeKey)
.map((value) => value ?? setting.defaultValue);
@@ -16,7 +16,7 @@ import 'package:openapi/api.dart';
class AssetSyncService with LogMixin {
const AssetSyncService();
Future<bool> doFullRemoteSyncForUserDrift(
Future<bool> performFullRemoteSyncForUser(
User user, {
DateTime? updatedUtil,
int? limit,
@@ -49,12 +49,11 @@ class AssetSyncService with LogMixin {
final assetsFromServer =
assets.map(Asset.remote).sorted(Asset.compareByRemoteId);
final assetsInDb =
await di<IAssetRepository>().fetchRemoteAssetsForIds(
final assetsInDb = await di<IAssetRepository>().getForRemoteIds(
assetsFromServer.map((a) => a.remoteId!).toList(),
);
await _syncAssetsToDbDrift(
await _syncAssetsToDb(
assetsFromServer,
assetsInDb,
Asset.compareByRemoteId,
@@ -73,7 +72,7 @@ class AssetSyncService with LogMixin {
});
}
Future<void> _syncAssetsToDbDrift(
Future<void> _syncAssetsToDb(
List<Asset> newAssets,
List<Asset> existingAssets,
Comparator<Asset> compare, {
@@ -88,9 +87,9 @@ class AssetSyncService with LogMixin {
final assetsToAdd = toAdd.followedBy(toUpdate);
await di<IAssetRepository>().addAll(assetsToAdd);
await di<IAssetRepository>().upsertAll(assetsToAdd);
await di<IAssetRepository>()
.deleteAssetsForIds(assetsToRemove.map((a) => a.id).toList());
.deleteIds(assetsToRemove.map((a) => a.id).toList());
}
/// Returns a triple (toAdd, toUpdate, toRemove)
@@ -107,7 +107,7 @@ class LoginService with LogMixin {
return null;
}
Future<bool> tryLoginFromSplash() async {
Future<bool> tryAutoLogin() async {
final serverEndpoint =
await di<IStoreRepository>().tryGet(StoreKey.serverEndpoint);
if (serverEndpoint == null) {