525 lines
17 KiB
Dart
525 lines
17 KiB
Dart
import '../../domain/entities/demande_aide.dart';
|
|
|
|
/// Modèle de données pour les demandes d'aide
|
|
///
|
|
/// Ce modèle fait la conversion entre les DTOs de l'API REST
|
|
/// et les entités du domaine pour les demandes d'aide.
|
|
class DemandeAideModel extends DemandeAide {
|
|
const DemandeAideModel({
|
|
required super.id,
|
|
required super.numeroReference,
|
|
required super.titre,
|
|
required super.description,
|
|
required super.typeAide,
|
|
required super.statut,
|
|
required super.priorite,
|
|
required super.demandeurId,
|
|
required super.nomDemandeur,
|
|
required super.organisationId,
|
|
super.montantDemande,
|
|
super.montantApprouve,
|
|
super.montantVerse,
|
|
required super.dateCreation,
|
|
required super.dateModification,
|
|
super.dateSoumission,
|
|
super.dateEvaluation,
|
|
super.dateApprobation,
|
|
super.dateLimiteTraitement,
|
|
super.evaluateurId,
|
|
super.commentairesEvaluateur,
|
|
super.motifRejet,
|
|
super.informationsRequises,
|
|
super.justificationUrgence,
|
|
super.contactUrgence,
|
|
super.localisation,
|
|
super.beneficiaires,
|
|
super.piecesJustificatives,
|
|
super.historiqueStatuts,
|
|
super.commentaires,
|
|
super.donneesPersonnalisees,
|
|
super.estModifiable,
|
|
super.estUrgente,
|
|
super.delaiDepasse,
|
|
super.estTerminee,
|
|
});
|
|
|
|
/// Crée un modèle à partir d'un JSON (API Response)
|
|
factory DemandeAideModel.fromJson(Map<String, dynamic> json) {
|
|
return DemandeAideModel(
|
|
id: json['id'] as String,
|
|
numeroReference: json['numeroReference'] as String,
|
|
titre: json['titre'] as String,
|
|
description: json['description'] as String,
|
|
typeAide: _parseTypeAide(json['typeAide'] as String),
|
|
statut: _parseStatutAide(json['statut'] as String),
|
|
priorite: _parsePrioriteAide(json['priorite'] as String),
|
|
demandeurId: json['demandeurId'] as String,
|
|
nomDemandeur: json['nomDemandeur'] as String,
|
|
organisationId: json['organisationId'] as String,
|
|
montantDemande: json['montantDemande']?.toDouble(),
|
|
montantApprouve: json['montantApprouve']?.toDouble(),
|
|
montantVerse: json['montantVerse']?.toDouble(),
|
|
dateCreation: DateTime.parse(json['dateCreation'] as String),
|
|
dateModification: DateTime.parse(json['dateModification'] as String),
|
|
dateSoumission: json['dateSoumission'] != null
|
|
? DateTime.parse(json['dateSoumission'] as String)
|
|
: null,
|
|
dateEvaluation: json['dateEvaluation'] != null
|
|
? DateTime.parse(json['dateEvaluation'] as String)
|
|
: null,
|
|
dateApprobation: json['dateApprobation'] != null
|
|
? DateTime.parse(json['dateApprobation'] as String)
|
|
: null,
|
|
dateLimiteTraitement: json['dateLimiteTraitement'] != null
|
|
? DateTime.parse(json['dateLimiteTraitement'] as String)
|
|
: null,
|
|
evaluateurId: json['evaluateurId'] as String?,
|
|
commentairesEvaluateur: json['commentairesEvaluateur'] as String?,
|
|
motifRejet: json['motifRejet'] as String?,
|
|
informationsRequises: json['informationsRequises'] as String?,
|
|
justificationUrgence: json['justificationUrgence'] as String?,
|
|
contactUrgence: json['contactUrgence'] != null
|
|
? ContactUrgenceModel.fromJson(json['contactUrgence'] as Map<String, dynamic>)
|
|
: null,
|
|
localisation: json['localisation'] != null
|
|
? LocalisationModel.fromJson(json['localisation'] as Map<String, dynamic>)
|
|
: null,
|
|
beneficiaires: (json['beneficiaires'] as List<dynamic>?)
|
|
?.map((e) => BeneficiaireAideModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
piecesJustificatives: (json['piecesJustificatives'] as List<dynamic>?)
|
|
?.map((e) => PieceJustificativeModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
historiqueStatuts: (json['historiqueStatuts'] as List<dynamic>?)
|
|
?.map((e) => HistoriqueStatutModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
commentaires: (json['commentaires'] as List<dynamic>?)
|
|
?.map((e) => CommentaireAideModel.fromJson(e as Map<String, dynamic>))
|
|
.toList() ?? [],
|
|
donneesPersonnalisees: Map<String, dynamic>.from(json['donneesPersonnalisees'] ?? {}),
|
|
estModifiable: json['estModifiable'] as bool? ?? false,
|
|
estUrgente: json['estUrgente'] as bool? ?? false,
|
|
delaiDepasse: json['delaiDepasse'] as bool? ?? false,
|
|
estTerminee: json['estTerminee'] as bool? ?? false,
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en JSON (API Request)
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'numeroReference': numeroReference,
|
|
'titre': titre,
|
|
'description': description,
|
|
'typeAide': typeAide.name,
|
|
'statut': statut.name,
|
|
'priorite': priorite.name,
|
|
'demandeurId': demandeurId,
|
|
'nomDemandeur': nomDemandeur,
|
|
'organisationId': organisationId,
|
|
'montantDemande': montantDemande,
|
|
'montantApprouve': montantApprouve,
|
|
'montantVerse': montantVerse,
|
|
'dateCreation': dateCreation.toIso8601String(),
|
|
'dateModification': dateModification.toIso8601String(),
|
|
'dateSoumission': dateSoumission?.toIso8601String(),
|
|
'dateEvaluation': dateEvaluation?.toIso8601String(),
|
|
'dateApprobation': dateApprobation?.toIso8601String(),
|
|
'dateLimiteTraitement': dateLimiteTraitement?.toIso8601String(),
|
|
'evaluateurId': evaluateurId,
|
|
'commentairesEvaluateur': commentairesEvaluateur,
|
|
'motifRejet': motifRejet,
|
|
'informationsRequises': informationsRequises,
|
|
'justificationUrgence': justificationUrgence,
|
|
'contactUrgence': contactUrgence != null
|
|
? (contactUrgence as ContactUrgenceModel).toJson()
|
|
: null,
|
|
'localisation': localisation != null
|
|
? (localisation as LocalisationModel).toJson()
|
|
: null,
|
|
'beneficiaires': beneficiaires
|
|
.map((e) => (e as BeneficiaireAideModel).toJson())
|
|
.toList(),
|
|
'piecesJustificatives': piecesJustificatives
|
|
.map((e) => (e as PieceJustificativeModel).toJson())
|
|
.toList(),
|
|
'historiqueStatuts': historiqueStatuts
|
|
.map((e) => (e as HistoriqueStatutModel).toJson())
|
|
.toList(),
|
|
'commentaires': commentaires
|
|
.map((e) => (e as CommentaireAideModel).toJson())
|
|
.toList(),
|
|
'donneesPersonnalisees': donneesPersonnalisees,
|
|
'estModifiable': estModifiable,
|
|
'estUrgente': estUrgente,
|
|
'delaiDepasse': delaiDepasse,
|
|
'estTerminee': estTerminee,
|
|
};
|
|
}
|
|
|
|
/// Crée un modèle à partir d'une entité du domaine
|
|
factory DemandeAideModel.fromEntity(DemandeAide entity) {
|
|
return DemandeAideModel(
|
|
id: entity.id,
|
|
numeroReference: entity.numeroReference,
|
|
titre: entity.titre,
|
|
description: entity.description,
|
|
typeAide: entity.typeAide,
|
|
statut: entity.statut,
|
|
priorite: entity.priorite,
|
|
demandeurId: entity.demandeurId,
|
|
nomDemandeur: entity.nomDemandeur,
|
|
organisationId: entity.organisationId,
|
|
montantDemande: entity.montantDemande,
|
|
montantApprouve: entity.montantApprouve,
|
|
montantVerse: entity.montantVerse,
|
|
dateCreation: entity.dateCreation,
|
|
dateModification: entity.dateModification,
|
|
dateSoumission: entity.dateSoumission,
|
|
dateEvaluation: entity.dateEvaluation,
|
|
dateApprobation: entity.dateApprobation,
|
|
dateLimiteTraitement: entity.dateLimiteTraitement,
|
|
evaluateurId: entity.evaluateurId,
|
|
commentairesEvaluateur: entity.commentairesEvaluateur,
|
|
motifRejet: entity.motifRejet,
|
|
informationsRequises: entity.informationsRequises,
|
|
justificationUrgence: entity.justificationUrgence,
|
|
contactUrgence: entity.contactUrgence != null
|
|
? ContactUrgenceModel.fromEntity(entity.contactUrgence!)
|
|
: null,
|
|
localisation: entity.localisation != null
|
|
? LocalisationModel.fromEntity(entity.localisation!)
|
|
: null,
|
|
beneficiaires: entity.beneficiaires
|
|
.map((e) => BeneficiaireAideModel.fromEntity(e))
|
|
.toList(),
|
|
piecesJustificatives: entity.piecesJustificatives
|
|
.map((e) => PieceJustificativeModel.fromEntity(e))
|
|
.toList(),
|
|
historiqueStatuts: entity.historiqueStatuts
|
|
.map((e) => HistoriqueStatutModel.fromEntity(e))
|
|
.toList(),
|
|
commentaires: entity.commentaires
|
|
.map((e) => CommentaireAideModel.fromEntity(e))
|
|
.toList(),
|
|
donneesPersonnalisees: Map<String, dynamic>.from(entity.donneesPersonnalisees),
|
|
estModifiable: entity.estModifiable,
|
|
estUrgente: entity.estUrgente,
|
|
delaiDepasse: entity.delaiDepasse,
|
|
estTerminee: entity.estTerminee,
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en entité du domaine
|
|
DemandeAide toEntity() {
|
|
return DemandeAide(
|
|
id: id,
|
|
numeroReference: numeroReference,
|
|
titre: titre,
|
|
description: description,
|
|
typeAide: typeAide,
|
|
statut: statut,
|
|
priorite: priorite,
|
|
demandeurId: demandeurId,
|
|
nomDemandeur: nomDemandeur,
|
|
organisationId: organisationId,
|
|
montantDemande: montantDemande,
|
|
montantApprouve: montantApprouve,
|
|
montantVerse: montantVerse,
|
|
dateCreation: dateCreation,
|
|
dateModification: dateModification,
|
|
dateSoumission: dateSoumission,
|
|
dateEvaluation: dateEvaluation,
|
|
dateApprobation: dateApprobation,
|
|
dateLimiteTraitement: dateLimiteTraitement,
|
|
evaluateurId: evaluateurId,
|
|
commentairesEvaluateur: commentairesEvaluateur,
|
|
motifRejet: motifRejet,
|
|
informationsRequises: informationsRequises,
|
|
justificationUrgence: justificationUrgence,
|
|
contactUrgence: contactUrgence,
|
|
localisation: localisation,
|
|
beneficiaires: beneficiaires,
|
|
piecesJustificatives: piecesJustificatives,
|
|
historiqueStatuts: historiqueStatuts,
|
|
commentaires: commentaires,
|
|
donneesPersonnalisees: donneesPersonnalisees,
|
|
estModifiable: estModifiable,
|
|
estUrgente: estUrgente,
|
|
delaiDepasse: delaiDepasse,
|
|
estTerminee: estTerminee,
|
|
);
|
|
}
|
|
|
|
// Méthodes utilitaires de parsing
|
|
static TypeAide _parseTypeAide(String value) {
|
|
return TypeAide.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => TypeAide.autre,
|
|
);
|
|
}
|
|
|
|
static StatutAide _parseStatutAide(String value) {
|
|
return StatutAide.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => StatutAide.brouillon,
|
|
);
|
|
}
|
|
|
|
static PrioriteAide _parsePrioriteAide(String value) {
|
|
return PrioriteAide.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => PrioriteAide.normale,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Modèles pour les classes auxiliaires
|
|
class ContactUrgenceModel extends ContactUrgence {
|
|
const ContactUrgenceModel({
|
|
required super.nom,
|
|
required super.telephone,
|
|
super.email,
|
|
required super.relation,
|
|
});
|
|
|
|
factory ContactUrgenceModel.fromJson(Map<String, dynamic> json) {
|
|
return ContactUrgenceModel(
|
|
nom: json['nom'] as String,
|
|
telephone: json['telephone'] as String,
|
|
email: json['email'] as String?,
|
|
relation: json['relation'] as String,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'nom': nom,
|
|
'telephone': telephone,
|
|
'email': email,
|
|
'relation': relation,
|
|
};
|
|
}
|
|
|
|
factory ContactUrgenceModel.fromEntity(ContactUrgence entity) {
|
|
return ContactUrgenceModel(
|
|
nom: entity.nom,
|
|
telephone: entity.telephone,
|
|
email: entity.email,
|
|
relation: entity.relation,
|
|
);
|
|
}
|
|
}
|
|
|
|
class LocalisationModel extends Localisation {
|
|
const LocalisationModel({
|
|
required super.adresse,
|
|
required super.ville,
|
|
super.codePostal,
|
|
super.pays,
|
|
super.latitude,
|
|
super.longitude,
|
|
});
|
|
|
|
factory LocalisationModel.fromJson(Map<String, dynamic> json) {
|
|
return LocalisationModel(
|
|
adresse: json['adresse'] as String,
|
|
ville: json['ville'] as String,
|
|
codePostal: json['codePostal'] as String?,
|
|
pays: json['pays'] as String?,
|
|
latitude: json['latitude']?.toDouble(),
|
|
longitude: json['longitude']?.toDouble(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'adresse': adresse,
|
|
'ville': ville,
|
|
'codePostal': codePostal,
|
|
'pays': pays,
|
|
'latitude': latitude,
|
|
'longitude': longitude,
|
|
};
|
|
}
|
|
|
|
factory LocalisationModel.fromEntity(Localisation entity) {
|
|
return LocalisationModel(
|
|
adresse: entity.adresse,
|
|
ville: entity.ville,
|
|
codePostal: entity.codePostal,
|
|
pays: entity.pays,
|
|
latitude: entity.latitude,
|
|
longitude: entity.longitude,
|
|
);
|
|
}
|
|
}
|
|
|
|
class BeneficiaireAideModel extends BeneficiaireAide {
|
|
const BeneficiaireAideModel({
|
|
required super.nom,
|
|
required super.prenom,
|
|
required super.age,
|
|
required super.relation,
|
|
super.telephone,
|
|
});
|
|
|
|
factory BeneficiaireAideModel.fromJson(Map<String, dynamic> json) {
|
|
return BeneficiaireAideModel(
|
|
nom: json['nom'] as String,
|
|
prenom: json['prenom'] as String,
|
|
age: json['age'] as int,
|
|
relation: json['relation'] as String,
|
|
telephone: json['telephone'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'nom': nom,
|
|
'prenom': prenom,
|
|
'age': age,
|
|
'relation': relation,
|
|
'telephone': telephone,
|
|
};
|
|
}
|
|
|
|
factory BeneficiaireAideModel.fromEntity(BeneficiaireAide entity) {
|
|
return BeneficiaireAideModel(
|
|
nom: entity.nom,
|
|
prenom: entity.prenom,
|
|
age: entity.age,
|
|
relation: entity.relation,
|
|
telephone: entity.telephone,
|
|
);
|
|
}
|
|
}
|
|
|
|
class PieceJustificativeModel extends PieceJustificative {
|
|
const PieceJustificativeModel({
|
|
required super.id,
|
|
required super.nom,
|
|
required super.type,
|
|
required super.url,
|
|
required super.taille,
|
|
required super.dateAjout,
|
|
});
|
|
|
|
factory PieceJustificativeModel.fromJson(Map<String, dynamic> json) {
|
|
return PieceJustificativeModel(
|
|
id: json['id'] as String,
|
|
nom: json['nom'] as String,
|
|
type: json['type'] as String,
|
|
url: json['url'] as String,
|
|
taille: json['taille'] as int,
|
|
dateAjout: DateTime.parse(json['dateAjout'] as String),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'nom': nom,
|
|
'type': type,
|
|
'url': url,
|
|
'taille': taille,
|
|
'dateAjout': dateAjout.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory PieceJustificativeModel.fromEntity(PieceJustificative entity) {
|
|
return PieceJustificativeModel(
|
|
id: entity.id,
|
|
nom: entity.nom,
|
|
type: entity.type,
|
|
url: entity.url,
|
|
taille: entity.taille,
|
|
dateAjout: entity.dateAjout,
|
|
);
|
|
}
|
|
}
|
|
|
|
class HistoriqueStatutModel extends HistoriqueStatut {
|
|
const HistoriqueStatutModel({
|
|
required super.ancienStatut,
|
|
required super.nouveauStatut,
|
|
required super.dateChangement,
|
|
super.commentaire,
|
|
super.utilisateurId,
|
|
});
|
|
|
|
factory HistoriqueStatutModel.fromJson(Map<String, dynamic> json) {
|
|
return HistoriqueStatutModel(
|
|
ancienStatut: DemandeAideModel._parseStatutAide(json['ancienStatut'] as String),
|
|
nouveauStatut: DemandeAideModel._parseStatutAide(json['nouveauStatut'] as String),
|
|
dateChangement: DateTime.parse(json['dateChangement'] as String),
|
|
commentaire: json['commentaire'] as String?,
|
|
utilisateurId: json['utilisateurId'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'ancienStatut': ancienStatut.name,
|
|
'nouveauStatut': nouveauStatut.name,
|
|
'dateChangement': dateChangement.toIso8601String(),
|
|
'commentaire': commentaire,
|
|
'utilisateurId': utilisateurId,
|
|
};
|
|
}
|
|
|
|
factory HistoriqueStatutModel.fromEntity(HistoriqueStatut entity) {
|
|
return HistoriqueStatutModel(
|
|
ancienStatut: entity.ancienStatut,
|
|
nouveauStatut: entity.nouveauStatut,
|
|
dateChangement: entity.dateChangement,
|
|
commentaire: entity.commentaire,
|
|
utilisateurId: entity.utilisateurId,
|
|
);
|
|
}
|
|
}
|
|
|
|
class CommentaireAideModel extends CommentaireAide {
|
|
const CommentaireAideModel({
|
|
required super.id,
|
|
required super.contenu,
|
|
required super.auteurId,
|
|
required super.nomAuteur,
|
|
required super.dateCreation,
|
|
super.estPrive,
|
|
});
|
|
|
|
factory CommentaireAideModel.fromJson(Map<String, dynamic> json) {
|
|
return CommentaireAideModel(
|
|
id: json['id'] as String,
|
|
contenu: json['contenu'] as String,
|
|
auteurId: json['auteurId'] as String,
|
|
nomAuteur: json['nomAuteur'] as String,
|
|
dateCreation: DateTime.parse(json['dateCreation'] as String),
|
|
estPrive: json['estPrive'] as bool? ?? false,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'contenu': contenu,
|
|
'auteurId': auteurId,
|
|
'nomAuteur': nomAuteur,
|
|
'dateCreation': dateCreation.toIso8601String(),
|
|
'estPrive': estPrive,
|
|
};
|
|
}
|
|
|
|
factory CommentaireAideModel.fromEntity(CommentaireAide entity) {
|
|
return CommentaireAideModel(
|
|
id: entity.id,
|
|
contenu: entity.contenu,
|
|
auteurId: entity.auteurId,
|
|
nomAuteur: entity.nomAuteur,
|
|
dateCreation: entity.dateCreation,
|
|
estPrive: entity.estPrive,
|
|
);
|
|
}
|
|
}
|