2024-09-24 14:50:21 +02:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:http/http.dart';
|
2025-03-12 19:26:56 +05:30
|
|
|
import 'package:immich_mobile/domain/models/user.model.dart';
|
2025-03-14 08:50:26 +05:30
|
|
|
import 'package:immich_mobile/infrastructure/repositories/api.repository.dart';
|
2025-03-12 19:26:56 +05:30
|
|
|
import 'package:immich_mobile/infrastructure/utils/user.converter.dart';
|
2024-09-24 14:50:21 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
2025-06-19 18:25:18 -05:00
|
|
|
class UserApiRepository extends ApiRepository {
|
2024-09-24 14:50:21 +02:00
|
|
|
final UsersApi _api;
|
2025-03-14 08:50:26 +05:30
|
|
|
const UserApiRepository(this._api);
|
2024-09-24 14:50:21 +02:00
|
|
|
|
2025-03-14 08:50:26 +05:30
|
|
|
Future<UserDto?> getMyUser() async {
|
|
|
|
final (adminDto, preferenceDto) =
|
|
|
|
await (_api.getMyUser(), _api.getMyPreferences()).wait;
|
|
|
|
if (adminDto == null) return null;
|
|
|
|
|
|
|
|
return UserConverter.fromAdminDto(adminDto, preferenceDto);
|
2024-09-24 14:50:21 +02:00
|
|
|
}
|
|
|
|
|
2025-03-14 08:50:26 +05:30
|
|
|
Future<String> createProfileImage({
|
2024-09-24 14:50:21 +02:00
|
|
|
required String name,
|
|
|
|
required Uint8List data,
|
|
|
|
}) async {
|
2025-03-14 08:50:26 +05:30
|
|
|
final res = await checkNull(
|
2024-09-24 14:50:21 +02:00
|
|
|
_api.createProfileImage(
|
|
|
|
MultipartFile.fromBytes('file', data, filename: name),
|
|
|
|
),
|
|
|
|
);
|
2025-03-14 08:50:26 +05:30
|
|
|
return res.profileImagePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<UserDto>> getAll() async {
|
|
|
|
final dto = await checkNull(_api.searchUsers());
|
|
|
|
return dto.map(UserConverter.fromSimpleUserDto).toList();
|
2024-09-24 14:50:21 +02:00
|
|
|
}
|
|
|
|
}
|