mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
31 lines
1.3 KiB
Dart
31 lines
1.3 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/domain/models/person.model.dart';
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
import 'package:immich_mobile/repositories/api.repository.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
final personApiRepositoryProvider = Provider((ref) => PersonApiRepository(ref.watch(apiServiceProvider).peopleApi));
|
|
|
|
class PersonApiRepository extends ApiRepository {
|
|
final PeopleApi _api;
|
|
|
|
PersonApiRepository(this._api);
|
|
|
|
Future<List<Person>> getAll() async {
|
|
final dto = await checkNull(_api.getAllPeople());
|
|
return dto.people.map(_toPerson).toList();
|
|
}
|
|
|
|
Future<Person> update(String id, {String? name, DateTime? birthday}) async {
|
|
final birthdayUtc = birthday == null ? null : DateTime.utc(birthday.year, birthday.month, birthday.day);
|
|
final dto = PersonUpdateDto(
|
|
name: name == null ? const Optional.absent() : Optional.present(name),
|
|
birthDate: birthdayUtc == null ? const Optional.absent() : Optional.present(birthdayUtc),
|
|
);
|
|
final response = await checkNull(_api.updatePerson(id, dto));
|
|
return _toPerson(response);
|
|
}
|
|
|
|
static Person _toPerson(PersonResponseDto dto) =>
|
|
.new(birthDate: dto.birthDate, id: dto.id, name: dto.name, updatedAt: dto.updatedAt.value);
|
|
}
|