65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
class EventModel {
|
|
final String eventId;
|
|
final String title;
|
|
final String description;
|
|
final String eventDate;
|
|
final String location;
|
|
final String category;
|
|
final String? link;
|
|
final String? imageUrl;
|
|
final String creatorId;
|
|
|
|
EventModel({
|
|
required this.eventId,
|
|
required this.title,
|
|
required this.description,
|
|
required this.eventDate,
|
|
required this.location,
|
|
required this.category,
|
|
this.link,
|
|
this.imageUrl,
|
|
required this.creatorId,
|
|
});
|
|
|
|
// Méthode pour créer un EventModel à partir d'un JSON
|
|
factory EventModel.fromJson(Map<String, dynamic> json) {
|
|
return EventModel(
|
|
eventId: json['id'],
|
|
title: json['title'],
|
|
description: json['description'],
|
|
eventDate: json['event_date'],
|
|
location: json['location'],
|
|
category: json['category'],
|
|
link: json['link'],
|
|
imageUrl: json['imageUrl'],
|
|
creatorId: json['creator']['id'], // Assurez-vous que le JSON a ce format
|
|
);
|
|
}
|
|
|
|
// Méthode pour convertir un EventModel en JSON
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': eventId,
|
|
'title': title,
|
|
'description': description,
|
|
'event_date': eventDate,
|
|
'location': location,
|
|
'category': category,
|
|
'link': link,
|
|
'imageUrl': imageUrl,
|
|
'creator': {'id': creatorId}, // Structure du JSON pour l'API
|
|
};
|
|
}
|
|
|
|
// Convertir une liste d'EventModel à partir d'une liste JSON
|
|
static List<EventModel> fromJsonList(List<dynamic> jsonList) {
|
|
return jsonList.map((json) => EventModel.fromJson(json)).toList();
|
|
}
|
|
|
|
// Convertir une liste d'EventModel en JSON
|
|
static List<Map<String, dynamic>> toJsonList(List<EventModel> events) {
|
|
return events.map((event) => event.toJson()).toList();
|
|
}
|
|
}
|
|
|