mirror of
https://github.com/immich-app/immich.git
synced 2024-11-17 19:08:49 -07:00
983473261b
* build(mobile): add riverpod_lint * refactor(mobile): riverpod_generator for providers * test(mobile): fix integration test helper * refactor: ApiService to riverpod codegen * refactor(mobile): return curatedcontent instead of people dto * refactor: person provider to asyncnotifier * mobile: update service providers to use lambda * mobile: update scaffoldbody default error icon * remove logger mixin --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
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';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:openapi/api.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
part 'person.service.g.dart';
|
|
|
|
@riverpod
|
|
PersonService personService(PersonServiceRef ref) =>
|
|
PersonService(ref.read(apiServiceProvider));
|
|
|
|
class PersonService {
|
|
final Logger _log = Logger("PersonService");
|
|
final ApiService _apiService;
|
|
|
|
PersonService(this._apiService);
|
|
|
|
Future<List<PersonResponseDto>> getCuratedPeople() async {
|
|
try {
|
|
final peopleResponseDto = await _apiService.personApi.getAllPeople();
|
|
return peopleResponseDto?.people ?? [];
|
|
} catch (error, stack) {
|
|
_log.severe("Error while fetching curated people", error, stack);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
Future<List<Asset>?> getPersonAssets(String id) async {
|
|
try {
|
|
final assets = await _apiService.personApi.getPersonAssets(id);
|
|
return assets?.map((e) => Asset.remote(e)).toList();
|
|
} catch (error, stack) {
|
|
_log.severe("Error while fetching person assets", error, stack);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<PersonResponseDto?> updateName(String id, String name) async {
|
|
try {
|
|
return await _apiService.personApi.updatePerson(
|
|
id,
|
|
PersonUpdateDto(
|
|
name: name,
|
|
),
|
|
);
|
|
} catch (error, stack) {
|
|
_log.severe("Error while updating person name", error, stack);
|
|
}
|
|
return null;
|
|
}
|
|
}
|