db1128ceaf
Co-authored-by: Copilot <copilot@github.com>
43 lines
1.1 KiB
Dart
43 lines
1.1 KiB
Dart
class UserProfile {
|
|
final int id;
|
|
final String username;
|
|
final String email;
|
|
final String? firstName;
|
|
final String? lastName;
|
|
final String role;
|
|
|
|
const UserProfile({
|
|
required this.id,
|
|
required this.username,
|
|
required this.email,
|
|
this.firstName,
|
|
this.lastName,
|
|
required this.role,
|
|
});
|
|
|
|
factory UserProfile.fromJson(Map<String, dynamic> json) => UserProfile(
|
|
id: json['id'] as int,
|
|
username: json['username'] as String,
|
|
email: json['email'] as String? ?? '',
|
|
firstName: json['firstName'] as String?,
|
|
lastName: json['lastName'] as String?,
|
|
role: json['role'] as String? ?? 'user',
|
|
);
|
|
|
|
bool get isAdmin => role == 'admin';
|
|
|
|
UserProfile copyWith({
|
|
String? email,
|
|
String? firstName,
|
|
String? lastName,
|
|
}) =>
|
|
UserProfile(
|
|
id: id,
|
|
username: username,
|
|
email: email ?? this.email,
|
|
firstName: firstName ?? this.firstName,
|
|
lastName: lastName ?? this.lastName,
|
|
role: role,
|
|
);
|
|
}
|