mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
refactor(mobile): introduce Album & User classes (#1561)
replace usages of AlbumResponseDto with Album replace usages of UserResponseDto with User
This commit is contained in:
parent
527aa61a87
commit
2139853dd9
25 changed files with 475 additions and 255 deletions
94
mobile/lib/shared/models/user.dart
Normal file
94
mobile/lib/shared/models/user.dart
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import 'package:openapi/api.dart';
|
||||
|
||||
class User {
|
||||
User({
|
||||
required this.id,
|
||||
required this.email,
|
||||
required this.firstName,
|
||||
required this.lastName,
|
||||
required this.profileImagePath,
|
||||
required this.isAdmin,
|
||||
required this.oauthId,
|
||||
});
|
||||
|
||||
User.fromDto(UserResponseDto dto)
|
||||
: id = dto.id,
|
||||
email = dto.email,
|
||||
firstName = dto.firstName,
|
||||
lastName = dto.lastName,
|
||||
profileImagePath = dto.profileImagePath,
|
||||
isAdmin = dto.isAdmin,
|
||||
oauthId = dto.oauthId;
|
||||
|
||||
String id;
|
||||
String email;
|
||||
String firstName;
|
||||
String lastName;
|
||||
String profileImagePath;
|
||||
bool isAdmin;
|
||||
String oauthId;
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
if (other is! User) return false;
|
||||
return id == other.id &&
|
||||
email == other.email &&
|
||||
firstName == other.firstName &&
|
||||
lastName == other.lastName &&
|
||||
profileImagePath == other.profileImagePath &&
|
||||
isAdmin == other.isAdmin &&
|
||||
oauthId == other.oauthId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
id.hashCode ^
|
||||
email.hashCode ^
|
||||
firstName.hashCode ^
|
||||
lastName.hashCode ^
|
||||
profileImagePath.hashCode ^
|
||||
isAdmin.hashCode ^
|
||||
oauthId.hashCode;
|
||||
|
||||
UserResponseDto toDto() {
|
||||
return UserResponseDto(
|
||||
id: id,
|
||||
email: email,
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
profileImagePath: profileImagePath,
|
||||
createdAt: '',
|
||||
isAdmin: isAdmin,
|
||||
shouldChangePassword: false,
|
||||
oauthId: oauthId,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
json["id"] = id;
|
||||
json["email"] = email;
|
||||
json["firstName"] = firstName;
|
||||
json["lastName"] = lastName;
|
||||
json["profileImagePath"] = profileImagePath;
|
||||
json["isAdmin"] = isAdmin;
|
||||
json["oauthId"] = oauthId;
|
||||
return json;
|
||||
}
|
||||
|
||||
static User? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
return User(
|
||||
id: json["id"],
|
||||
email: json["email"],
|
||||
firstName: json["firstName"],
|
||||
lastName: json["lastName"],
|
||||
profileImagePath: json["profileImagePath"],
|
||||
isAdmin: json["isAdmin"],
|
||||
oauthId: json["oauthId"],
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue