mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 11:24:37 +02:00
b05132a01a
* refactor: server info model to use data classes instead of dtos * mobile: add return types and refactor private variables in map / stack --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
65 lines
1.8 KiB
Dart
65 lines
1.8 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/shared/models/asset.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 mapServiceProvider = Provider(
|
|
(ref) => MapSerivce(
|
|
ref.read(apiServiceProvider),
|
|
ref.read(dbProvider),
|
|
),
|
|
);
|
|
|
|
class MapSerivce {
|
|
final ApiService _apiService;
|
|
final Isar _db;
|
|
final _log = Logger("MapService");
|
|
|
|
MapSerivce(this._apiService, this._db);
|
|
|
|
Future<List<MapMarkerResponseDto>> getMapMarkers({
|
|
bool? isFavorite,
|
|
bool? withArchived,
|
|
DateTime? fileCreatedAfter,
|
|
DateTime? fileCreatedBefore,
|
|
}) async {
|
|
try {
|
|
final markers = await _apiService.assetApi.getMapMarkers(
|
|
isFavorite: isFavorite,
|
|
isArchived: withArchived,
|
|
fileCreatedAfter: fileCreatedAfter,
|
|
fileCreatedBefore: fileCreatedBefore,
|
|
);
|
|
|
|
return markers ?? [];
|
|
} catch (error, stack) {
|
|
_log.severe("Cannot get map markers ${error.toString()}", error, stack);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
Future<Asset?> getAssetForMarkerId(String remoteId) async {
|
|
try {
|
|
final assets = await _db.assets.getAllByRemoteId([remoteId]);
|
|
if (assets.isNotEmpty) return assets[0];
|
|
|
|
final dto = await _apiService.assetApi.getAssetById(remoteId);
|
|
if (dto == null) {
|
|
return null;
|
|
}
|
|
return Asset.remote(dto);
|
|
} catch (error, stack) {
|
|
_log.severe(
|
|
"Cannot get asset for marker ${error.toString()}",
|
|
error,
|
|
stack,
|
|
);
|
|
return null;
|
|
}
|
|
}
|
|
}
|