Implémentation complète du service collaborateur et de l'api collaborateurs

develop
Yanaël GRETTE 4 years ago
parent a099587a74
commit 18316d9f8a
  1. 18
      ApiCollaborateur/CollaborateurApi.cs
  2. 109
      Controllers/CollaborateursApi.cs
  3. 6
      IServices/ICollaborateurService.cs
  4. 54
      Services/CollaborateurService.cs

@ -778,6 +778,8 @@ namespace IO.Swagger.ApiCollaborateur
public List<Collaborateur> ChercherCollab (List<Guid?> collabsId = null, bool? ancienCollaborateur = null, bool? referent = null)
{
ApiResponse<List<Collaborateur>> localVarResponse = ChercherCollabWithHttpInfo(collabsId, ancienCollaborateur, referent);
if (localVarResponse == null)
return new List<Collaborateur>();
return localVarResponse.Data;
}
@ -914,6 +916,8 @@ namespace IO.Swagger.ApiCollaborateur
public List<Collaborateur> ChercherCollabAgence (long? agenceId, bool? referent = null)
{
ApiResponse<List<Collaborateur>> 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<List<Collaborateur>>(localVarStatusCode,
@ -1051,6 +1055,8 @@ namespace IO.Swagger.ApiCollaborateur
public List<Collaborateur> ChercherCollabBU (long? buId, bool? referent = null)
{
ApiResponse<List<Collaborateur>> localVarResponse = ChercherCollabBUWithHttpInfo(buId, referent);
if (localVarResponse == null)
return new List<Collaborateur>();
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<List<Collaborateur>>(localVarStatusCode,
@ -1320,6 +1326,8 @@ namespace IO.Swagger.ApiCollaborateur
public Collaborateur ChercherCollabMail (string mailApside)
{
ApiResponse<Collaborateur> 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<Collaborateur>(localVarStatusCode,
@ -1451,6 +1459,8 @@ namespace IO.Swagger.ApiCollaborateur
public List<Collaborateur> ChercherCollabRef (Guid? refId)
{
ApiResponse<List<Collaborateur>> localVarResponse = ChercherCollabRefWithHttpInfo(refId);
if (localVarResponse == null)
return new List<Collaborateur>();
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<List<Collaborateur>>(localVarStatusCode,

@ -51,8 +51,8 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;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<CollaborateurDTO>(exampleJson)
: default(CollaborateurDTO); //TODO: Change the data returned
return new ObjectResult(example);*/
}
/// <summary>
@ -89,29 +77,29 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[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&#x27;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<CollaborateurDTO>(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);
}
/// <summary>
@ -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<string> 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<List<CollaborateurDTO>>(exampleJson)
: default(List<CollaborateurDTO>); //TODO: Change the data returned
return new ObjectResult(example);*/
}
/// <summary>
@ -165,29 +147,27 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/collaborateurs/referent/{idReferent}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetCollaborateursByReferent")]
[SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;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<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}, {\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<List<CollaborateurDTO>>(exampleJson)
: default(List<CollaborateurDTO>); //TODO: Change the data returned
return new ObjectResult(example);
List<CollaborateurDTO> 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);
}
/// <summary>
@ -200,29 +180,28 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[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&#x27;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<ProfilDTO>(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);
}
}
}

@ -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<CollaborateurDTO> GetCollaborateurs();
List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idRefent);
List<CollaborateurDTO> GetCollaborateurs(bool? asc, int? numPage, int? parPage, List<string> fonctions, int? idAgence, int? idBU, String texte, string tri);
List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, String texte, string tri);
}
}

@ -39,23 +39,46 @@ namespace EPAServeur.Services
}
public List<CollaborateurDTO> GetCollaborateurs()
public List<CollaborateurDTO> GetCollaborateurs(bool? asc, int? numPage, int? parPage, List<string> fonctions, int? idAgence, int? idBU, String texte, string tri)
{
List<Collaborateur> collaborateurs = collaborateurApi.ChercherCollab();
List<CollaborateurDTO> collaborateursDTO = (from c in collaborateurs
select GetCollaborateurDTO(c)).ToList();
//List<CollaborateurDTO> collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList();
if (texte == null)
texte = "";
else
texte = texte.ToLower();
List<Collaborateur> collaborateurs;
List<CollaborateurDTO> 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<CollaborateurDTO>();
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<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent)
public List<CollaborateurDTO> 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<Collaborateur> collaborateurs = collaborateurApi.ChercherCollabRef(idReferent);
List<CollaborateurDTO> collaborateursDTO = (from c in collaborateurs
select GetCollaborateurDTO(c)).ToList();
//List<CollaborateurDTO> collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList();
int skip = (numPage.Value - 1) * parPage.Value;
int take = parPage.Value;
List<CollaborateurDTO> 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)

Loading…
Cancel
Save