refactoring
This commit is contained in:
34
lib/data/models/creator_model.dart
Normal file
34
lib/data/models/creator_model.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:afterwork/data/models/user_model.dart';
|
||||
|
||||
/// Modèle représentant le créateur d'un événement.
|
||||
class CreatorModel extends UserModel {
|
||||
CreatorModel({
|
||||
required String id,
|
||||
required String nom,
|
||||
required String prenoms,
|
||||
|
||||
}) : super(
|
||||
userId: id,
|
||||
nom: nom,
|
||||
prenoms: prenoms,
|
||||
email: '', // Valeur par défaut vide
|
||||
motDePasse: '', // Valeur par défaut vide
|
||||
);
|
||||
|
||||
factory CreatorModel.fromJson(Map<String, dynamic> json) {
|
||||
return CreatorModel(
|
||||
id: json['id'],
|
||||
nom: json['nom'],
|
||||
prenoms: json['prenoms'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': userId,
|
||||
'nom': nom,
|
||||
'prenoms': prenoms,
|
||||
};
|
||||
}
|
||||
}
|
||||
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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
34
lib/data/models/participant_model.dart
Normal file
34
lib/data/models/participant_model.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:afterwork/data/models/user_model.dart';
|
||||
|
||||
/// Modèle représentant un participant à un événement.
|
||||
class ParticipantModel extends UserModel {
|
||||
ParticipantModel({
|
||||
required String id,
|
||||
required String nom,
|
||||
required String prenoms,
|
||||
}) : super(
|
||||
userId: id,
|
||||
nom: nom,
|
||||
prenoms: prenoms,
|
||||
email: '', // Valeur par défaut vide
|
||||
motDePasse: '', // Valeur par défaut vide
|
||||
);
|
||||
|
||||
factory ParticipantModel.fromJson(Map<String, dynamic> json) {
|
||||
return ParticipantModel(
|
||||
id: json['id'],
|
||||
nom: json['nom'],
|
||||
prenoms: json['prenoms'],
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': userId,
|
||||
'nom': nom,
|
||||
'prenoms': prenoms,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import 'package:afterwork/domain/entities/user.dart';
|
||||
|
||||
class UserModel extends User {
|
||||
class UserModel extends User {
|
||||
const UserModel({
|
||||
required String id,
|
||||
required String userId, // Utilisez `id` pour correspondre à l'entité User
|
||||
required String nom,
|
||||
required String prenoms,
|
||||
required String email,
|
||||
required String motDePasse,
|
||||
}) : super(
|
||||
id: id,
|
||||
userId: userId,
|
||||
nom: nom,
|
||||
prenoms: prenoms,
|
||||
email: email,
|
||||
@@ -17,7 +17,7 @@ class UserModel extends User {
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
id: json['id'] ?? '',
|
||||
userId: json['id'] ?? '',
|
||||
nom: json['nom'] ?? '',
|
||||
prenoms: json['prenoms'] ?? '',
|
||||
email: json['email'] ?? '',
|
||||
@@ -27,7 +27,7 @@ class UserModel extends User {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'id': userId, // Utilisez `id` pour correspondre à l'entité User
|
||||
'nom': nom,
|
||||
'prenoms': prenoms,
|
||||
'email': email,
|
||||
|
||||
Reference in New Issue
Block a user