Ajout du service ICollaborateur et possibilité de récupérer un collaborateur via json-serveur et l'API du service collaborateur

master
Yanaël GRETTE 4 years ago
parent 3f7aea1062
commit 96c3cc579d
  1. 6
      ApiCollaborateur/CollaborateurApi.cs
  2. 11
      ClientCollaborateur/ApiClient.cs
  3. 4
      ClientCollaborateur/Configuration.cs
  4. 29
      Controllers/CollaborateursApi.cs
  5. 23
      IServices/ICollaborateurService.cs
  6. 2
      Properties/launchSettings.json
  7. 112
      Services/CollaborateurService.cs
  8. 16
      Startup.cs

@ -1187,7 +1187,9 @@ namespace IO.Swagger.ApiCollaborateur
public Collaborateur ChercherCollabId (Guid? collabId) public Collaborateur ChercherCollabId (Guid? collabId)
{ {
ApiResponse<Collaborateur> localVarResponse = ChercherCollabIdWithHttpInfo(collabId); ApiResponse<Collaborateur> localVarResponse = ChercherCollabIdWithHttpInfo(collabId);
return localVarResponse.Data; if(localVarResponse != null)
return localVarResponse.Data;
return null;
} }
/// <summary> /// <summary>
@ -1235,7 +1237,7 @@ namespace IO.Swagger.ApiCollaborateur
if (ExceptionFactory != null) if (ExceptionFactory != null)
{ {
Exception exception = ExceptionFactory("ChercherCollabId", localVarResponse); Exception exception = ExceptionFactory("ChercherCollabId", localVarResponse);
if (exception != null) throw exception; if (exception != null) return null;
} }
return new ApiResponse<Collaborateur>(localVarStatusCode, return new ApiResponse<Collaborateur>(localVarStatusCode,

@ -29,7 +29,8 @@ namespace IO.Swagger.ClientCollaborateur
{ {
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{ {
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
DateFormatString = "yyyy/MM/dd"
}; };
/// <summary> /// <summary>
@ -72,7 +73,7 @@ namespace IO.Swagger.ClientCollaborateur
/// with default configuration. /// with default configuration.
/// </summary> /// </summary>
/// <param name="basePath">The base path.</param> /// <param name="basePath">The base path.</param>
public ApiClient(String basePath = "https://localhost:3000") public ApiClient(String basePath = "http://localhost:3000/api")
{ {
if (String.IsNullOrEmpty(basePath)) if (String.IsNullOrEmpty(basePath))
throw new ArgumentException("basePath cannot be empty"); throw new ArgumentException("basePath cannot be empty");
@ -314,7 +315,11 @@ namespace IO.Swagger.ClientCollaborateur
{ {
return ConvertType(response.Content, type); return ConvertType(response.Content, type);
} }
Console.WriteLine(response.Content);
Console.WriteLine("JFPEIOZJEZPIOFJENPOI");
Console.WriteLine(type.Name);
Console.WriteLine("18616840684");
Console.WriteLine(response.Content);
// at this point, it must be a model (json) // at this point, it must be a model (json)
try try
{ {

@ -114,7 +114,7 @@ namespace IO.Swagger.ClientCollaborateur
public Configuration() public Configuration()
{ {
UserAgent = "Swagger-Codegen/1.0.0/csharp"; UserAgent = "Swagger-Codegen/1.0.0/csharp";
BasePath = "https://localhost:3000"; BasePath = "http://localhost:3000/api";
DefaultHeader = new ConcurrentDictionary<string, string>(); DefaultHeader = new ConcurrentDictionary<string, string>();
ApiKey = new ConcurrentDictionary<string, string>(); ApiKey = new ConcurrentDictionary<string, string>();
ApiKeyPrefix = new ConcurrentDictionary<string, string>(); ApiKeyPrefix = new ConcurrentDictionary<string, string>();
@ -129,7 +129,7 @@ namespace IO.Swagger.ClientCollaborateur
IDictionary<string, string> defaultHeader, IDictionary<string, string> defaultHeader,
IDictionary<string, string> apiKey, IDictionary<string, string> apiKey,
IDictionary<string, string> apiKeyPrefix, IDictionary<string, string> apiKeyPrefix,
string basePath = "https://virtserver.swaggerhub.com/LilianG/Service-Collaborateur/1.1.1") : this() string basePath = "http://localhost:3000/api") : this()
{ {
if (string.IsNullOrWhiteSpace(basePath)) if (string.IsNullOrWhiteSpace(basePath))
throw new ArgumentException("The provided basePath is invalid.", "basePath"); throw new ArgumentException("The provided basePath is invalid.", "basePath");

@ -18,6 +18,7 @@ using IO.Swagger.Attributes;
using IO.Swagger.Security; using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using EPAServeur.IServices;
namespace IO.Swagger.Controllers namespace IO.Swagger.Controllers
{ {
@ -27,6 +28,11 @@ namespace IO.Swagger.Controllers
[ApiController] [ApiController]
public class CollaborateursApiController : ControllerBase public class CollaborateursApiController : ControllerBase
{ {
private readonly ICollaborateurService collaborateurService;
public CollaborateursApiController(ICollaborateurService _collaborateurService)
{
collaborateurService = _collaborateurService;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -37,7 +43,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/{idCollaborateur}")] [Route("/api/collaborateurs/{idCollaborateur}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurById")] [SwaggerOperation("GetCollaborateurById")]
[SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(CollaborateurDTO), description: "OK")]
@ -47,19 +53,30 @@ namespace IO.Swagger.Controllers
{ {
//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(CollaborateurDTO)); // return StatusCode(200, default(CollaborateurDTO));
Console.WriteLine("COUCOU");
CollaborateurDTO collaborateurDTO = collaborateurService.GetCollaborateurById(idCollaborateur);
if( collaborateurDTO == null)
{
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "404",
Message = "Le collaborateur n'existe pas",
};
return StatusCode(404, erreurDTO);
}
return StatusCode(200, collaborateurDTO);
//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));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //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)); // return StatusCode(404, 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}"; 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 var example = exampleJson != null
? JsonConvert.DeserializeObject<CollaborateurDTO>(exampleJson) ? JsonConvert.DeserializeObject<CollaborateurDTO>(exampleJson)
: default(CollaborateurDTO); //TODO: Change the data returned : default(CollaborateurDTO); //TODO: Change the data returned
return new ObjectResult(example); return new ObjectResult(example);*/
} }
/// <summary> /// <summary>
@ -71,7 +88,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/{mail}")] [Route("/api/collaborateurs/mail/{mail}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetCollaborateurByMail")] [SwaggerOperation("GetCollaborateurByMail")]
@ -183,7 +200,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
/// <response code="404">Ressource n&#x27;a pas été trouvée</response> /// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet] [HttpGet]
[Route("/api/collaborateurs/{mail}/profil")] [Route("/api/collaborateurs/profil/{mail}/")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetProfilCollaborateurByMail")] [SwaggerOperation("GetProfilCollaborateurByMail")]

@ -0,0 +1,23 @@
using EPAServeur.Context;
using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.IServices
{
public interface ICollaborateurService
{
CollaborateurDTO GetCollaborateurById(Guid? id);
CollaborateurDTO GetCollaborateurByMail(string mail);
ProfilDTO GetProfilByMail(string mail);
List<CollaborateurDTO> GetCollaborateurs();
List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idRefent);
CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur);
BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit);
ReferentDTO GetReferentDTO(Collaborateur referent);
}
}

@ -12,7 +12,7 @@
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "api/collaborateurs", "launchUrl": "api/collaborateurs/59a8becb-bc0a-4d3d-adb1-8a8bd13c48c9",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

@ -0,0 +1,112 @@
using EPAServeur.Context;
using EPAServeur.IServices;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services
{
public class CollaborateurService : ICollaborateurService
{
private readonly ICollaborateurApi collaborateurApi;
public CollaborateurService(ICollaborateurApi _collaborateurApi)
{
collaborateurApi = _collaborateurApi;
}
public CollaborateurDTO GetCollaborateurById(Guid? id)
{
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id);
if (collaborateur == null)
return null;
CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
{
Id = collaborateur.Id,
Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee,
};
collaborateurDTO.BusinessUnit = new BusinessUnitDTO()
{
Id = collaborateur.BusinessUnit.Id,
Nom = collaborateur.BusinessUnit.Nom,
Agence = new AgenceDTO()
{
Id = collaborateur.BusinessUnit.Agence.Id,
Nom = collaborateur.BusinessUnit.Agence.Nom
}
};
collaborateurDTO.Referent = new ReferentDTO()
{
Id = collaborateur.Referent.Id,
Prenom = collaborateur.Referent.Prenom,
Nom = collaborateur.Referent.Nom,
MailApside = collaborateur.Referent.MailApside
};
return collaborateurDTO;
}
public CollaborateurDTO GetCollaborateurByMail(string mail)
{
Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail);
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
};
return collaborateurDTO;
}
public List<CollaborateurDTO> GetCollaborateurs()
{
throw new NotImplementedException();
}
public List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent)
{
/*
Collaborateur collaborateur = collaborateurApi.ChercherCollabRef(idReferent);
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
};
return collaborateurDTO;
*/
throw new NotImplementedException();
}
public ProfilDTO GetProfilByMail(string mail)
{
throw new NotImplementedException();
}
}
}

@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using EPAServeur.Context; using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.Security; using IO.Swagger.Security;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -28,10 +31,11 @@ namespace EPAServeur
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
//SetupDatabase(); Console.WriteLine("SERVICES");
services.AddControllers(); services.AddControllers();
services.AddAuthentication(BearerAuthenticationHandler.SchemeName) services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
.AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null); .AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null);
services.AddDbContext<EpContext>(); services.AddDbContext<EpContext>();
using(var context = new EpContext()) using(var context = new EpContext())
{ {
@ -41,8 +45,16 @@ namespace EPAServeur
context.AjoutInformationsDeBase(); context.AjoutInformationsDeBase();
context.AjoutChamps(); context.AjoutChamps();
} }
//ensurecreated HERE
//faire using, check si kekchoz exkist puis appeler les méthodes de création si il n'y a rien //faire using, check si kekchoz exkist puis appeler les méthodes de création si il n'y a rien
//API Collaborateurs
services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<IAgenceApi, AgenceApi>();
services.AddScoped<IRfrentApi, RfrentApi>();
//Services
services.AddScoped<ICollaborateurService, CollaborateurService>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Loading…
Cancel
Save