Refactor code structure for improved readability and maintainability

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-04-23 21:14:46 +02:00
parent cd4274575e
commit db1128ceaf
49 changed files with 285993 additions and 175 deletions
@@ -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;
}
}