389 lines
14 KiB
Dart
389 lines
14 KiB
Dart
import '../../domain/entities/evaluation_aide.dart';
|
|
|
|
/// Modèle de données pour les évaluations d'aide
|
|
///
|
|
/// Ce modèle fait la conversion entre les DTOs de l'API REST
|
|
/// et les entités du domaine pour les évaluations d'aide.
|
|
class EvaluationAideModel extends EvaluationAide {
|
|
const EvaluationAideModel({
|
|
required super.id,
|
|
required super.demandeId,
|
|
super.propositionId,
|
|
required super.evaluateurId,
|
|
required super.nomEvaluateur,
|
|
required super.typeEvaluateur,
|
|
required super.statut,
|
|
required super.noteGlobale,
|
|
super.noteDelaiReponse,
|
|
super.noteCommunication,
|
|
super.noteProfessionnalisme,
|
|
super.noteRespectEngagements,
|
|
required super.commentairePrincipal,
|
|
super.pointsPositifs,
|
|
super.pointsAmelioration,
|
|
super.recommandations,
|
|
super.recommande,
|
|
required super.dateCreation,
|
|
required super.dateModification,
|
|
super.dateValidation,
|
|
super.validateurId,
|
|
super.motifSignalement,
|
|
super.nombreSignalements,
|
|
super.estModeree,
|
|
super.estPublique,
|
|
super.donneesPersonnalisees,
|
|
});
|
|
|
|
/// Crée un modèle à partir d'un JSON (API Response)
|
|
factory EvaluationAideModel.fromJson(Map<String, dynamic> json) {
|
|
return EvaluationAideModel(
|
|
id: json['id'] as String,
|
|
demandeId: json['demandeId'] as String,
|
|
propositionId: json['propositionId'] as String?,
|
|
evaluateurId: json['evaluateurId'] as String,
|
|
nomEvaluateur: json['nomEvaluateur'] as String,
|
|
typeEvaluateur: _parseTypeEvaluateur(json['typeEvaluateur'] as String),
|
|
statut: _parseStatutEvaluation(json['statut'] as String),
|
|
noteGlobale: json['noteGlobale'].toDouble(),
|
|
noteDelaiReponse: json['noteDelaiReponse']?.toDouble(),
|
|
noteCommunication: json['noteCommunication']?.toDouble(),
|
|
noteProfessionnalisme: json['noteProfessionnalisme']?.toDouble(),
|
|
noteRespectEngagements: json['noteRespectEngagements']?.toDouble(),
|
|
commentairePrincipal: json['commentairePrincipal'] as String,
|
|
pointsPositifs: json['pointsPositifs'] as String?,
|
|
pointsAmelioration: json['pointsAmelioration'] as String?,
|
|
recommandations: json['recommandations'] as String?,
|
|
recommande: json['recommande'] as bool?,
|
|
dateCreation: DateTime.parse(json['dateCreation'] as String),
|
|
dateModification: DateTime.parse(json['dateModification'] as String),
|
|
dateValidation: json['dateValidation'] != null
|
|
? DateTime.parse(json['dateValidation'] as String)
|
|
: null,
|
|
validateurId: json['validateurId'] as String?,
|
|
motifSignalement: json['motifSignalement'] as String?,
|
|
nombreSignalements: json['nombreSignalements'] as int? ?? 0,
|
|
estModeree: json['estModeree'] as bool? ?? false,
|
|
estPublique: json['estPublique'] as bool? ?? true,
|
|
donneesPersonnalisees: Map<String, dynamic>.from(json['donneesPersonnalisees'] ?? {}),
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en JSON (API Request)
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'demandeId': demandeId,
|
|
'propositionId': propositionId,
|
|
'evaluateurId': evaluateurId,
|
|
'nomEvaluateur': nomEvaluateur,
|
|
'typeEvaluateur': typeEvaluateur.name,
|
|
'statut': statut.name,
|
|
'noteGlobale': noteGlobale,
|
|
'noteDelaiReponse': noteDelaiReponse,
|
|
'noteCommunication': noteCommunication,
|
|
'noteProfessionnalisme': noteProfessionnalisme,
|
|
'noteRespectEngagements': noteRespectEngagements,
|
|
'commentairePrincipal': commentairePrincipal,
|
|
'pointsPositifs': pointsPositifs,
|
|
'pointsAmelioration': pointsAmelioration,
|
|
'recommandations': recommandations,
|
|
'recommande': recommande,
|
|
'dateCreation': dateCreation.toIso8601String(),
|
|
'dateModification': dateModification.toIso8601String(),
|
|
'dateValidation': dateValidation?.toIso8601String(),
|
|
'validateurId': validateurId,
|
|
'motifSignalement': motifSignalement,
|
|
'nombreSignalements': nombreSignalements,
|
|
'estModeree': estModeree,
|
|
'estPublique': estPublique,
|
|
'donneesPersonnalisees': donneesPersonnalisees,
|
|
};
|
|
}
|
|
|
|
/// Crée un modèle à partir d'une entité du domaine
|
|
factory EvaluationAideModel.fromEntity(EvaluationAide entity) {
|
|
return EvaluationAideModel(
|
|
id: entity.id,
|
|
demandeId: entity.demandeId,
|
|
propositionId: entity.propositionId,
|
|
evaluateurId: entity.evaluateurId,
|
|
nomEvaluateur: entity.nomEvaluateur,
|
|
typeEvaluateur: entity.typeEvaluateur,
|
|
statut: entity.statut,
|
|
noteGlobale: entity.noteGlobale,
|
|
noteDelaiReponse: entity.noteDelaiReponse,
|
|
noteCommunication: entity.noteCommunication,
|
|
noteProfessionnalisme: entity.noteProfessionnalisme,
|
|
noteRespectEngagements: entity.noteRespectEngagements,
|
|
commentairePrincipal: entity.commentairePrincipal,
|
|
pointsPositifs: entity.pointsPositifs,
|
|
pointsAmelioration: entity.pointsAmelioration,
|
|
recommandations: entity.recommandations,
|
|
recommande: entity.recommande,
|
|
dateCreation: entity.dateCreation,
|
|
dateModification: entity.dateModification,
|
|
dateValidation: entity.dateValidation,
|
|
validateurId: entity.validateurId,
|
|
motifSignalement: entity.motifSignalement,
|
|
nombreSignalements: entity.nombreSignalements,
|
|
estModeree: entity.estModeree,
|
|
estPublique: entity.estPublique,
|
|
donneesPersonnalisees: Map<String, dynamic>.from(entity.donneesPersonnalisees),
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en entité du domaine
|
|
EvaluationAide toEntity() {
|
|
return EvaluationAide(
|
|
id: id,
|
|
demandeId: demandeId,
|
|
propositionId: propositionId,
|
|
evaluateurId: evaluateurId,
|
|
nomEvaluateur: nomEvaluateur,
|
|
typeEvaluateur: typeEvaluateur,
|
|
statut: statut,
|
|
noteGlobale: noteGlobale,
|
|
noteDelaiReponse: noteDelaiReponse,
|
|
noteCommunication: noteCommunication,
|
|
noteProfessionnalisme: noteProfessionnalisme,
|
|
noteRespectEngagements: noteRespectEngagements,
|
|
commentairePrincipal: commentairePrincipal,
|
|
pointsPositifs: pointsPositifs,
|
|
pointsAmelioration: pointsAmelioration,
|
|
recommandations: recommandations,
|
|
recommande: recommande,
|
|
dateCreation: dateCreation,
|
|
dateModification: dateModification,
|
|
dateValidation: dateValidation,
|
|
validateurId: validateurId,
|
|
motifSignalement: motifSignalement,
|
|
nombreSignalements: nombreSignalements,
|
|
estModeree: estModeree,
|
|
estPublique: estPublique,
|
|
donneesPersonnalisees: donneesPersonnalisees,
|
|
);
|
|
}
|
|
|
|
// Méthodes utilitaires de parsing
|
|
static TypeEvaluateur _parseTypeEvaluateur(String value) {
|
|
return TypeEvaluateur.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => TypeEvaluateur.beneficiaire,
|
|
);
|
|
}
|
|
|
|
static StatutEvaluation _parseStatutEvaluation(String value) {
|
|
return StatutEvaluation.values.firstWhere(
|
|
(e) => e.name == value,
|
|
orElse: () => StatutEvaluation.brouillon,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Modèle pour les statistiques d'évaluation
|
|
class StatistiquesEvaluationModel {
|
|
final double noteMoyenne;
|
|
final int nombreEvaluations;
|
|
final Map<int, int> repartitionNotes;
|
|
final double pourcentageRecommandations;
|
|
final List<EvaluationAideModel> evaluationsRecentes;
|
|
final DateTime dateCalcul;
|
|
|
|
const StatistiquesEvaluationModel({
|
|
required this.noteMoyenne,
|
|
required this.nombreEvaluations,
|
|
required this.repartitionNotes,
|
|
required this.pourcentageRecommandations,
|
|
required this.evaluationsRecentes,
|
|
required this.dateCalcul,
|
|
});
|
|
|
|
/// Crée un modèle à partir d'un JSON (API Response)
|
|
factory StatistiquesEvaluationModel.fromJson(Map<String, dynamic> json) {
|
|
return StatistiquesEvaluationModel(
|
|
noteMoyenne: json['noteMoyenne'].toDouble(),
|
|
nombreEvaluations: json['nombreEvaluations'] as int,
|
|
repartitionNotes: Map<int, int>.from(json['repartitionNotes']),
|
|
pourcentageRecommandations: json['pourcentageRecommandations'].toDouble(),
|
|
evaluationsRecentes: (json['evaluationsRecentes'] as List<dynamic>)
|
|
.map((e) => EvaluationAideModel.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
dateCalcul: DateTime.parse(json['dateCalcul'] as String),
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en JSON
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'noteMoyenne': noteMoyenne,
|
|
'nombreEvaluations': nombreEvaluations,
|
|
'repartitionNotes': repartitionNotes,
|
|
'pourcentageRecommandations': pourcentageRecommandations,
|
|
'evaluationsRecentes': evaluationsRecentes
|
|
.map((e) => e.toJson())
|
|
.toList(),
|
|
'dateCalcul': dateCalcul.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
/// Convertit le modèle en entité du domaine
|
|
StatistiquesEvaluation toEntity() {
|
|
return StatistiquesEvaluation(
|
|
noteMoyenne: noteMoyenne,
|
|
nombreEvaluations: nombreEvaluations,
|
|
repartitionNotes: repartitionNotes,
|
|
pourcentageRecommandations: pourcentageRecommandations,
|
|
evaluationsRecentes: evaluationsRecentes
|
|
.map((e) => e.toEntity())
|
|
.toList(),
|
|
dateCalcul: dateCalcul,
|
|
);
|
|
}
|
|
|
|
/// Crée un modèle à partir d'une entité du domaine
|
|
factory StatistiquesEvaluationModel.fromEntity(StatistiquesEvaluation entity) {
|
|
return StatistiquesEvaluationModel(
|
|
noteMoyenne: entity.noteMoyenne,
|
|
nombreEvaluations: entity.nombreEvaluations,
|
|
repartitionNotes: Map<int, int>.from(entity.repartitionNotes),
|
|
pourcentageRecommandations: entity.pourcentageRecommandations,
|
|
evaluationsRecentes: entity.evaluationsRecentes
|
|
.map((e) => EvaluationAideModel.fromEntity(e))
|
|
.toList(),
|
|
dateCalcul: entity.dateCalcul,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Modèle pour les réponses de recherche d'évaluations
|
|
class RechercheEvaluationsResponse {
|
|
final List<EvaluationAideModel> evaluations;
|
|
final int totalElements;
|
|
final int totalPages;
|
|
final int currentPage;
|
|
final int pageSize;
|
|
final bool hasNext;
|
|
final bool hasPrevious;
|
|
|
|
const RechercheEvaluationsResponse({
|
|
required this.evaluations,
|
|
required this.totalElements,
|
|
required this.totalPages,
|
|
required this.currentPage,
|
|
required this.pageSize,
|
|
required this.hasNext,
|
|
required this.hasPrevious,
|
|
});
|
|
|
|
/// Crée un modèle à partir d'un JSON (API Response)
|
|
factory RechercheEvaluationsResponse.fromJson(Map<String, dynamic> json) {
|
|
return RechercheEvaluationsResponse(
|
|
evaluations: (json['content'] as List<dynamic>)
|
|
.map((e) => EvaluationAideModel.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
totalElements: json['totalElements'] as int,
|
|
totalPages: json['totalPages'] as int,
|
|
currentPage: json['number'] as int,
|
|
pageSize: json['size'] as int,
|
|
hasNext: !(json['last'] as bool),
|
|
hasPrevious: !(json['first'] as bool),
|
|
);
|
|
}
|
|
|
|
/// Convertit le modèle en JSON
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'content': evaluations.map((e) => e.toJson()).toList(),
|
|
'totalElements': totalElements,
|
|
'totalPages': totalPages,
|
|
'number': currentPage,
|
|
'size': pageSize,
|
|
'last': !hasNext,
|
|
'first': !hasPrevious,
|
|
};
|
|
}
|
|
}
|
|
|
|
/// Modèle pour les requêtes de création d'évaluation
|
|
class CreerEvaluationRequest {
|
|
final String demandeId;
|
|
final String? propositionId;
|
|
final String evaluateurId;
|
|
final TypeEvaluateur typeEvaluateur;
|
|
final double noteGlobale;
|
|
final double? noteDelaiReponse;
|
|
final double? noteCommunication;
|
|
final double? noteProfessionnalisme;
|
|
final double? noteRespectEngagements;
|
|
final String commentairePrincipal;
|
|
final String? pointsPositifs;
|
|
final String? pointsAmelioration;
|
|
final String? recommandations;
|
|
final bool? recommande;
|
|
final bool estPublique;
|
|
final Map<String, dynamic> donneesPersonnalisees;
|
|
|
|
const CreerEvaluationRequest({
|
|
required this.demandeId,
|
|
this.propositionId,
|
|
required this.evaluateurId,
|
|
required this.typeEvaluateur,
|
|
required this.noteGlobale,
|
|
this.noteDelaiReponse,
|
|
this.noteCommunication,
|
|
this.noteProfessionnalisme,
|
|
this.noteRespectEngagements,
|
|
required this.commentairePrincipal,
|
|
this.pointsPositifs,
|
|
this.pointsAmelioration,
|
|
this.recommandations,
|
|
this.recommande,
|
|
this.estPublique = true,
|
|
this.donneesPersonnalisees = const {},
|
|
});
|
|
|
|
/// Convertit la requête en JSON
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'demandeId': demandeId,
|
|
'propositionId': propositionId,
|
|
'evaluateurId': evaluateurId,
|
|
'typeEvaluateur': typeEvaluateur.name,
|
|
'noteGlobale': noteGlobale,
|
|
'noteDelaiReponse': noteDelaiReponse,
|
|
'noteCommunication': noteCommunication,
|
|
'noteProfessionnalisme': noteProfessionnalisme,
|
|
'noteRespectEngagements': noteRespectEngagements,
|
|
'commentairePrincipal': commentairePrincipal,
|
|
'pointsPositifs': pointsPositifs,
|
|
'pointsAmelioration': pointsAmelioration,
|
|
'recommandations': recommandations,
|
|
'recommande': recommande,
|
|
'estPublique': estPublique,
|
|
'donneesPersonnalisees': donneesPersonnalisees,
|
|
};
|
|
}
|
|
|
|
/// Crée une requête à partir d'une entité d'évaluation
|
|
factory CreerEvaluationRequest.fromEntity(EvaluationAide entity) {
|
|
return CreerEvaluationRequest(
|
|
demandeId: entity.demandeId,
|
|
propositionId: entity.propositionId,
|
|
evaluateurId: entity.evaluateurId,
|
|
typeEvaluateur: entity.typeEvaluateur,
|
|
noteGlobale: entity.noteGlobale,
|
|
noteDelaiReponse: entity.noteDelaiReponse,
|
|
noteCommunication: entity.noteCommunication,
|
|
noteProfessionnalisme: entity.noteProfessionnalisme,
|
|
noteRespectEngagements: entity.noteRespectEngagements,
|
|
commentairePrincipal: entity.commentairePrincipal,
|
|
pointsPositifs: entity.pointsPositifs,
|
|
pointsAmelioration: entity.pointsAmelioration,
|
|
recommandations: entity.recommandations,
|
|
recommande: entity.recommande,
|
|
estPublique: entity.estPublique,
|
|
donneesPersonnalisees: entity.donneesPersonnalisees,
|
|
);
|
|
}
|
|
}
|