Files
afterwork/lib/domain/entities/event.dart

69 lines
1.8 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;
final String status;
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,
required this.status,
});
// 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
status: json['status'],
);
}
// 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
'status': status,
};
}
// 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();
}
}