refactoring
This commit is contained in:
65
lib/data/models/event_model.dart
Normal file
65
lib/data/models/event_model.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
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,
|
||||
required 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'],
|
||||
imageUrl: json['imageUrl'],
|
||||
creator: UserModel.fromJson(json['creator']),
|
||||
participants: json['participants'] != null
|
||||
? (json['participants'] as List)
|
||||
.map((user) => UserModel.fromJson(user))
|
||||
.toList()
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// 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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user