2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
|
|
|
import 'package:immich_mobile/shared/services/api.service.dart';
|
2023-11-19 18:04:44 +02:00
|
|
|
import 'package:logging/logging.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2023-11-19 18:04:44 +02:00
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
part 'person.service.g.dart';
|
|
|
|
|
|
|
|
@riverpod
|
|
|
|
PersonService personService(PersonServiceRef ref) =>
|
|
|
|
PersonService(ref.read(apiServiceProvider));
|
2023-06-23 17:44:02 +02:00
|
|
|
|
|
|
|
class PersonService {
|
2023-11-19 18:04:44 +02:00
|
|
|
final Logger _log = Logger("PersonService");
|
2023-06-23 17:44:02 +02:00
|
|
|
final ApiService _apiService;
|
|
|
|
|
|
|
|
PersonService(this._apiService);
|
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
Future<List<PersonResponseDto>> getCuratedPeople() async {
|
2023-06-23 17:44:02 +02:00
|
|
|
try {
|
2023-07-18 20:09:43 +02:00
|
|
|
final peopleResponseDto = await _apiService.personApi.getAllPeople();
|
2023-11-19 18:04:44 +02:00
|
|
|
return peopleResponseDto?.people ?? [];
|
|
|
|
} catch (error, stack) {
|
|
|
|
_log.severe("Error while fetching curated people", error, stack);
|
|
|
|
return [];
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<Asset>?> getPersonAssets(String id) async {
|
|
|
|
try {
|
|
|
|
final assets = await _apiService.personApi.getPersonAssets(id);
|
2023-11-19 18:04:44 +02:00
|
|
|
return assets?.map((e) => Asset.remote(e)).toList();
|
|
|
|
} catch (error, stack) {
|
|
|
|
_log.severe("Error while fetching person assets", error, stack);
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
2023-11-19 18:04:44 +02:00
|
|
|
return null;
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<PersonResponseDto?> updateName(String id, String name) async {
|
|
|
|
try {
|
|
|
|
return await _apiService.personApi.updatePerson(
|
|
|
|
id,
|
|
|
|
PersonUpdateDto(
|
|
|
|
name: name,
|
|
|
|
),
|
|
|
|
);
|
2023-11-19 18:04:44 +02:00
|
|
|
} catch (error, stack) {
|
|
|
|
_log.severe("Error while updating person name", error, stack);
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
2023-11-19 18:04:44 +02:00
|
|
|
return null;
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
|
|
|
}
|