refactoring and checkpoint

This commit is contained in:
DahoudG
2024-09-24 00:32:20 +00:00
parent dc73ba7dcc
commit 6b12cfeb41
159 changed files with 8119 additions and 1535 deletions

View File

@@ -1,8 +1,10 @@
import 'package:afterwork/domain/entities/user.dart';
import '../../domain/entities/user.dart';
class UserModel extends User {
const UserModel({
required String userId, // Utilisez `id` pour correspondre à l'entité User
/// Modèle représentant l'utilisateur dans l'application AfterWork.
/// Ce modèle est utilisé pour la conversion JSON et l'interaction avec l'API.
class UserModel extends User {
UserModel({
required String userId,
required String nom,
required String prenoms,
required String email,
@@ -15,23 +17,25 @@ class UserModel extends User {
motDePasse: motDePasse,
);
/// Factory pour créer un `UserModel` à partir d'un JSON reçu depuis l'API.
factory UserModel.fromJson(Map<String, dynamic> json) {
return UserModel(
userId: json['id'] ?? '',
nom: json['nom'] ?? '',
prenoms: json['prenoms'] ?? '',
email: json['email'] ?? '',
nom: json['nom'] ?? 'Inconnu',
prenoms: json['prenoms'] ?? 'Inconnu',
email: json['email'] ?? 'inconnu@example.com',
motDePasse: json['motDePasse'] ?? '',
);
}
/// Convertit le `UserModel` en JSON pour l'envoi vers l'API.
Map<String, dynamic> toJson() {
return {
'id': userId, // Utilisez `id` pour correspondre à l'entité User
'id': userId,
'nom': nom,
'prenoms': prenoms,
'email': email,
'motDePasse': motDePasse,
'motDePasse': motDePasse, // Mot de passe en clair (comme demandé temporairement)
};
}
}