diff --git a/Controllers/CollaborateursApi.cs b/Controllers/CollaborateursApi.cs index 672b80e..c4cd299 100644 --- a/Controllers/CollaborateursApi.cs +++ b/Controllers/CollaborateursApi.cs @@ -130,7 +130,7 @@ namespace IO.Swagger.Controllers /// Acces interdit [HttpGet] [Route("/api/collaborateurs")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetCollaborateurs")] [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] @@ -138,17 +138,16 @@ namespace IO.Swagger.Controllers public virtual IActionResult GetCollaborateurs([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]List fonctions, [FromQuery]int? idAgence, [FromQuery]int? idBU, [FromQuery]string texte, [FromQuery]string tri) { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... - // return StatusCode(200, default(List)); - + return StatusCode(200, collaborateurService.GetCollaborateurs()); //TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ... // return StatusCode(403, default(ErreurDTO)); - string exampleJson = null; + /*string exampleJson = null; exampleJson = "[ {\n \"businessUnit\" : {\n \"agence\" : {\n \"bu\" : [ null, null ],\n \"id\" : 6.027456183070403,\n \"nom\" : \"nom\"\n },\n \"id\" : 0.8008281904610115,\n \"nom\" : \"nom\"\n },\n \"mailApside\" : \"\",\n \"dateArrivee\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateDepart\" : \"2000-01-23T04:56:07.000+00:00\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n}, {\n \"businessUnit\" : {\n \"agence\" : {\n \"bu\" : [ null, null ],\n \"id\" : 6.027456183070403,\n \"nom\" : \"nom\"\n },\n \"id\" : 0.8008281904610115,\n \"nom\" : \"nom\"\n },\n \"mailApside\" : \"\",\n \"dateArrivee\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateDepart\" : \"2000-01-23T04:56:07.000+00:00\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n} ]"; var example = exampleJson != null ? JsonConvert.DeserializeObject>(exampleJson) : default(List); //TODO: Change the data returned - return new ObjectResult(example); + return new ObjectResult(example);*/ } /// diff --git a/IServices/ICollaborateurService.cs b/IServices/ICollaborateurService.cs index 117de68..652c3e8 100644 --- a/IServices/ICollaborateurService.cs +++ b/IServices/ICollaborateurService.cs @@ -16,8 +16,10 @@ namespace EPAServeur.IServices List GetCollaborateurs(); List GetCollaborateursByReferent(Guid? idRefent); + //Object to DTO CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur); BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit); + AgenceDTO GetAgenceDTO(Agence agence); ReferentDTO GetReferentDTO(Collaborateur referent); } } diff --git a/Services/CollaborateurService.cs b/Services/CollaborateurService.cs index d6d8df0..f160656 100644 --- a/Services/CollaborateurService.cs +++ b/Services/CollaborateurService.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices.ComTypes; using System.Threading.Tasks; namespace EPAServeur.Services @@ -20,64 +21,81 @@ namespace EPAServeur.Services collaborateurApi = _collaborateurApi; } - public CollaborateurDTO GetCollaborateurById(Guid? id) + // + public AgenceDTO GetAgenceDTO(Agence agence) { - Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id); - if (collaborateur == null) + if (agence == null) return null; - CollaborateurDTO collaborateurDTO = new CollaborateurDTO() + AgenceDTO agenceDTO = new AgenceDTO() { - Id = collaborateur.Id, - Prenom = collaborateur.Prenom, - Nom = collaborateur.Nom, - MailApside = collaborateur.MailApside, - DateArrivee = collaborateur.DateArrivee, - + Id = agence.Id, + Nom = agence.Nom, + Bu = new List() }; - collaborateurDTO.BusinessUnit = new BusinessUnitDTO() + foreach(BU bu in agence.Bus) { - Id = collaborateur.BusinessUnit.Id, - Nom = collaborateur.BusinessUnit.Nom, - Agence = new AgenceDTO() + agenceDTO.Bu.Add(new BusinessUnitDTO() { - Id = collaborateur.BusinessUnit.Agence.Id, - Nom = collaborateur.BusinessUnit.Agence.Nom - } - }; - collaborateurDTO.Referent = new ReferentDTO() + Id = bu.Id, + Nom = bu.Nom + }); + } + return agenceDTO; + } + + public BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit) + { + if (businessUnit == null) + return null; + BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO() { - Id = collaborateur.Referent.Id, - Prenom = collaborateur.Referent.Prenom, - Nom = collaborateur.Referent.Nom, - MailApside = collaborateur.Referent.MailApside + Id = businessUnit.Id, + Nom = businessUnit.Nom, + Agence = GetAgenceDTO(businessUnit.Agence) }; - return collaborateurDTO; + return businessUnitDTO; + } + + public CollaborateurDTO GetCollaborateurById(Guid? id) + { + Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id); + if (collaborateur == null) + return null; + return GetCollaborateurDTO(collaborateur); } public CollaborateurDTO GetCollaborateurByMail(string mail) { Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail); + if (collaborateur == null) + return null; + return GetCollaborateurDTO(collaborateur); + } + + public CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur) + { CollaborateurDTO collaborateurDTO = new CollaborateurDTO() { Id = collaborateur.Id, Prenom = collaborateur.Prenom, Nom = collaborateur.Nom, MailApside = collaborateur.MailApside, - DateArrivee = collaborateur.DateArrivee - }; - collaborateurDTO.Referent = new ReferentDTO() - { - Id = collaborateur.Referent.Id, - Prenom = collaborateur.Referent.Prenom, - Nom = collaborateur.Referent.Nom, - MailApside = collaborateur.Referent.MailApside + DateArrivee = collaborateur.DateArrivee, + }; + collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit); + collaborateurDTO.Referent = GetReferentDTO(collaborateur.Referent); return collaborateurDTO; } public List GetCollaborateurs() { - throw new NotImplementedException(); + List collaborateurs = collaborateurApi.ChercherCollab(); + List collaborateursDTO = (from c in collaborateurs + select GetCollaborateurDTO(c)).ToList(); + //List collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList(); + + return collaborateursDTO; } public List GetCollaborateursByReferent(Guid? idReferent) @@ -108,5 +126,19 @@ namespace EPAServeur.Services { throw new NotImplementedException(); } + + public ReferentDTO GetReferentDTO(Collaborateur referent) + { + if (referent == null) + return null; + ReferentDTO referentDTO = new ReferentDTO() + { + Id = referent.Id, + Prenom = referent.Prenom, + Nom = referent.Nom, + MailApside = referent.MailApside + }; + return referentDTO; + } } }