diff --git a/ApiCollaborateur/CollaborateurApi.cs b/ApiCollaborateur/CollaborateurApi.cs index 3deb419..4a172a3 100644 --- a/ApiCollaborateur/CollaborateurApi.cs +++ b/ApiCollaborateur/CollaborateurApi.cs @@ -1187,7 +1187,9 @@ namespace IO.Swagger.ApiCollaborateur public Collaborateur ChercherCollabId (Guid? collabId) { ApiResponse localVarResponse = ChercherCollabIdWithHttpInfo(collabId); - return localVarResponse.Data; + if(localVarResponse != null) + return localVarResponse.Data; + return null; } /// @@ -1235,7 +1237,7 @@ namespace IO.Swagger.ApiCollaborateur if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ChercherCollabId", localVarResponse); - if (exception != null) throw exception; + if (exception != null) return null; } return new ApiResponse(localVarStatusCode, diff --git a/ClientCollaborateur/ApiClient.cs b/ClientCollaborateur/ApiClient.cs index a8ac5d8..f4a048f 100644 --- a/ClientCollaborateur/ApiClient.cs +++ b/ClientCollaborateur/ApiClient.cs @@ -29,7 +29,8 @@ namespace IO.Swagger.ClientCollaborateur { private JsonSerializerSettings serializerSettings = new JsonSerializerSettings { - ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor + ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, + DateFormatString = "yyyy/MM/dd" }; /// @@ -72,7 +73,7 @@ namespace IO.Swagger.ClientCollaborateur /// with default configuration. /// /// The base path. - public ApiClient(String basePath = "https://localhost:3000") + public ApiClient(String basePath = "http://localhost:3000/api") { if (String.IsNullOrEmpty(basePath)) throw new ArgumentException("basePath cannot be empty"); @@ -314,7 +315,11 @@ namespace IO.Swagger.ClientCollaborateur { 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) try { diff --git a/ClientCollaborateur/Configuration.cs b/ClientCollaborateur/Configuration.cs index b07e7c8..2c725e2 100644 --- a/ClientCollaborateur/Configuration.cs +++ b/ClientCollaborateur/Configuration.cs @@ -114,7 +114,7 @@ namespace IO.Swagger.ClientCollaborateur public Configuration() { UserAgent = "Swagger-Codegen/1.0.0/csharp"; - BasePath = "https://localhost:3000"; + BasePath = "http://localhost:3000/api"; DefaultHeader = new ConcurrentDictionary(); ApiKey = new ConcurrentDictionary(); ApiKeyPrefix = new ConcurrentDictionary(); @@ -129,7 +129,7 @@ namespace IO.Swagger.ClientCollaborateur IDictionary defaultHeader, IDictionary apiKey, IDictionary 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)) throw new ArgumentException("The provided basePath is invalid.", "basePath"); diff --git a/Controllers/CollaborateursApi.cs b/Controllers/CollaborateursApi.cs index 12a594a..672b80e 100644 --- a/Controllers/CollaborateursApi.cs +++ b/Controllers/CollaborateursApi.cs @@ -18,6 +18,7 @@ using IO.Swagger.Attributes; using IO.Swagger.Security; using Microsoft.AspNetCore.Authorization; using IO.Swagger.DTO; +using EPAServeur.IServices; namespace IO.Swagger.Controllers { @@ -26,7 +27,12 @@ namespace IO.Swagger.Controllers /// [ApiController] public class CollaborateursApiController : ControllerBase - { + { + private readonly ICollaborateurService collaborateurService; + public CollaborateursApiController(ICollaborateurService _collaborateurService) + { + collaborateurService = _collaborateurService; + } /// /// /// @@ -37,29 +43,40 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/collaborateurs/{idCollaborateur}")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetCollaborateurById")] [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 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)); - + 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(..), ... // 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; + /*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); + return new ObjectResult(example);*/ } /// @@ -71,7 +88,7 @@ namespace IO.Swagger.Controllers /// Acces interdit /// Ressource n'a pas été trouvée [HttpGet] - [Route("/api/collaborateurs/{mail}")] + [Route("/api/collaborateurs/mail/{mail}")] [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetCollaborateurByMail")] @@ -183,7 +200,7 @@ namespace IO.Swagger.Controllers /// Acces interdit /// Ressource n'a pas été trouvée [HttpGet] - [Route("/api/collaborateurs/{mail}/profil")] + [Route("/api/collaborateurs/profil/{mail}/")] [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetProfilCollaborateurByMail")] diff --git a/IServices/ICollaborateurService.cs b/IServices/ICollaborateurService.cs new file mode 100644 index 0000000..117de68 --- /dev/null +++ b/IServices/ICollaborateurService.cs @@ -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 GetCollaborateurs(); + List GetCollaborateursByReferent(Guid? idRefent); + + CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur); + BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit); + ReferentDTO GetReferentDTO(Collaborateur referent); + } +} diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index ba3aba4..132903c 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -12,7 +12,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "api/collaborateurs", + "launchUrl": "api/collaborateurs/59a8becb-bc0a-4d3d-adb1-8a8bd13c48c9", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Services/CollaborateurService.cs b/Services/CollaborateurService.cs new file mode 100644 index 0000000..d6d8df0 --- /dev/null +++ b/Services/CollaborateurService.cs @@ -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 GetCollaborateurs() + { + throw new NotImplementedException(); + } + + public List 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(); + } + } +} diff --git a/Startup.cs b/Startup.cs index 175993f..96463b9 100644 --- a/Startup.cs +++ b/Startup.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using EPAServeur.Context; +using EPAServeur.IServices; +using EPAServeur.Services; +using IO.Swagger.ApiCollaborateur; using IO.Swagger.Security; using Microsoft.AspNetCore.Authentication; 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. public void ConfigureServices(IServiceCollection services) { - //SetupDatabase(); + Console.WriteLine("SERVICES"); services.AddControllers(); services.AddAuthentication(BearerAuthenticationHandler.SchemeName) .AddScheme(BearerAuthenticationHandler.SchemeName, null); + services.AddDbContext(); using(var context = new EpContext()) { @@ -41,8 +45,16 @@ namespace EPAServeur context.AjoutInformationsDeBase(); context.AjoutChamps(); } - //ensurecreated HERE //faire using, check si kekchoz exkist puis appeler les méthodes de création si il n'y a rien + + //API Collaborateurs + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + //Services + services.AddScoped(); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.