2024-09-24 14:50:21 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2025-06-20 11:45:31 -05:00
|
|
|
import 'package:immich_mobile/domain/models/person.model.dart';
|
2024-09-24 14:50:21 +02:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
2024-09-30 16:37:30 +02:00
|
|
|
import 'package:immich_mobile/repositories/api.repository.dart';
|
2024-09-24 14:50:21 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
final personApiRepositoryProvider = Provider((ref) => PersonApiRepository(ref.watch(apiServiceProvider).peopleApi));
|
2024-09-24 14:50:21 +02:00
|
|
|
|
2025-06-20 11:45:31 -05:00
|
|
|
class PersonApiRepository extends ApiRepository {
|
2024-09-24 14:50:21 +02:00
|
|
|
final PeopleApi _api;
|
|
|
|
|
|
|
|
|
|
PersonApiRepository(this._api);
|
|
|
|
|
|
2025-07-18 22:21:39 +08:00
|
|
|
Future<List<PersonDto>> getAll() async {
|
2024-09-24 14:50:21 +02:00
|
|
|
final dto = await checkNull(_api.getAllPeople());
|
|
|
|
|
return dto.people.map(_toPerson).toList();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-29 22:07:53 -05:00
|
|
|
Future<PersonDto> update(String id, {String? name, DateTime? birthday}) async {
|
|
|
|
|
final dto = await checkNull(_api.updatePerson(id, PersonUpdateDto(name: name, birthDate: birthday)));
|
2024-09-24 14:50:21 +02:00
|
|
|
return _toPerson(dto);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 20:38:29 +02:00
|
|
|
Future<void> merge(String targetId, List<String> mergeIds) async {
|
|
|
|
|
await checkNull(_api.mergePerson(targetId, MergePersonDto(ids: mergeIds)));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 22:21:39 +08:00
|
|
|
static PersonDto _toPerson(PersonResponseDto dto) => PersonDto(
|
2025-07-29 00:34:03 +05:30
|
|
|
birthDate: dto.birthDate,
|
|
|
|
|
id: dto.id,
|
|
|
|
|
isHidden: dto.isHidden,
|
|
|
|
|
name: dto.name,
|
|
|
|
|
thumbnailPath: dto.thumbnailPath,
|
|
|
|
|
);
|
2024-09-24 14:50:21 +02:00
|
|
|
}
|