2023-05-29 14:16:23 -04:00
|
|
|
import 'package:contacts_plus_plus/models/users/user_profile.dart';
|
2023-04-30 09:43:59 -04:00
|
|
|
|
|
|
|
class User {
|
|
|
|
final String id;
|
|
|
|
final String username;
|
|
|
|
final DateTime registrationDate;
|
|
|
|
final UserProfile? userProfile;
|
|
|
|
|
|
|
|
const User({required this.id, required this.username, required this.registrationDate, this.userProfile});
|
|
|
|
|
|
|
|
factory User.fromMap(Map map) {
|
|
|
|
UserProfile? profile;
|
|
|
|
try {
|
|
|
|
profile = UserProfile.fromMap(map["profile"]);
|
|
|
|
} catch (e) {
|
|
|
|
profile = null;
|
|
|
|
}
|
|
|
|
return User(
|
|
|
|
id: map["id"],
|
|
|
|
username: map["username"],
|
|
|
|
registrationDate: DateTime.parse(map["registrationDate"]),
|
|
|
|
userProfile: profile,
|
|
|
|
);
|
|
|
|
}
|
2023-04-30 17:14:29 -04:00
|
|
|
|
|
|
|
Map toMap() {
|
|
|
|
return {
|
|
|
|
"id": id,
|
|
|
|
"username": username,
|
|
|
|
"registrationDate": registrationDate.toIso8601String(),
|
|
|
|
"profile": userProfile?.toMap(),
|
|
|
|
};
|
|
|
|
}
|
2023-04-30 09:43:59 -04:00
|
|
|
}
|