2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-06-25 20:46:51 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:http/http.dart';
|
2022-06-23 06:14:14 +02:00
|
|
|
import 'package:http_parser/http_parser.dart';
|
2022-05-29 05:35:45 +02:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:immich_mobile/shared/services/api.service.dart';
|
2022-05-29 05:35:45 +02:00
|
|
|
import 'package:immich_mobile/utils/files_helper.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
final userServiceProvider = Provider(
|
|
|
|
(ref) => UserService(
|
|
|
|
ref.watch(apiServiceProvider),
|
|
|
|
),
|
|
|
|
);
|
2022-06-25 20:46:51 +02:00
|
|
|
|
2022-04-24 04:08:45 +02:00
|
|
|
class UserService {
|
2022-07-13 14:23:48 +02:00
|
|
|
final ApiService _apiService;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
UserService(this._apiService);
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
Future<List<User>?> getAllUsers({required bool isAll}) async {
|
2022-07-13 14:23:48 +02:00
|
|
|
try {
|
2023-02-06 09:13:32 +02:00
|
|
|
final dto = await _apiService.userApi.getAllUsers(isAll);
|
|
|
|
return dto?.map(User.fromDto).toList();
|
2022-04-24 04:08:45 +02:00
|
|
|
} catch (e) {
|
2022-07-13 14:23:48 +02:00
|
|
|
debugPrint("Error [getAllUsersInfo] ${e.toString()}");
|
|
|
|
return null;
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-29 05:35:45 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
Future<CreateProfileImageResponseDto?> uploadProfileImage(XFile image) async {
|
2022-05-29 05:35:45 +02:00
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
var mimeType = FileHelper.getMimeType(image.path);
|
|
|
|
|
|
|
|
return await _apiService.userApi.createProfileImage(
|
|
|
|
MultipartFile.fromBytes(
|
|
|
|
'file',
|
|
|
|
await image.readAsBytes(),
|
|
|
|
filename: image.name,
|
|
|
|
contentType: MediaType(
|
|
|
|
mimeType["type"],
|
|
|
|
mimeType["subType"],
|
|
|
|
),
|
|
|
|
),
|
2022-05-29 05:35:45 +02:00
|
|
|
);
|
|
|
|
} catch (e) {
|
2022-07-13 14:23:48 +02:00
|
|
|
debugPrint("Error [uploadProfileImage] ${e.toString()}");
|
2022-05-29 05:35:45 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|