336 lines
12 KiB
Dart
336 lines
12 KiB
Dart
import '../../domain/entities/proposition_aide.dart';
|
|
import '../../domain/entities/demande_aide.dart';
|
|
|
|
/// Modèle de données pour les propositions d'aide
|
|
///
|
|
/// Ce modèle fait la conversion entre les DTOs de l'API REST
|
|
/// et les entités du domaine pour les propositions d'aide.
|
|
class PropositionAideModel extends PropositionAide {
|
|
const PropositionAideModel({
|
|
required super.id,
|
|
required super.titre,
|
|
required super.description,
|
|
required super.typeAide,
|
|
required super.statut,
|
|
required super.proposantId,
|
|
required super.nomProposant,
|
|
required super.organisationId,
|
|
required super.nombreMaxBeneficiaires,
|
|
super.montantMaximum,
|
|
super.montantMinimum,
|
|
required super.delaiReponseHeures,
|
|
required super.dateCreation,
|
|
required super.dateModification,
|
|
super.dateExpiration,
|
|
super.dateActivation,
|
|
super.dateDesactivation,
|
|
required super.contactProposant,
|
|
super.zonesGeographiques,
|
|
super.creneauxDisponibilite,
|
|
super.criteresSelection,
|
|
super.conditionsSpeciales,
|
|
super.nombreBeneficiairesAides,
|
|
super.nombreVues,
|
|
super.nombreCandidatures,
|
|
super.noteMoyenne,
|
|
super.nombreEvaluations,
|
|
super.donneesPersonnalisees,
|
|
super.estVerifiee,
|
|
super.estPromue,
|
|
});
|
|
|
|
/// Crée un modèle à partir d'un JSON (API Response)
|
|
factory PropositionAideModel.fromJson(Map<String, dynamic> json) {
|
|
return PropositionAideModel(
|
|
id: json['id'] as String,
|
|
titre: json['titre'] as String,
|
|
description: json['description'] as String,
|
|
typeAide: _parseTypeAide(json['typeAide'] as String),
|
|
statut: _parseStatutProposition(json['statut'] as String),
|
|
proposantId: json['proposantId'] as String,
|
|
nomProposant: json['nomProposant'] as String,
|
|
organisationId: json['organisationId'] as String,
|
|
nombreMaxBeneficiaires: json['nombreMaxBeneficiaires'] as int,
|
|
montantMaximum: json['montantMaximum']?.toDouble(),
|
|
montantMinimum: json['montantMinimum']?.toDouble(),
|
|
delaiReponseHeures: json['delaiReponseHeures'] as int,
|
|
dateCreation: DateTime.parse(json['dateCreation'] as String),
|
|
dateModification: DateTime.parse(json['dateModification'] as String),
|
|
dateExpiration: json['dateExpiration'] != null
|
|
? DateTime.parse(json['dateExpiration'] as String)
|
|
: null,
|
|
dateActivation: json['dateActivation'] != null
|
|
? DateTime.parse(json['dateActivation'] as String)
|
|
: null,
|
|
dateDesactivation: json['dateDesactivation'] != null
|
|
? DateTime.parse(json['dateDesactivation'] as String)
|
|
: null,
|
|
contactProposant: ContactProposantModel.fromJson(
|
|
json['contactProposant'] as Map<String, dynamic>
|
|
),
|
|
zonesGeographiques: (json['zonesGeographiques'] as List<dynamic>?)
|
|
?.cast<String>() ?? [],
|
|
creneauxDisponibilite: (json['creneauxDisponibilite'] as List<dynamic>?)
|
|
?.map((e) => CreneauDisponibiliteModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
criteresSelection: (json['criteresSelection'] as List<dynamic>?)
|
|
?.map((e) => CritereSelectionModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
conditionsSpeciales: (json['conditionsSpeciales'] as List<dynamic>?)
|
|
?.cast<String>() ?? [],
|
|
nombreBeneficiairesAides: json['nombreBeneficiairesAides'] as int? ?? 0,
|
|
nombreVues: json['nombreVues'] as int? ?? 0,
|
|
nombreCandidatures: json['nombreCandidatures'] as int? ?? 0,
|
|
noteMoyenne: json['noteMoyenne']?.toDouble(),
|
|
nombreEvaluations: json['nombreEvaluations'] as int? ?? 0,
|
|
donneesPersonnalisees: Map<String, dynamic>.from(json['donneesPersonnalisees'] ?? {}),
|
|
estVerifiee: json['estVerifiee'] as bool? ?? false,
|
|
estPromue: json['estPromue'] as bool? ?? false,
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en JSON (API Request)
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'titre': titre,
|
|
'description': description,
|
|
'typeAide': typeAide.name,
|
|
'statut': statut.name,
|
|
'proposantId': proposantId,
|
|
'nomProposant': nomProposant,
|
|
'organisationId': organisationId,
|
|
'nombreMaxBeneficiaires': nombreMaxBeneficiaires,
|
|
'montantMaximum': montantMaximum,
|
|
'montantMinimum': montantMinimum,
|
|
'delaiReponseHeures': delaiReponseHeures,
|
|
'dateCreation': dateCreation.toIso8601String(),
|
|
'dateModification': dateModification.toIso8601String(),
|
|
'dateExpiration': dateExpiration?.toIso8601String(),
|
|
'dateActivation': dateActivation?.toIso8601String(),
|
|
'dateDesactivation': dateDesactivation?.toIso8601String(),
|
|
'contactProposant': (contactProposant as ContactProposantModel).toJson(),
|
|
'zonesGeographiques': zonesGeographiques,
|
|
'creneauxDisponibilite': creneauxDisponibilite
|
|
.map((e) => (e as CreneauDisponibiliteModel).toJson())
|
|
.toList(),
|
|
'criteresSelection': criteresSelection
|
|
.map((e) => (e as CritereSelectionModel).toJson())
|
|
.toList(),
|
|
'conditionsSpeciales': conditionsSpeciales,
|
|
'nombreBeneficiairesAides': nombreBeneficiairesAides,
|
|
'nombreVues': nombreVues,
|
|
'nombreCandidatures': nombreCandidatures,
|
|
'noteMoyenne': noteMoyenne,
|
|
'nombreEvaluations': nombreEvaluations,
|
|
'donneesPersonnalisees': donneesPersonnalisees,
|
|
'estVerifiee': estVerifiee,
|
|
'estPromue': estPromue,
|
|
};
|
|
}
|
|
|
|
/// Crée un modèle à partir d'une entité du domaine
|
|
factory PropositionAideModel.fromEntity(PropositionAide entity) {
|
|
return PropositionAideModel(
|
|
id: entity.id,
|
|
titre: entity.titre,
|
|
description: entity.description,
|
|
typeAide: entity.typeAide,
|
|
statut: entity.statut,
|
|
proposantId: entity.proposantId,
|
|
nomProposant: entity.nomProposant,
|
|
organisationId: entity.organisationId,
|
|
nombreMaxBeneficiaires: entity.nombreMaxBeneficiaires,
|
|
montantMaximum: entity.montantMaximum,
|
|
montantMinimum: entity.montantMinimum,
|
|
delaiReponseHeures: entity.delaiReponseHeures,
|
|
dateCreation: entity.dateCreation,
|
|
dateModification: entity.dateModification,
|
|
dateExpiration: entity.dateExpiration,
|
|
dateActivation: entity.dateActivation,
|
|
dateDesactivation: entity.dateDesactivation,
|
|
contactProposant: ContactProposantModel.fromEntity(entity.contactProposant),
|
|
zonesGeographiques: List<String>.from(entity.zonesGeographiques),
|
|
creneauxDisponibilite: entity.creneauxDisponibilite
|
|
.map((e) => CreneauDisponibiliteModel.fromEntity(e))
|
|
.toList(),
|
|
criteresSelection: entity.criteresSelection
|
|
.map((e) => CritereSelectionModel.fromEntity(e))
|
|
.toList(),
|
|
conditionsSpeciales: List<String>.from(entity.conditionsSpeciales),
|
|
nombreBeneficiairesAides: entity.nombreBeneficiairesAides,
|
|
nombreVues: entity.nombreVues,
|
|
nombreCandidatures: entity.nombreCandidatures,
|
|
noteMoyenne: entity.noteMoyenne,
|
|
nombreEvaluations: entity.nombreEvaluations,
|
|
donneesPersonnalisees: Map<String, dynamic>.from(entity.donneesPersonnalisees),
|
|
estVerifiee: entity.estVerifiee,
|
|
estPromue: entity.estPromue,
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en entité du domaine
|
|
PropositionAide toEntity() {
|
|
return PropositionAide(
|
|
id: id,
|
|
titre: titre,
|
|
description: description,
|
|
typeAide: typeAide,
|
|
statut: statut,
|
|
proposantId: proposantId,
|
|
nomProposant: nomProposant,
|
|
organisationId: organisationId,
|
|
nombreMaxBeneficiaires: nombreMaxBeneficiaires,
|
|
montantMaximum: montantMaximum,
|
|
montantMinimum: montantMinimum,
|
|
delaiReponseHeures: delaiReponseHeures,
|
|
dateCreation: dateCreation,
|
|
dateModification: dateModification,
|
|
dateExpiration: dateExpiration,
|
|
dateActivation: dateActivation,
|
|
dateDesactivation: dateDesactivation,
|
|
contactProposant: contactProposant,
|
|
zonesGeographiques: zonesGeographiques,
|
|
creneauxDisponibilite: creneauxDisponibilite,
|
|
criteresSelection: criteresSelection,
|
|
conditionsSpeciales: conditionsSpeciales,
|
|
nombreBeneficiairesAides: nombreBeneficiairesAides,
|
|
nombreVues: nombreVues,
|
|
nombreCandidatures: nombreCandidatures,
|
|
noteMoyenne: noteMoyenne,
|
|
nombreEvaluations: nombreEvaluations,
|
|
donneesPersonnalisees: donneesPersonnalisees,
|
|
estVerifiee: estVerifiee,
|
|
estPromue: estPromue,
|
|
);
|
|
}
|
|
|
|
// Méthodes utilitaires de parsing
|
|
static TypeAide _parseTypeAide(String value) {
|
|
return TypeAide.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => TypeAide.autre,
|
|
);
|
|
}
|
|
|
|
static StatutProposition _parseStatutProposition(String value) {
|
|
return StatutProposition.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => StatutProposition.brouillon,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Modèles pour les classes auxiliaires
|
|
class ContactProposantModel extends ContactProposant {
|
|
const ContactProposantModel({
|
|
required super.nom,
|
|
required super.telephone,
|
|
super.email,
|
|
super.adresse,
|
|
super.heuresDisponibilite,
|
|
});
|
|
|
|
factory ContactProposantModel.fromJson(Map<String, dynamic> json) {
|
|
return ContactProposantModel(
|
|
nom: json['nom'] as String,
|
|
telephone: json['telephone'] as String,
|
|
email: json['email'] as String?,
|
|
adresse: json['adresse'] as String?,
|
|
heuresDisponibilite: json['heuresDisponibilite'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'nom': nom,
|
|
'telephone': telephone,
|
|
'email': email,
|
|
'adresse': adresse,
|
|
'heuresDisponibilite': heuresDisponibilite,
|
|
};
|
|
}
|
|
|
|
factory ContactProposantModel.fromEntity(ContactProposant entity) {
|
|
return ContactProposantModel(
|
|
nom: entity.nom,
|
|
telephone: entity.telephone,
|
|
email: entity.email,
|
|
adresse: entity.adresse,
|
|
heuresDisponibilite: entity.heuresDisponibilite,
|
|
);
|
|
}
|
|
}
|
|
|
|
class CreneauDisponibiliteModel extends CreneauDisponibilite {
|
|
const CreneauDisponibiliteModel({
|
|
required super.jourSemaine,
|
|
required super.heureDebut,
|
|
required super.heureFin,
|
|
super.commentaire,
|
|
});
|
|
|
|
factory CreneauDisponibiliteModel.fromJson(Map<String, dynamic> json) {
|
|
return CreneauDisponibiliteModel(
|
|
jourSemaine: json['jourSemaine'] as String,
|
|
heureDebut: json['heureDebut'] as String,
|
|
heureFin: json['heureFin'] as String,
|
|
commentaire: json['commentaire'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'jourSemaine': jourSemaine,
|
|
'heureDebut': heureDebut,
|
|
'heureFin': heureFin,
|
|
'commentaire': commentaire,
|
|
};
|
|
}
|
|
|
|
factory CreneauDisponibiliteModel.fromEntity(CreneauDisponibilite entity) {
|
|
return CreneauDisponibiliteModel(
|
|
jourSemaine: entity.jourSemaine,
|
|
heureDebut: entity.heureDebut,
|
|
heureFin: entity.heureFin,
|
|
commentaire: entity.commentaire,
|
|
);
|
|
}
|
|
}
|
|
|
|
class CritereSelectionModel extends CritereSelection {
|
|
const CritereSelectionModel({
|
|
required super.nom,
|
|
required super.description,
|
|
required super.obligatoire,
|
|
super.valeurAttendue,
|
|
});
|
|
|
|
factory CritereSelectionModel.fromJson(Map<String, dynamic> json) {
|
|
return CritereSelectionModel(
|
|
nom: json['nom'] as String,
|
|
description: json['description'] as String,
|
|
obligatoire: json['obligatoire'] as bool,
|
|
valeurAttendue: json['valeurAttendue'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'nom': nom,
|
|
'description': description,
|
|
'obligatoire': obligatoire,
|
|
'valeurAttendue': valeurAttendue,
|
|
};
|
|
}
|
|
|
|
factory CritereSelectionModel.fromEntity(CritereSelection entity) {
|
|
return CritereSelectionModel(
|
|
nom: entity.nom,
|
|
description: entity.description,
|
|
obligatoire: entity.obligatoire,
|
|
valeurAttendue: entity.valeurAttendue,
|
|
);
|
|
}
|
|
}
|