66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
import 'package:afterwork/data/models/user_model.dart';
|
|
|
|
/// Modèle de données représentant un événement.
|
|
class EventModel {
|
|
final String id;
|
|
final String title;
|
|
final String description;
|
|
final String date;
|
|
final String location;
|
|
final String category;
|
|
final String link;
|
|
final String? imageUrl;
|
|
final UserModel creator;
|
|
final List<UserModel> participants;
|
|
|
|
/// 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.location,
|
|
required this.category,
|
|
required this.link,
|
|
this.imageUrl,
|
|
required this.creator,
|
|
required this.participants,
|
|
});
|
|
|
|
/// Convertit un objet JSON en `EventModel`.
|
|
factory EventModel.fromJson(Map<String, dynamic> json) {
|
|
return EventModel(
|
|
id: json['id'],
|
|
title: json['title'],
|
|
description: json['description'],
|
|
date: json['date'],
|
|
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
|
|
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
|
|
);
|
|
}
|
|
|
|
/// Convertit un `EventModel` en objet JSON.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'date': date,
|
|
'location': location,
|
|
'category': category,
|
|
'link': link,
|
|
'imageUrl': imageUrl,
|
|
'creator': creator.toJson(),
|
|
'participants': participants.map((user) => user.toJson()).toList(),
|
|
};
|
|
}
|
|
}
|