mirror of
https://github.com/immich-app/immich.git
synced 2025-12-17 01:11:13 +03:00
refactor(server): user endpoints (#9730)
* refactor(server): user endpoints * fix repos * fix unit tests --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev> Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class User {
|
||||
|
||||
Id get isarId => fastHash(id);
|
||||
|
||||
User.fromUserDto(UserResponseDto dto)
|
||||
User.fromUserDto(UserAdminResponseDto dto)
|
||||
: id = dto.id,
|
||||
updatedAt = dto.updatedAt,
|
||||
email = dto.email,
|
||||
@@ -44,21 +44,21 @@ class User {
|
||||
|
||||
User.fromPartnerDto(PartnerResponseDto dto)
|
||||
: id = dto.id,
|
||||
updatedAt = dto.updatedAt,
|
||||
updatedAt = DateTime.now(),
|
||||
email = dto.email,
|
||||
name = dto.name,
|
||||
isPartnerSharedBy = false,
|
||||
isPartnerSharedWith = false,
|
||||
profileImagePath = dto.profileImagePath,
|
||||
isAdmin = dto.isAdmin,
|
||||
memoryEnabled = dto.memoriesEnabled ?? false,
|
||||
isAdmin = false,
|
||||
memoryEnabled = false,
|
||||
avatarColor = dto.avatarColor.toAvatarColor(),
|
||||
inTimeline = dto.inTimeline ?? false,
|
||||
quotaUsageInBytes = dto.quotaUsageInBytes ?? 0,
|
||||
quotaSizeInBytes = dto.quotaSizeInBytes ?? 0;
|
||||
quotaUsageInBytes = 0,
|
||||
quotaSizeInBytes = 0;
|
||||
|
||||
/// Base user dto used where the complete user object is not required
|
||||
User.fromSimpleUserDto(UserDto dto)
|
||||
User.fromSimpleUserDto(UserResponseDto dto)
|
||||
: id = dto.id,
|
||||
email = dto.email,
|
||||
name = dto.name,
|
||||
|
||||
@@ -138,11 +138,9 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
|
||||
Future<bool> changePassword(String newPassword) async {
|
||||
try {
|
||||
await _apiService.userApi.updateUser(
|
||||
UpdateUserDto(
|
||||
id: state.userId,
|
||||
await _apiService.userApi.updateMyUser(
|
||||
UserUpdateMeDto(
|
||||
password: newPassword,
|
||||
shouldChangePassword: false,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -178,9 +176,9 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
user = offlineUser;
|
||||
retResult = false;
|
||||
} else {
|
||||
UserResponseDto? userResponseDto;
|
||||
UserAdminResponseDto? userResponseDto;
|
||||
try {
|
||||
userResponseDto = await _apiService.userApi.getMyUserInfo();
|
||||
userResponseDto = await _apiService.userApi.getMyUser();
|
||||
} on ApiException catch (error, stackTrace) {
|
||||
_log.severe(
|
||||
"Error getting user information from the server [API EXCEPTION]",
|
||||
|
||||
@@ -20,7 +20,7 @@ class CurrentUserProvider extends StateNotifier<User?> {
|
||||
|
||||
refresh() async {
|
||||
try {
|
||||
final user = await _apiService.userApi.getMyUserInfo();
|
||||
final user = await _apiService.userApi.getMyUser();
|
||||
if (user != null) {
|
||||
Store.put(
|
||||
StoreKey.currentUser,
|
||||
|
||||
@@ -57,7 +57,7 @@ class TabNavigationObserver extends AutoRouterObserver {
|
||||
// Update user info
|
||||
try {
|
||||
final userResponseDto =
|
||||
await ref.read(apiServiceProvider).userApi.getMyUserInfo();
|
||||
await ref.read(apiServiceProvider).userApi.getMyUser();
|
||||
|
||||
if (userResponseDto == null) {
|
||||
return;
|
||||
|
||||
@@ -37,10 +37,10 @@ class UserService {
|
||||
this._partnerService,
|
||||
);
|
||||
|
||||
Future<List<User>?> _getAllUsers({required bool isAll}) async {
|
||||
Future<List<User>?> _getAllUsers() async {
|
||||
try {
|
||||
final dto = await _apiService.userApi.getAllUsers(isAll);
|
||||
return dto?.map(User.fromUserDto).toList();
|
||||
final dto = await _apiService.userApi.searchUsers();
|
||||
return dto?.map(User.fromSimpleUserDto).toList();
|
||||
} catch (e) {
|
||||
_log.warning("Failed get all users", e);
|
||||
return null;
|
||||
@@ -71,7 +71,7 @@ class UserService {
|
||||
}
|
||||
|
||||
Future<List<User>?> getUsersFromServer() async {
|
||||
final List<User>? users = await _getAllUsers(isAll: true);
|
||||
final List<User>? users = await _getAllUsers();
|
||||
final List<User>? sharedBy =
|
||||
await _partnerService.getPartners(PartnerDirection.sharedBy);
|
||||
final List<User>? sharedWith =
|
||||
|
||||
Reference in New Issue
Block a user