diff --git a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs index 8bbb295..2621269 100644 --- a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs +++ b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs @@ -128,14 +128,32 @@ namespace EPAServeur.Tests.Services } #endregion + #region Récupérer EP avec CommentaireAssistant + [TestCase(2, 2)] + [TestCase(4, 0)] + [TestCase(16, 1)] + public async Task GetEpById_GetCommentairesAssistant(long idEP, int count) + { + IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); + EpDTO epDTO = await epDetailsService.GetEp(idEP); + if (count == 0) + { + Assert.IsNull(epDTO.CommentairesAssistant); + } + else + { + Assert.IsNotNull(epDTO.CommentairesAssistant); + Assert.AreEqual(count, epDTO.CommentairesAssistant.Count); + } + } + #endregion + #region Récupérer EP avec RDV entretiens #endregion #region Récupérer EP avec type entretien #endregion - #region Récupérer EP avec CommentaireAssistant - #endregion #region Récupérer EP avec demandes de délégation #endregion diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index 4b2bf6f..ba32f35 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -86,7 +86,7 @@ namespace EPAServeur.Context { Engagement eg1, eg2, eg3, eg4; ParticipationEP p1, p2, p3, p4, p5; - + CommentaireAssistant ca1, ca2, ca3; //Ep en cours Ep epEnCours1, epEnCours2, epEnCours3, epEnCours4, epEnCours5, epEnCours6, epEnCours7, epEnCours8, epEnCours9; @@ -118,6 +118,19 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("e7820f92-eab1-42f5-ae96-5c16e71ff1e6"), Obligatoire = false, }; + ca1 = new CommentaireAssistant() + { + Commentaire = "Commentaire assistant", + IdAssistant = new Guid("a43b6f4f-f199-4dd0-93b6-a1cb2c0a0d14"), + Ep = epEnCours2 + }; + ca2 = new CommentaireAssistant() + { + Commentaire = "Commentaire assistant", + IdAssistant = new Guid("a29d707c-5d82-4c48-bed1-a6d1c1710047"), + Ep = epEnCours2 + }; + epEnCours2.CommentairesAssistant = new List(new[] { ca1, ca2 }); epContext.Ep.Add(epEnCours2); @@ -133,6 +146,7 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832"), Obligatoire = false, }; + p1 = new ParticipationEP() { Ep = epEnCours3, @@ -269,6 +283,7 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("13fbe621-1bc9-4f04-afde-b54ca076e239"), Obligatoire = true, }; + epContext.Ep.Add(epEnCours9); @@ -398,6 +413,14 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("13fbe621-1bc9-4f04-afde-b54ca076e239"), Obligatoire = false, }; + ca3 = new CommentaireAssistant() + { + Commentaire = "Commentaire assistant", + IdAssistant = new Guid("e6255f16-bcaf-48ac-b00b-97de83677ad8"), + Ep = epSigne7 + }; + epSigne7.CommentairesAssistant = new List(); + epSigne7.CommentairesAssistant.Add(ca3); epContext.Ep.Add(epSigne7); epSigne8 = new Ep() diff --git a/EPAServeur/IServices/ITransformDTO.cs b/EPAServeur/IServices/ITransformDTO.cs index 1a410b9..ed7dffe 100644 --- a/EPAServeur/IServices/ITransformDTO.cs +++ b/EPAServeur/IServices/ITransformDTO.cs @@ -74,6 +74,7 @@ namespace EPAServeur.IServices EpDTO EpToEpDetails(Ep ep, IEnumerable collaborateurDTOs); List GetEngagementDTOs(List engagements); List GetParticipantsDTO(List participants, IEnumerable collaborateurDTOs); + List GetCommentaireAssistant(List commentaireAssistant, IEnumerable collaborateurDTOs); DemandeEPIDTO GetDemandeEPIDTO(DemandeEPI demande, IEnumerable collaborateurDTOs); AugmentationSalaireDTO GetAugmentationSalaireDTO(AugmentationSalaire augmentation); DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable collaborateurDTOs); @@ -83,7 +84,6 @@ namespace EPAServeur.IServices DocumentDTO GetDocumentDTO(Document document); ObjectifDTO GetObjectifDTO(Objectif objectif); ObjectifPrecedentDTO GetObjectifPrecedentDTO(ObjectifPrecedent objectifPrecedent); - CommentaireAssistant GetCommentaireAssistant(CommentaireAssistant commentaireAssistant); diff --git a/EPAServeur/Services/EpDetailsService.cs b/EPAServeur/Services/EpDetailsService.cs index f8ae2e1..18c9efa 100644 --- a/EPAServeur/Services/EpDetailsService.cs +++ b/EPAServeur/Services/EpDetailsService.cs @@ -29,6 +29,7 @@ namespace EPAServeur.Services Ep ep = await context.Ep .Include(ep => ep.Engagements) .Include(ep => ep.Participants) + .Include(ep => ep.CommentairesAssistant) .FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); if (ep == null) throw new EpNotFoundException(); @@ -40,6 +41,8 @@ namespace EPAServeur.Services guids.Add(ep.IdCollaborateur); if (ep.Participants != null && ep.Participants.Any()) guids.AddRange(ep.Participants.SelectMany(p => new[] { (Guid?)p.IdParticipant })); + if (ep.CommentairesAssistant != null && ep.CommentairesAssistant.Any()) + guids.AddRange(ep.CommentairesAssistant.SelectMany(p => new[] { (Guid?)p.IdAssistant })); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); diff --git a/EPAServeur/Services/TransformDTO.cs b/EPAServeur/Services/TransformDTO.cs index b291f73..3f43355 100644 --- a/EPAServeur/Services/TransformDTO.cs +++ b/EPAServeur/Services/TransformDTO.cs @@ -62,7 +62,8 @@ namespace EPAServeur.Services Type = ep.TypeEP, Cv = ep.CV, Engagements = GetEngagementDTOs(ep.Engagements), - Participants = GetParticipantsDTO(ep.Participants, collaborateurDTOs) + Participants = GetParticipantsDTO(ep.Participants, collaborateurDTOs), + CommentairesAssistant = GetCommentaireAssistant(ep.CommentairesAssistant, collaborateurDTOs) }; } @@ -205,11 +206,27 @@ namespace EPAServeur.Services /// /// Transformer un commentaire assistante en objet DTO /// - /// Le commentaire a transformé en DTO + /// Les commentaire a transformé en DTO /// Le commentaire assistant transformé en DTO - public CommentaireAssistant GetCommentaireAssistant(CommentaireAssistant commentaireAssistant) + public List GetCommentaireAssistant(List commentairesAssistant, IEnumerable collaborateurDTOs) { - throw new NotImplementedException(); + if (commentairesAssistant == null || !commentairesAssistant.Any()) + return null; + List commentaireAssistantDTO = new List(); + foreach(CommentaireAssistant ca in commentairesAssistant) + { + CollaborateurDTO c = collaborateurDTOs.FirstOrDefault(collaborateur => collaborateur.Id.Equals(ca.IdAssistant)); + if(c != null) + { + commentaireAssistantDTO.Add(new CommentaireAssistantDTO() + { + Commentaire = ca.Commentaire, + Id = ca.IdCommentaireAssistant, + IdAssistante = ca.IdAssistant + }); + } + } + return commentaireAssistantDTO.Any() ? commentaireAssistantDTO : null; }