From b48458e2d050b3638f575aeca84abcd377f8d4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Wed, 10 Mar 2021 15:45:12 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20de=20la=20r=C3=A9cup?= =?UTF-8?q?=C3=A9ration=20des=20participants=20=C3=A0=20un=20EP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/EpDetailsServiceTests.cs | 18 +++++++ EPAServeur/Context/DataSeeder.cs | 39 ++++++++++++++- EPAServeur/IServices/ITransformDTO.cs | 3 +- EPAServeur/Models/EP/ParticipationEP.cs | 2 +- EPAServeur/Services/EpDetailsService.cs | 9 ++-- EPAServeur/Services/TransformDTO.cs | 49 ++++++++++++++----- 6 files changed, 102 insertions(+), 18 deletions(-) diff --git a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs index 086498f..8bbb295 100644 --- a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs +++ b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs @@ -108,6 +108,24 @@ namespace EPAServeur.Tests.Services #endregion #region Récupérer EP avec participant EP + [TestCase(1,0)] + [TestCase(3,2)] + [TestCase(5,1)] + [TestCase(11,2)] + public async Task GetEpById_GetParticipantEP(long idEP, int count) + { + IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); + EpDTO epDTO = await epDetailsService.GetEp(idEP); + if (count == 0) + { + Assert.IsNull(epDTO.Participants); + } + else + { + Assert.IsNotNull(epDTO.Participants); + Assert.AreEqual(count, epDTO.Participants.Count); + } + } #endregion #region Récupérer EP avec RDV entretiens diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index 8b7902d..4b2bf6f 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -85,9 +85,12 @@ namespace EPAServeur.Context public static void AddEp(EpContext epContext) { Engagement eg1, eg2, eg3, eg4; + ParticipationEP p1, p2, p3, p4, p5; + + //Ep en cours Ep epEnCours1, epEnCours2, epEnCours3, epEnCours4, epEnCours5, epEnCours6, epEnCours7, epEnCours8, epEnCours9; - //Tours + epEnCours1 = new Ep() { @@ -130,6 +133,20 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832"), Obligatoire = false, }; + p1 = new ParticipationEP() + { + Ep = epEnCours3, + IdParticipant = new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"), + EstPermanente = false + }; + p2 = new ParticipationEP() + { + Ep = epEnCours3, + IdParticipant = new Guid("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"), + EstPermanente = false + }; + epEnCours3.Participants = new List(new[] { p1, p2 }); + epContext.Ep.Add(epEnCours3); epEnCours4 = new Ep() @@ -158,6 +175,13 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"), Obligatoire = true, }; + p3 = new ParticipationEP() + { + Ep = epEnCours5, + IdParticipant = new Guid("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"), + EstPermanente = false + }; + epEnCours5.Participants = new List(new[] { p3 }); epContext.Ep.Add(epEnCours5); epEnCours6 = new Ep() @@ -289,6 +313,19 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("e7820f92-eab1-42f5-ae96-5c16e71ff1e6"), Obligatoire = false, }; + p4 = new ParticipationEP() + { + Ep = epSigne2, + IdParticipant = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), + EstPermanente = false + }; + p5 = new ParticipationEP() + { + Ep = epSigne2, + IdParticipant = new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"), + EstPermanente = false + }; + epSigne2.Participants = new List(new[] { p4, p5 }); epContext.Ep.Add(epSigne2); diff --git a/EPAServeur/IServices/ITransformDTO.cs b/EPAServeur/IServices/ITransformDTO.cs index af5770c..1a410b9 100644 --- a/EPAServeur/IServices/ITransformDTO.cs +++ b/EPAServeur/IServices/ITransformDTO.cs @@ -72,7 +72,8 @@ namespace EPAServeur.IServices // Récupération DetailsEP EpDTO EpToEpDetails(Ep ep, IEnumerable collaborateurDTOs); - List GetEngagementDTOs(Ep ep); + List GetEngagementDTOs(List engagements); + List GetParticipantsDTO(List participants, IEnumerable collaborateurDTOs); DemandeEPIDTO GetDemandeEPIDTO(DemandeEPI demande, IEnumerable collaborateurDTOs); AugmentationSalaireDTO GetAugmentationSalaireDTO(AugmentationSalaire augmentation); DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable collaborateurDTOs); diff --git a/EPAServeur/Models/EP/ParticipationEP.cs b/EPAServeur/Models/EP/ParticipationEP.cs index 2f1b960..64e3eb8 100644 --- a/EPAServeur/Models/EP/ParticipationEP.cs +++ b/EPAServeur/Models/EP/ParticipationEP.cs @@ -18,7 +18,7 @@ namespace EPAServeur.Models.EP /// /// Id du collaborateur participant à l’EP /// - public string IdParticipant { get; set; } + public Guid IdParticipant { get; set; } /// /// Indique si la participation est juste une participation d’un EP en cours ou des prochains EP en plus diff --git a/EPAServeur/Services/EpDetailsService.cs b/EPAServeur/Services/EpDetailsService.cs index 914636d..f8ae2e1 100644 --- a/EPAServeur/Services/EpDetailsService.cs +++ b/EPAServeur/Services/EpDetailsService.cs @@ -2,7 +2,6 @@ using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.EP; -using IO.Swagger.ApiCollaborateur; using IO.Swagger.DTO; using Microsoft.EntityFrameworkCore; using System; @@ -27,7 +26,10 @@ namespace EPAServeur.Services public async Task GetEp(long id) { - Ep ep = await context.Ep.Include(ep => ep.Engagements).FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); + Ep ep = await context.Ep + .Include(ep => ep.Engagements) + .Include(ep => ep.Participants) + .FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); if (ep == null) throw new EpNotFoundException(); @@ -36,7 +38,8 @@ namespace EPAServeur.Services guids.Add(ep.IdCollaborateur); if (ep.IdReferent.HasValue) guids.Add(ep.IdCollaborateur); - + if (ep.Participants != null && ep.Participants.Any()) + guids.AddRange(ep.Participants.SelectMany(p => new[] { (Guid?)p.IdParticipant })); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); diff --git a/EPAServeur/Services/TransformDTO.cs b/EPAServeur/Services/TransformDTO.cs index 2e86254..b291f73 100644 --- a/EPAServeur/Services/TransformDTO.cs +++ b/EPAServeur/Services/TransformDTO.cs @@ -61,7 +61,8 @@ namespace EPAServeur.Services Statut = ep.Statut, Type = ep.TypeEP, Cv = ep.CV, - Engagements = GetEngagementDTOs(ep) + Engagements = GetEngagementDTOs(ep.Engagements), + Participants = GetParticipantsDTO(ep.Participants, collaborateurDTOs) }; } @@ -295,11 +296,11 @@ namespace EPAServeur.Services return engagementDTO; } - public List GetEngagementDTOs(Ep ep) + public List GetEngagementDTOs(List engagements) { - if (ep.Engagements == null || ep.Engagements.Count == 0) + if (engagements == null || engagements.Count == 0) return null; - return ep.Engagements.Select(engagment => GetEngagementDTO(engagment, null, false)).ToList(); + return engagements.Select(engagment => GetEngagementDTO(engagment, null, false)).ToList(); } public TypeEntretienDTO GetEntretienDTO(ChoixTypeEntretien choixTypeEntretien) @@ -540,14 +541,38 @@ namespace EPAServeur.Services return origineFormationDTO; } - /// - /// Transformer un objet ParticipationFormation en objet ParticipationFormationDTO. - /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO. - /// - /// - /// - /// - public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) + public List GetParticipantsDTO(List participants, IEnumerable collaborateurDTOs) + { + if (participants == null || !participants.Any()) + return null; + List participantsDTO = new List(); + foreach(ParticipationEP p in participants) + { + CollaborateurDTO c = collaborateurDTOs.FirstOrDefault( c => c.Id.Equals(p.IdParticipant)); + if(c != null) + { + participantsDTO.Add(new ParticipationEPDTO() + { + Id = p.IdParticipationEP, + EstPermanente = p.EstPermanente, + IdParticipant = c.Id, + Participant = c.Nom + " " + c.Prenom + }); + } + } + if (participantsDTO.Any()) + return participantsDTO; + return null; + } + + /// + /// Transformer un objet ParticipationFormation en objet ParticipationFormationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO. + /// + /// + /// + /// + public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) { if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) return null;