34 lines
725 B
Dart
34 lines
725 B
Dart
import '../core/utils/safe_convert.dart';
|
|
|
|
class User {
|
|
final int id;
|
|
final String name;
|
|
final String email;
|
|
final String role;
|
|
|
|
const User({
|
|
required this.id,
|
|
required this.name,
|
|
required this.email,
|
|
required this.role,
|
|
});
|
|
|
|
bool get isStudent => role == 'student';
|
|
|
|
factory User.fromJson(Map<String, dynamic> json) {
|
|
return User(
|
|
id: SafeConvert.toSafeInt(json['id']),
|
|
name: SafeConvert.toSafeString(json['name']),
|
|
email: SafeConvert.toSafeString(json['email']),
|
|
role: SafeConvert.toSafeString(json['role'], 'user'),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'name': name,
|
|
'email': email,
|
|
'role': role,
|
|
};
|
|
}
|