1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-24 10:37:28 +02:00
immich/mobile/lib/modules/memories/services/memory.service.dart
Robert Vollmer bc3979029d
refactor(mobile): move error details to separate DB column (#6898)
* Add "details" column to LoggerMessage

* Include error details in log details page

* Move error details out of log message

* Add error message to mixin

* Create extension for HTTP Response logging

* Fix analyze errors

* format

* fix analyze errors, format again
2024-02-23 21:38:57 -06:00

55 lines
1.5 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/modules/memories/models/memory.dart';
import 'package:immich_mobile/shared/providers/api.provider.dart';
import 'package:immich_mobile/shared/providers/db.provider.dart';
import 'package:immich_mobile/shared/services/api.service.dart';
import 'package:isar/isar.dart';
import 'package:logging/logging.dart';
import 'package:openapi/api.dart';
final memoryServiceProvider = StateProvider<MemoryService>((ref) {
return MemoryService(
ref.watch(apiServiceProvider),
ref.watch(dbProvider),
);
});
class MemoryService {
final log = Logger("MemoryService");
final ApiService _apiService;
final Isar _db;
MemoryService(this._apiService, this._db);
Future<List<Memory>?> getMemoryLane() async {
try {
final now = DateTime.now();
final data = await _apiService.assetApi.getMemoryLane(
now.day,
now.month,
);
if (data == null) {
return null;
}
List<Memory> memories = [];
for (final MemoryLaneResponseDto(:title, :assets) in data) {
memories.add(
Memory(
title: title,
assets: await _db.assets.getAllByRemoteId(assets.map((e) => e.id)),
),
);
}
return memories.isNotEmpty ? memories : null;
} catch (error, stack) {
log.severe("Cannot get memories", error, stack);
return null;
}
}
}