Récupération des notes d'un auteur, par collaborateur et d'une note par id

develop
Yanaël GRETTE 4 years ago
parent f01fa3099f
commit 4e78c28d10
  1. 40
      Context/EpContext.cs
  2. 116
      Controllers/NotesApi.cs
  3. 9
      IServices/INoteService.cs
  4. 2
      Properties/launchSettings.json
  5. 63
      Services/NoteService.cs
  6. 3
      Startup.cs

@ -829,8 +829,8 @@ namespace EPAServeur.Context
Id = 1, Id = 1,
Titre = "Titre1", Titre = "Titre1",
Texte = "Texte1", Texte = "Texte1",
IdAuteur = "ecf528c3-e509-402f-87bb-c8821467e350", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = "779bf1cf-4d38-48fb-8550-3d583384523b", IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -841,8 +841,8 @@ namespace EPAServeur.Context
Id = 2, Id = 2,
Titre = "Titre2", Titre = "Titre2",
Texte = "Texte2", Texte = "Texte2",
IdAuteur = "ecf528c3-e509-402f-87bb-c8821467e350", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = "779bf1cf-4d38-48fb-8550-3d583384523b", IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -853,8 +853,8 @@ namespace EPAServeur.Context
Id = 3, Id = 3,
Titre = "Titre3", Titre = "Titre3",
Texte = "Texte3", Texte = "Texte3",
IdAuteur = "ecf528c3-e509-402f-87bb-c8821467e350", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = "779bf1cf-4d38-48fb-8550-3d583384523b", IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -865,8 +865,8 @@ namespace EPAServeur.Context
Id = 4, Id = 4,
Titre = "Titre4", Titre = "Titre4",
Texte = "Texte4", Texte = "Texte4",
IdAuteur = "ecf528c3-e509-402f-87bb-c8821467e350", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -877,8 +877,8 @@ namespace EPAServeur.Context
Id = 5, Id = 5,
Titre = "Titre5", Titre = "Titre5",
Texte = "Texte5", Texte = "Texte5",
IdAuteur = "ecf528c3-e509-402f-87bb-c8821467e350", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -889,8 +889,8 @@ namespace EPAServeur.Context
Id = 6, Id = 6,
Titre = "Titre6", Titre = "Titre6",
Texte = "Texte6", Texte = "Texte6",
IdAuteur = "6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb", IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -901,8 +901,8 @@ namespace EPAServeur.Context
Id = 7, Id = 7,
Titre = "Titre7", Titre = "Titre7",
Texte = "Texte7", Texte = "Texte7",
IdAuteur = "6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb", IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -914,8 +914,8 @@ namespace EPAServeur.Context
Id = 8, Id = 8,
Titre = "Titre8", Titre = "Titre8",
Texte = "Texte8", Texte = "Texte8",
IdAuteur = "571463f3-b286-4a21-9eab-0707dc506dec", IdAuteur = new Guid("571463f3-b286-4a21-9eab-0707dc506dec"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -926,8 +926,8 @@ namespace EPAServeur.Context
Id = 9, Id = 9,
Titre = "Titre9", Titre = "Titre9",
Texte = "Texte9", Texte = "Texte9",
IdAuteur = "571463f3-b286-4a21-9eab-0707dc506dec", IdAuteur = new Guid("571463f3-b286-4a21-9eab-0707dc506dec"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now
@ -938,8 +938,8 @@ namespace EPAServeur.Context
Id = 10, Id = 10,
Titre = "Titre10", Titre = "Titre10",
Texte = "Texte10", Texte = "Texte10",
IdAuteur = "6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb", IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"),
IdCollaborateur = "006226f6-51b2-4a02-a302-7447f7fccc04", IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"),
DateCreation = DateTime.Now, DateCreation = DateTime.Now,
DateUpdate = DateTime.Now DateUpdate = DateTime.Now

@ -3,7 +3,7 @@
* *
* API qui sra utilisée afin de faire communiquer le client et le serveur ainsi que le serveur et la boîte noire. * API qui sra utilisée afin de faire communiquer le client et le serveur ainsi que le serveur et la boîte noire.
* *
* OpenAPI spec version: 1.3.2 * OpenAPI spec version: 1.3.3
* *
* Generated by: https://github.com/swagger-api/swagger-codegen.git * Generated by: https://github.com/swagger-api/swagger-codegen.git
*/ */
@ -18,6 +18,8 @@ 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.Services;
using EPAServeur.IServices;
namespace IO.Swagger.Controllers namespace IO.Swagger.Controllers
{ {
@ -27,6 +29,13 @@ namespace IO.Swagger.Controllers
[ApiController] [ApiController]
public class NotesApiController : ControllerBase public class NotesApiController : ControllerBase
{ {
private readonly INoteService noteService;
public NotesApiController(INoteService _noteService)
{
noteService = _noteService;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -37,7 +46,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>
[HttpDelete] [HttpDelete]
[Route("/api/notes/{idNote}/supprimer")] [Route("/api/notes/{idNote}/supprimer")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("DeleteNote")] [SwaggerOperation("DeleteNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
@ -66,7 +75,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/notes/{idNote}")] [Route("/api/notes/{idNote}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetNoteById")] [SwaggerOperation("GetNoteById")]
[SwaggerResponse(statusCode: 200, type: typeof(DetailsNoteDTO), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(DetailsNoteDTO), description: "OK")]
@ -74,27 +83,30 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNoteById([FromRoute][Required]int? idNote) public virtual IActionResult GetNoteById([FromRoute][Required]int? idNote)
{ {
//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(DetailsNoteDTO));
//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));
DetailsNoteDTO note = noteService.GetNoteById(idNote);
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... if(note == null)
// return StatusCode(404, default(ErreurDTO)); {
string exampleJson = null; ErreurDTO erreur = new ErreurDTO()
exampleJson = "{\n \"idAuteur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"texte\" : \"texte\",\n \"id\" : 0,\n \"collaborateur\" : {\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 \"referent\" : {\n \"mailApside\" : \"\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\",\n \"collaborateurs\" : [ null, null ]\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}"; {
Code = "404",
var example = exampleJson != null Message = "Aucune note n'a été trouvée"
? JsonConvert.DeserializeObject<DetailsNoteDTO>(exampleJson) };
: default(DetailsNoteDTO); //TODO: Change the data returned return NotFound(erreur);
return new ObjectResult(example); }
return Ok(note);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <remarks>Récupérer toutes les notes</remarks> /// <remarks>Récupérer toutes les notes</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
/// <param name="parPAge">Nombre d&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <response code="200">OK</response> /// <response code="200">OK</response>
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
[HttpGet] [HttpGet]
@ -104,7 +116,7 @@ namespace IO.Swagger.Controllers
[SwaggerOperation("GetNotes")] [SwaggerOperation("GetNotes")]
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetNotes() public virtual IActionResult GetNotes([FromQuery][Required()]bool? asc, [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(..), ... //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<AffichageNoteDTO>)); // return StatusCode(200, default(List<AffichageNoteDTO>));
@ -124,71 +136,77 @@ namespace IO.Swagger.Controllers
/// ///
/// </summary> /// </summary>
/// <remarks>Récupérer les notes d&#x27;une personne a écrite</remarks> /// <remarks>Récupérer les notes d&#x27;une personne a écrite</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
/// <param name="idReferent">id referent</param> /// <param name="idReferent">id referent</param>
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
/// <param name="parPAge">Nombre d&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <response code="200">OK</response> /// <response code="200">OK</response>
/// <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/notes/auteur/{idReferent}")] [Route("/api/notes/auteur/{idReferent}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetNotesByAuteur")] [SwaggerOperation("GetNotesByAuteur")]
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNotesByAuteur([FromRoute][Required]Guid? idReferent) public virtual IActionResult GetNotesByAuteur([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<AffichageNoteDTO>));
//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));
IEnumerable<AffichageNoteDTO> notes = noteService.GetNotesByAuteur(idReferent, asc, numPage, parPAge, texte, tri);
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... if(notes == null)
// return StatusCode(404, default(ErreurDTO)); {
string exampleJson = null; ErreurDTO erreur = new ErreurDTO()
exampleJson = "[ {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n}, {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n} ]"; {
Code = "404",
var example = exampleJson != null Message = "Aucun id ne correspond au référent"
? JsonConvert.DeserializeObject<List<AffichageNoteDTO>>(exampleJson) };
: default(List<AffichageNoteDTO>); //TODO: Change the data returned return NotFound(erreur);
return new ObjectResult(example); }
return Ok(notes);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <remarks>Récupérer une note par son id</remarks> /// <remarks>Récupérer une note par son id</remarks>
/// <param name="asc">Préciser si les données sont dans l&#x27;ordre (true) ou dans l&#x27;ordre inverse (false)</param>
/// <param name="idCollaborateur">id collaborateur</param> /// <param name="idCollaborateur">id collaborateur</param>
/// <param name="idReferent">id referent</param> /// <param name="idReferent">id referent</param>
/// <param name="numPage">Numéro de la page du tableau qui affiche les données</param>
/// <param name="parPAge">Nombre d&#x27;éléments affiché sur chaque page du tableau</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <response code="200">OK</response> /// <response code="200">OK</response>
/// <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/notes/auteur/{idReferent}/collaborateur/{idCollaborateur}")] [Route("/api/notes/auteur/{idReferent}/collaborateur/{idCollaborateur}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("GetNotesByCollaborateur")] [SwaggerOperation("GetNotesByCollaborateur")]
[SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")] [SwaggerResponse(statusCode: 200, type: typeof(List<AffichageNoteDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetNotesByCollaborateur([FromRoute][Required]Guid? idCollaborateur, [FromRoute][Required]Guid? idReferent) public virtual IActionResult GetNotesByCollaborateur([FromQuery][Required()]bool? asc, [FromRoute][Required]Guid? idCollaborateur, [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<AffichageNoteDTO>));
//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));
IEnumerable<AffichageNoteDTO> notes = noteService.GetNotesByCollaborateur(idReferent, idCollaborateur, asc, numPage, parPAge, texte, tri);
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... if (notes == null)
// return StatusCode(404, default(ErreurDTO)); {
string exampleJson = null; ErreurDTO erreur = new ErreurDTO()
exampleJson = "[ {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n}, {\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateMiseAjour\" : \"2000-01-23T04:56:07.000+00:00\",\n \"titre\" : \"titre\",\n \"id\" : 0,\n \"collaborateur\" : \"collaborateur\"\n} ]"; {
Code = "404",
var example = exampleJson != null Message = "Aucun id ne correspond au référent et/ou au collaborateur"
? JsonConvert.DeserializeObject<List<AffichageNoteDTO>>(exampleJson) };
: default(List<AffichageNoteDTO>); //TODO: Change the data returned return NotFound(erreur);
return new ObjectResult(example); }
return Ok(notes);
} }
/// <summary> /// <summary>
@ -200,7 +218,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
[HttpPost] [HttpPost]
[Route("/api/notes/nouvellenote")] [Route("/api/notes/nouvellenote")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("NouvelleNote")] [SwaggerOperation("NouvelleNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
@ -226,7 +244,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response> /// <response code="403">Acces interdit</response>
[HttpPut] [HttpPut]
[Route("/api/notes/{idNote}/updateNote")] [Route("/api/notes/{idNote}/updateNote")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("UpdateNote")] [SwaggerOperation("UpdateNote")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]

@ -7,12 +7,13 @@ using System.Threading.Tasks;
namespace EPAServeur.IServices namespace EPAServeur.IServices
{ {
interface INoteService public interface INoteService
{ {
public List<AffichageNoteDTO> GetNotes(); //bool? asc, int? numPage, int? parPAge, string texte, string tri)
public List<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur); public IEnumerable<AffichageNoteDTO> GetNotes(bool? asc, int? numPage, int? parPAge, string texte, string tri);
public IEnumerable<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur, bool? asc, int? numPage, int? parPAge, string texte, string tri);
public DetailsNoteDTO GetNoteById(int? idNote); public DetailsNoteDTO GetNoteById(int? idNote);
public List<AffichageNoteDTO> GetNotByCollaborateur(Guid? idAuteur, Guid? idCollaborateur); public IEnumerable<AffichageNoteDTO> GetNotesByCollaborateur(Guid? idAuteur, Guid? idCollaborateur, bool? asc, int? numPage, int? parPAge, string texte, string tri);
public bool AjouterNote(DetailsNoteDTO nouvelleNote); public bool AjouterNote(DetailsNoteDTO nouvelleNote);
public bool SupprimerNote(int? idNote); public bool SupprimerNote(int? idNote);
public void UpdateNote(int? idNote, DetailsNoteDTO note); public void UpdateNote(int? idNote, DetailsNoteDTO note);

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

@ -5,6 +5,7 @@ using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur; using IO.Swagger.ModelCollaborateur;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,10 +13,10 @@ namespace EPAServeur.Services
{ {
public class NoteService : INoteService public class NoteService : INoteService
{ {
private readonly CollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
private readonly EpContext context; private readonly EpContext context;
public NoteService(CollaborateurService _collaborateurService, EpContext _context) public NoteService(ICollaborateurService _collaborateurService, EpContext _context)
{ {
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
context = _context; context = _context;
@ -26,24 +27,63 @@ namespace EPAServeur.Services
throw new NotImplementedException(); throw new NotImplementedException();
} }
public List<AffichageNoteDTO> GetNotByCollaborateur(Guid? idAuteur, Guid? idCollaborateur) public IEnumerable<AffichageNoteDTO> GetNotesByCollaborateur(Guid? idAuteur, Guid? idCollaborateur, bool? asc, int? numPage, int? parPage, string texte, string tri)
{ {
throw new NotImplementedException(); if (collaborateurService.GetProfilById(idAuteur) == null || collaborateurService.GetProfilById(idCollaborateur) == null)
return null;
if (texte == null)
texte = "";
else
texte = texte.ToLower();
int skip = (numPage.Value - 1) * parPage.Value;
int take = parPage.Value;
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = (from n in context.Note
where n.IdAuteur == idAuteur && n.IdCollaborateur == idCollaborateur
select NoteToAffichageDTO(n, collaborateurService));
AffichageNoteDTO = (from a in AffichageNoteDTO
where a.Collaborateur.ToLower().Contains(texte) || a.Titre.ToLower().Contains(texte)
select a).Skip(skip).Take(take);
return AffichageNoteDTO;
} }
public DetailsNoteDTO GetNoteById(int? idNote) public DetailsNoteDTO GetNoteById(int? idNote)
{ {
throw new NotImplementedException(); DetailsNoteDTO details = NoteToDetailSDTO(context.Note.Where(c => c.Id == idNote).FirstOrDefault());
return details;
/*return (from n in context.Note
where n.Id == idNote
select NoteToDetailSDTO(n)).ToList().FirstOrDefault();*/
} }
public List<AffichageNoteDTO> GetNotes() public IEnumerable<AffichageNoteDTO> GetNotes(bool? asc, int? numPage, int? parPage, string texte, string tri)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public List<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur) public IEnumerable<AffichageNoteDTO> GetNotesByAuteur(Guid? idAuteur, bool? asc, int? numPage, int? parPage, string texte, string tri)
{ {
throw new NotImplementedException(); if (collaborateurService.GetCollaborateurById(idAuteur) == null)
return null;
if (texte == null)
texte = "";
else
texte = texte.ToLower();
int skip = (numPage.Value - 1) * parPage.Value;
int take = parPage.Value;
//Stopwatch stopwatch = new Stopwatch();
//stopwatch.Start();
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = (from n in context.Note
where n.IdAuteur == idAuteur
select NoteToAffichageDTO(n, collaborateurService));
//stopwatch.Stop();
//Console.WriteLine("Durée d'exécution numéro 1: {0}", stopwatch.Elapsed.TotalSeconds);
//stopwatch.Restart();
AffichageNoteDTO = (from a in AffichageNoteDTO
where a.Collaborateur.ToLower().Contains(texte) || a.Titre.ToLower().Contains(texte)
select a).Skip(skip).Take(take);
//stopwatch.Stop();
//Console.WriteLine("Durée d'exécution numéro 2: {0}", stopwatch.Elapsed.TotalSeconds);
return AffichageNoteDTO;
} }
public bool SupprimerNote(int? idNote) public bool SupprimerNote(int? idNote)
@ -57,12 +97,13 @@ namespace EPAServeur.Services
} }
//Object to DTO //Object to DTO
private AffichageNoteDTO NoteToAffichageDTO(Note note) private static AffichageNoteDTO NoteToAffichageDTO(Note note, ICollaborateurService collaborateurService)
{ {
CollaborateurDTO collaborateur = collaborateurService.GetCollaborateurById(note.IdCollaborateur); CollaborateurDTO collaborateur = collaborateurService.GetCollaborateurById(note.IdCollaborateur);
AffichageNoteDTO affichage = new AffichageNoteDTO() AffichageNoteDTO affichage = new AffichageNoteDTO()
{ {
Id = note.Id, Id = note.Id,
IdCollaborateur = note.IdCollaborateur,
Collaborateur = collaborateur.Prenom + collaborateur.Nom, Collaborateur = collaborateur.Prenom + collaborateur.Nom,
Titre = note.Titre, Titre = note.Titre,
DateMiseAjour = note.DateUpdate DateMiseAjour = note.DateUpdate

@ -52,8 +52,11 @@ namespace EPAServeur
services.AddScoped<IAgenceApi, AgenceApi>(); services.AddScoped<IAgenceApi, AgenceApi>();
services.AddScoped<IRfrentApi, RfrentApi>(); services.AddScoped<IRfrentApi, RfrentApi>();
//Services //Services
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<INoteService, NoteService>();
} }

Loading…
Cancel
Save