refactoring

This commit is contained in:
DahoudG
2024-09-01 04:08:50 +00:00
parent 7e1cb85160
commit a1fce6bf27
31 changed files with 1651 additions and 441 deletions

View File

@@ -0,0 +1,64 @@
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();
}
}

View File

@@ -1,14 +1,14 @@
import 'package:equatable/equatable.dart';
class User extends Equatable {
final String id;
final String userId;
final String nom;
final String prenoms;
final String email;
final String motDePasse;
const User({
required this.id,
required this.userId,
required this.nom,
required this.prenoms,
required this.email,
@@ -16,5 +16,5 @@ class User extends Equatable {
});
@override
List<Object?> get props => [id, nom, prenoms, email, motDePasse];
List<Object?> get props => [userId, nom, prenoms, email, motDePasse];
}