diff --git a/ApiCollaborateur/CollaborateurApi.cs b/ApiCollaborateur/CollaborateurApi.cs index 8d70356..5713160 100644 --- a/ApiCollaborateur/CollaborateurApi.cs +++ b/ApiCollaborateur/CollaborateurApi.cs @@ -778,6 +778,8 @@ namespace IO.Swagger.ApiCollaborateur public List ChercherCollab (List collabsId = null, bool? ancienCollaborateur = null, bool? referent = null) { ApiResponse> localVarResponse = ChercherCollabWithHttpInfo(collabsId, ancienCollaborateur, referent); + if (localVarResponse == null) + return new List(); return localVarResponse.Data; } @@ -914,6 +916,8 @@ namespace IO.Swagger.ApiCollaborateur public List ChercherCollabAgence (long? agenceId, bool? referent = null) { ApiResponse> localVarResponse = ChercherCollabAgenceWithHttpInfo(agenceId, referent); + if (localVarResponse == null) + return null; return localVarResponse.Data; } @@ -964,7 +968,7 @@ namespace IO.Swagger.ApiCollaborateur if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ChercherCollabAgence", localVarResponse); - if (exception != null) throw exception; + if (exception != null) return null; } return new ApiResponse>(localVarStatusCode, @@ -1051,6 +1055,8 @@ namespace IO.Swagger.ApiCollaborateur public List ChercherCollabBU (long? buId, bool? referent = null) { ApiResponse> localVarResponse = ChercherCollabBUWithHttpInfo(buId, referent); + if (localVarResponse == null) + return new List(); return localVarResponse.Data; } @@ -1101,7 +1107,7 @@ namespace IO.Swagger.ApiCollaborateur if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ChercherCollabBU", localVarResponse); - if (exception != null) throw exception; + if (exception != null) return null; } return new ApiResponse>(localVarStatusCode, @@ -1320,6 +1326,8 @@ namespace IO.Swagger.ApiCollaborateur public Collaborateur ChercherCollabMail (string mailApside) { ApiResponse localVarResponse = ChercherCollabMailWithHttpInfo(mailApside); + if (localVarResponse == null) + return null; return localVarResponse.Data; } @@ -1368,7 +1376,7 @@ namespace IO.Swagger.ApiCollaborateur if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ChercherCollabMail", localVarResponse); - if (exception != null) throw exception; + if (exception != null) return null; } return new ApiResponse(localVarStatusCode, @@ -1451,6 +1459,8 @@ namespace IO.Swagger.ApiCollaborateur public List ChercherCollabRef (Guid? refId) { ApiResponse> localVarResponse = ChercherCollabRefWithHttpInfo(refId); + if (localVarResponse == null) + return new List(); return localVarResponse.Data; } @@ -1499,7 +1509,7 @@ namespace IO.Swagger.ApiCollaborateur if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ChercherCollabRef", localVarResponse); - if (exception != null) throw exception; + if (exception != null) return null; } return new ApiResponse>(localVarStatusCode, diff --git a/Controllers/CollaborateursApi.cs b/Controllers/CollaborateursApi.cs index d7da8a3..c9e9c70 100644 --- a/Controllers/CollaborateursApi.cs +++ b/Controllers/CollaborateursApi.cs @@ -51,8 +51,8 @@ namespace IO.Swagger.Controllers [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] public virtual IActionResult GetCollaborateurById([FromRoute][Required]Guid? idCollaborateur) { - //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(CollaborateurDTO)); + //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)); CollaborateurDTO collaborateurDTO = collaborateurService.GetCollaborateurById(idCollaborateur); if( collaborateurDTO == null) @@ -65,18 +65,6 @@ namespace IO.Swagger.Controllers return NotFound(erreurDTO); } return Ok(collaborateurDTO); - //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)); - - //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... - // return StatusCode(404, default(ErreurDTO)); - /*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}"; - - var example = exampleJson != null - ? JsonConvert.DeserializeObject(exampleJson) - : default(CollaborateurDTO); //TODO: Change the data returned - return new ObjectResult(example);*/ } /// @@ -89,29 +77,29 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/collaborateurs/mail/{mail}")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetCollaborateurByMail")] [SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] public virtual IActionResult GetCollaborateurByMail([FromRoute][Required]string mail) - { - //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(CollaborateurDTO)); - + { //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)); - - //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... - // return StatusCode(404, default(ErreurDTO)); - 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}"; - var example = exampleJson != null - ? JsonConvert.DeserializeObject(exampleJson) - : default(CollaborateurDTO); //TODO: Change the data returned - return new ObjectResult(example); + CollaborateurDTO collaborateurDTO = collaborateurService.GetCollaborateurByMail(mail); + if (collaborateurDTO == null) + { + ErreurDTO erreurDTO = new ErreurDTO() + { + Code = "404", + Message = "Aucun collaborateur n'est lié au mail "+mail, + }; + return NotFound(erreurDTO); + } + return Ok(collaborateurDTO); + } /// @@ -137,17 +125,11 @@ namespace IO.Swagger.Controllers [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] 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, 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; - 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} ]"; + + return Ok(collaborateurService.GetCollaborateurs(asc, numPage, parPAge, fonctions, idAgence, idBU, texte, tri)); - var example = exampleJson != null - ? JsonConvert.DeserializeObject>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example);*/ } /// @@ -165,29 +147,27 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/collaborateurs/referent/{idReferent}")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetCollaborateursByReferent")] [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] public virtual IActionResult GetCollaborateursByReferent([FromQuery][Required()]bool? asc, [FromRoute][Required]Guid? idReferent, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [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)); - + { //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)); - - //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... - // return StatusCode(404, default(ErreurDTO)); - 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); + List collaborateurs = collaborateurService.GetCollaborateursByReferent(idReferent, asc, numPage, parPAge, texte, tri); + if(collaborateurs == null) + { + ErreurDTO erreurDTO = new ErreurDTO() + { + Code = "404", + Message = "Le référent n'existe pas", + }; + return NotFound(erreurDTO); + } + return Ok(collaborateurs); } /// @@ -200,29 +180,28 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/collaborateurs/profil/{mail}/")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetProfilCollaborateurByMail")] [SwaggerResponse(statusCode: 200, type: typeof(ProfilDTO), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] public virtual IActionResult GetProfilCollaborateurByMail([FromRoute][Required]string mail) - { - //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(ProfilDTO)); - + { //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)); - //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... - // return StatusCode(404, default(ErreurDTO)); - 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 \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n}"; - - var example = exampleJson != null - ? JsonConvert.DeserializeObject(exampleJson) - : default(ProfilDTO); //TODO: Change the data returned - return new ObjectResult(example); + ProfilDTO collaborateurDTO = collaborateurService.GetProfilByMail(mail); + if (collaborateurDTO == null) + { + ErreurDTO erreurDTO = new ErreurDTO() + { + Code = "404", + Message = "Aucun collaborateur n'est lié au mail " + mail, + }; + return NotFound(erreurDTO); + } + return Ok(collaborateurDTO); } } } diff --git a/IServices/ICollaborateurService.cs b/IServices/ICollaborateurService.cs index 2f86193..1c02ed0 100644 --- a/IServices/ICollaborateurService.cs +++ b/IServices/ICollaborateurService.cs @@ -4,6 +4,7 @@ using IO.Swagger.ModelCollaborateur; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata; using System.Threading.Tasks; namespace EPAServeur.IServices @@ -12,8 +13,9 @@ namespace EPAServeur.IServices { CollaborateurDTO GetCollaborateurById(Guid? id); CollaborateurDTO GetCollaborateurByMail(string mail); + ProfilDTO GetProfilById(Guid? idCollaborateur); ProfilDTO GetProfilByMail(string mail); - List GetCollaborateurs(); - List GetCollaborateursByReferent(Guid? idRefent); + List GetCollaborateurs(bool? asc, int? numPage, int? parPage, List fonctions, int? idAgence, int? idBU, String texte, string tri); + List GetCollaborateursByReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, String texte, string tri); } } diff --git a/Services/CollaborateurService.cs b/Services/CollaborateurService.cs index 16b4cea..b2eea39 100644 --- a/Services/CollaborateurService.cs +++ b/Services/CollaborateurService.cs @@ -39,23 +39,46 @@ namespace EPAServeur.Services } - public List GetCollaborateurs() + public List GetCollaborateurs(bool? asc, int? numPage, int? parPage, List fonctions, int? idAgence, int? idBU, String texte, string tri) { - List collaborateurs = collaborateurApi.ChercherCollab(); - List collaborateursDTO = (from c in collaborateurs - select GetCollaborateurDTO(c)).ToList(); - //List collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList(); + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + List collaborateurs; + List collaborateursDTO; + if(idBU != null) + collaborateurs = collaborateurApi.ChercherCollabBU(idBU); + else if( idAgence != null) + collaborateurs = collaborateurApi.ChercherCollabAgence(idAgence); + else + collaborateurs = collaborateurApi.ChercherCollab(); + if (collaborateurs == null) + return new List(); + int skip = (numPage.Value - 1) * parPage.Value; + int take = parPage.Value; + collaborateursDTO = (from c in collaborateurs + where (c.Nom + " " + c.Prenom).ToLower().Contains(texte) || (c.Prenom + " " + c.Nom).ToLower().Contains(texte) + select GetCollaborateurDTO(c)).Skip(skip).Take(take).ToList(); return collaborateursDTO; } - public List GetCollaborateursByReferent(Guid? idReferent) + public List GetCollaborateursByReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, String texte, string tri) { + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + Collaborateur referent = collaborateurApi.ChercherCollabId(idReferent); + if (referent == null) + return null; List collaborateurs = collaborateurApi.ChercherCollabRef(idReferent); - List collaborateursDTO = (from c in collaborateurs - select GetCollaborateurDTO(c)).ToList(); - //List collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList(); - + int skip = (numPage.Value - 1) * parPage.Value; + int take = parPage.Value; + List collaborateursDTO = (from c in collaborateurs + where (c.Nom + " " + c.Prenom).ToLower().Contains(texte) || (c.Prenom + " " + c.Nom).ToLower().Contains(texte) + select GetCollaborateurDTO(c)).Skip(skip).Take(take).ToList(); return collaborateursDTO; } @@ -67,6 +90,15 @@ namespace EPAServeur.Services return GetProfilDTO(collaborateur); } + public ProfilDTO GetProfilById(Guid? idCollaborateur) + { + Collaborateur collaborateur = collaborateurApi.ChercherCollabId(idCollaborateur); + if (collaborateur == null) + return null; + return GetProfilDTO(collaborateur); + } + + //Object to DTO private ProfilDTO GetProfilDTO(Collaborateur collaborateur) { ProfilDTO profilDTO = new ProfilDTO() @@ -81,7 +113,7 @@ namespace EPAServeur.Services return profilDTO; } - //Object to DTO + private AgenceDTO GetAgenceDTO(Agence agence) { if (agence == null)