refactoring and checkpoint
This commit is contained in:
@@ -1,78 +1,71 @@
|
||||
import 'package:afterwork/data/models/user_model.dart';
|
||||
|
||||
/// Modèle de données représentant un événement.
|
||||
/// Cette classe encapsule toutes les propriétés d'un événement, y compris
|
||||
/// le titre, la description, la date, la localisation, la catégorie, les liens,
|
||||
/// l'image, le créateur, les participants et le statut de l'événement.
|
||||
class EventModel {
|
||||
final String id; // Identifiant unique de l'événement
|
||||
final String title; // Titre de l'événement
|
||||
final String description; // Description de l'événement
|
||||
final String date; // Date de l'événement
|
||||
final String location; // Localisation de l'événement
|
||||
final String category; // Catégorie de l'événement
|
||||
final String link; // Lien associé à l'événement
|
||||
final String? imageUrl; // URL de l'image de l'événement (optionnel)
|
||||
final UserModel creator; // Créateur de l'événement
|
||||
final List<UserModel> participants; // Liste des participants à l'événement
|
||||
final String status; // Statut de l'événement (e.g., "OPEN", "CLOSED")
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final String startDate; // Utiliser startDate au lieu de date, si c'est ce que l'API retourne
|
||||
final String location;
|
||||
final String category;
|
||||
final String link;
|
||||
final String? imageUrl; // Nullable
|
||||
final String creatorEmail; // Remplacer UserModel si le créateur est un email
|
||||
final List<dynamic> participants; // Si participants est une liste simple
|
||||
final String status;
|
||||
final int reactionsCount;
|
||||
final int commentsCount;
|
||||
final int sharesCount;
|
||||
|
||||
/// Constructeur pour initialiser toutes les propriétés de l'événement.
|
||||
EventModel({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.date,
|
||||
required this.startDate,
|
||||
required this.location,
|
||||
required this.category,
|
||||
required this.link,
|
||||
this.imageUrl,
|
||||
required this.creator,
|
||||
required this.creatorEmail,
|
||||
required this.participants,
|
||||
required this.status,
|
||||
required this.reactionsCount,
|
||||
required this.commentsCount,
|
||||
required this.sharesCount,
|
||||
});
|
||||
|
||||
/// Convertit un objet JSON en `EventModel`.
|
||||
factory EventModel.fromJson(Map<String, dynamic> json) {
|
||||
// Log de la conversion depuis JSON
|
||||
print('Conversion de l\'objet JSON en EventModel: ${json['id']}');
|
||||
|
||||
return EventModel(
|
||||
id: json['id'],
|
||||
title: json['title'],
|
||||
description: json['description'],
|
||||
date: json['date'],
|
||||
startDate: json['startDate'], // Vérifier si c'est bien startDate
|
||||
location: json['location'],
|
||||
category: json['category'],
|
||||
link: json['link'] ?? '', // Assure qu'il ne soit pas null
|
||||
imageUrl: json['imageUrl'] ?? '', // Assure qu'il ne soit pas null
|
||||
status: json['status'],
|
||||
creator: UserModel.fromJson(json['creator']),
|
||||
participants: json['participants'] != null
|
||||
? (json['participants'] as List)
|
||||
.map((user) => UserModel.fromJson(user))
|
||||
.toList()
|
||||
: [], // Si participants est null, retourne une liste vide
|
||||
link: json['link'] ?? '',
|
||||
imageUrl: json['imageUrl'], // Peut être null
|
||||
creatorEmail: json['creatorEmail'], // Email du créateur
|
||||
participants: json['participants'] ?? [], // Gérer les participants
|
||||
status: json['status'] ?? 'open', // Par défaut à "open" si non fourni
|
||||
reactionsCount: json['reactionsCount'] ?? 0,
|
||||
commentsCount: json['commentsCount'] ?? 0,
|
||||
sharesCount: json['sharesCount'] ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convertit un `EventModel` en objet JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
// Log de la conversion en JSON
|
||||
print('Conversion de l\'EventModel en objet JSON: $id');
|
||||
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'date': date,
|
||||
'startDate': startDate,
|
||||
'location': location,
|
||||
'category': category,
|
||||
'link': link,
|
||||
'imageUrl': imageUrl,
|
||||
'creator': creator.toJson(),
|
||||
'participants': participants.map((user) => user.toJson()).toList(),
|
||||
'creatorEmail': creatorEmail,
|
||||
'participants': participants,
|
||||
'status': status,
|
||||
'reactionsCount': reactionsCount,
|
||||
'commentsCount': commentsCount,
|
||||
'sharesCount': sharesCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user