41ae7d4d06
- Implemented functionality to set recipe visibility (public/private) with appropriate checks for user permissions. - Added ability to share recipes with other users, including validation for existing users and permissions. - Introduced new DTOs for setting visibility and sharing recipes. - Updated RecipesController and RecipesService to handle new endpoints for visibility and sharing. - Enhanced inventory preview to consider user permissions and shared recipes. - Updated front-end to support new sharing and visibility features, including UI changes for recipe detail and admin user management.
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
/// 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 bool canShareRecipes;
|
|
final DateTime? createdAt;
|
|
|
|
const UserAdmin({
|
|
required this.id,
|
|
required this.username,
|
|
required this.email,
|
|
this.firstName,
|
|
this.lastName,
|
|
required this.role,
|
|
required this.isPremium,
|
|
required this.canShareRecipes,
|
|
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,
|
|
canShareRecipes: json['canShareRecipes'] as bool? ?? true,
|
|
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;
|
|
}
|
|
}
|