Refactor code structure for improved readability and maintainability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/// Model for a user as returned by the admin endpoint.
|
||||
class UserAdmin {
|
||||
final int id;
|
||||
final String username;
|
||||
final String email;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String role;
|
||||
final bool isPremium;
|
||||
final DateTime? createdAt;
|
||||
|
||||
const UserAdmin({
|
||||
required this.id,
|
||||
required this.username,
|
||||
required this.email,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
required this.role,
|
||||
required this.isPremium,
|
||||
this.createdAt,
|
||||
});
|
||||
|
||||
factory UserAdmin.fromJson(Map<String, dynamic> json) => UserAdmin(
|
||||
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',
|
||||
isPremium: json['isPremium'] as bool? ?? false,
|
||||
createdAt: json['createdAt'] != null ? DateTime.tryParse(json['createdAt'] as String) : null,
|
||||
);
|
||||
|
||||
bool get isAdmin => role == 'admin';
|
||||
|
||||
String get displayName {
|
||||
final parts = [firstName, lastName].where((s) => s != null && s.isNotEmpty).toList();
|
||||
return parts.isNotEmpty ? parts.join(' ') : username;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user