Récupération de la liste des collaborateurs 'simple' (sans trier)

master
Yanaël GRETTE 4 years ago
parent 96c3cc579d
commit 0506fa42a7
  1. 9
      Controllers/CollaborateursApi.cs
  2. 2
      IServices/ICollaborateurService.cs
  3. 96
      Services/CollaborateurService.cs

@ -130,7 +130,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs")] [Route("/api/collaborateurs")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurs")] [SwaggerOperation("GetCollaborateurs")]
[SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), 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<string> fonctions, [FromQuery]int? idAgence, [FromQuery]int? idBU, [FromQuery]string texte, [FromQuery]string tri) 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(..), ... //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>)); 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(..), ... //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)); // 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} ]"; 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 var example = exampleJson != null
? JsonConvert.DeserializeObject<List<CollaborateurDTO>>(exampleJson) ? JsonConvert.DeserializeObject<List<CollaborateurDTO>>(exampleJson)
: default(List<CollaborateurDTO>); //TODO: Change the data returned : default(List<CollaborateurDTO>); //TODO: Change the data returned
return new ObjectResult(example); return new ObjectResult(example);*/
} }
/// <summary> /// <summary>

@ -16,8 +16,10 @@ namespace EPAServeur.IServices
List<CollaborateurDTO> GetCollaborateurs(); List<CollaborateurDTO> GetCollaborateurs();
List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idRefent); List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idRefent);
//Object to DTO
CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur); CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur);
BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit); BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit);
AgenceDTO GetAgenceDTO(Agence agence);
ReferentDTO GetReferentDTO(Collaborateur referent); ReferentDTO GetReferentDTO(Collaborateur referent);
} }
} }

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace EPAServeur.Services namespace EPAServeur.Services
@ -20,64 +21,81 @@ namespace EPAServeur.Services
collaborateurApi = _collaborateurApi; collaborateurApi = _collaborateurApi;
} }
public CollaborateurDTO GetCollaborateurById(Guid? id) //
public AgenceDTO GetAgenceDTO(Agence agence)
{ {
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id); if (agence == null)
if (collaborateur == null)
return null; return null;
CollaborateurDTO collaborateurDTO = new CollaborateurDTO() AgenceDTO agenceDTO = new AgenceDTO()
{ {
Id = collaborateur.Id, Id = agence.Id,
Prenom = collaborateur.Prenom, Nom = agence.Nom,
Nom = collaborateur.Nom, Bu = new List<BusinessUnitDTO>()
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee,
}; };
collaborateurDTO.BusinessUnit = new BusinessUnitDTO() foreach(BU bu in agence.Bus)
{ {
Id = collaborateur.BusinessUnit.Id, agenceDTO.Bu.Add(new BusinessUnitDTO()
Nom = collaborateur.BusinessUnit.Nom,
Agence = new AgenceDTO()
{ {
Id = collaborateur.BusinessUnit.Agence.Id, Id = bu.Id,
Nom = collaborateur.BusinessUnit.Agence.Nom Nom = bu.Nom
});
} }
}; return agenceDTO;
collaborateurDTO.Referent = new ReferentDTO() }
public BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit)
{ {
Id = collaborateur.Referent.Id, if (businessUnit == null)
Prenom = collaborateur.Referent.Prenom, return null;
Nom = collaborateur.Referent.Nom, BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO()
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) public CollaborateurDTO GetCollaborateurByMail(string mail)
{ {
Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail); Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail);
if (collaborateur == null)
return null;
return GetCollaborateurDTO(collaborateur);
}
public CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur)
{
CollaborateurDTO collaborateurDTO = new CollaborateurDTO() CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
{ {
Id = collaborateur.Id, Id = collaborateur.Id,
Prenom = collaborateur.Prenom, Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom, Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside, MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee DateArrivee = collaborateur.DateArrivee,
};
collaborateurDTO.Referent = new ReferentDTO()
{
Id = collaborateur.Referent.Id,
Prenom = collaborateur.Referent.Prenom,
Nom = collaborateur.Referent.Nom,
MailApside = collaborateur.Referent.MailApside
}; };
collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit);
collaborateurDTO.Referent = GetReferentDTO(collaborateur.Referent);
return collaborateurDTO; return collaborateurDTO;
} }
public List<CollaborateurDTO> GetCollaborateurs() public List<CollaborateurDTO> GetCollaborateurs()
{ {
throw new NotImplementedException(); 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();
return collaborateursDTO;
} }
public List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent) public List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent)
@ -108,5 +126,19 @@ namespace EPAServeur.Services
{ {
throw new NotImplementedException(); 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;
}
} }
} }

Loading…
Cancel
Save