72 lines
2.1 KiB
Dart
72 lines
2.1 KiB
Dart
class EventModel {
|
|
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;
|
|
final List<dynamic> participants; // Si participants est une liste simple
|
|
final String status;
|
|
final int reactionsCount;
|
|
final int commentsCount;
|
|
final int sharesCount;
|
|
|
|
EventModel({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.startDate,
|
|
required this.location,
|
|
required this.category,
|
|
required this.link,
|
|
this.imageUrl,
|
|
required this.creatorEmail,
|
|
required this.participants,
|
|
required this.status,
|
|
required this.reactionsCount,
|
|
required this.commentsCount,
|
|
required this.sharesCount,
|
|
});
|
|
|
|
factory EventModel.fromJson(Map<String, dynamic> json) {
|
|
return EventModel(
|
|
id: json['id'],
|
|
title: json['title'],
|
|
description: json['description'],
|
|
startDate: json['startDate'], // Vérifier si c'est bien startDate
|
|
location: json['location'],
|
|
category: json['category'],
|
|
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'] ?? 'ouvert', // Par défaut à "ouvert" si non fourni
|
|
reactionsCount: json['reactionsCount'] ?? 0,
|
|
commentsCount: json['commentsCount'] ?? 0,
|
|
sharesCount: json['sharesCount'] ?? 0,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'startDate': startDate,
|
|
'location': location,
|
|
'category': category,
|
|
'link': link,
|
|
'imageUrl': imageUrl,
|
|
'creatorEmail': creatorEmail,
|
|
'participants': participants,
|
|
'status': status,
|
|
'reactionsCount': reactionsCount,
|
|
'commentsCount': commentsCount,
|
|
'sharesCount': sharesCount,
|
|
};
|
|
}
|
|
}
|