refactor repositories
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user