Implémenation de l'API des Ep pour la récupération des EP en cours et des EP signés

develop
Yanaël GRETTE 4 years ago
parent d48884349f
commit e362dc75df
  1. 5
      EPAServeur.Tests/Controllers/EpInformationApiTests.cs
  2. 143
      EPAServeur/Controllers/EpApi.cs

@ -65,6 +65,7 @@ namespace EPAServeur.Tests.Controllers
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value); Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
} }
[Test]
public async Task GetEpEnCoursCount() public async Task GetEpEnCoursCount()
{ {
EpApiController epApiController = new EpApiController(epInformationService, logger); EpApiController epApiController = new EpApiController(epInformationService, logger);
@ -74,7 +75,7 @@ namespace EPAServeur.Tests.Controllers
Assert.IsInstanceOf<int>(result.Value); Assert.IsInstanceOf<int>(result.Value);
} }
[Test]
public async Task GetEpEnSignes() public async Task GetEpEnSignes()
{ {
EpApiController epApiController = new EpApiController(epInformationService, logger); EpApiController epApiController = new EpApiController(epInformationService, logger);
@ -84,6 +85,8 @@ namespace EPAServeur.Tests.Controllers
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value); Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
} }
[Test]
public async Task GetEpEnSignesCount() public async Task GetEpEnSignesCount()
{ {
EpApiController epApiController = new EpApiController(epInformationService, logger); EpApiController epApiController = new EpApiController(epInformationService, logger);

@ -21,6 +21,7 @@ using IO.Swagger.DTO;
using EPAServeur.IServices; using EPAServeur.IServices;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace IO.Swagger.Controllers namespace IO.Swagger.Controllers
{ {
@ -188,7 +189,33 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")] [SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual async Task<IActionResult> GetEPEnCours([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin) public virtual async Task<IActionResult> GetEPEnCours([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin)
{ {
IEnumerable<EpInformationDTO> epEnCours;
try
{
epEnCours = await epInformationService.GetEPEnCours(idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
catch (Exception e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur inconnue est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
return Ok(epEnCours);
//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<EpInformationDTO>)); // return StatusCode(200, default(List<EpInformationDTO>));
@ -200,13 +227,6 @@ namespace IO.Swagger.Controllers
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO)); // return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n}, {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<EpInformationDTO>>(exampleJson)
: default(List<EpInformationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
} }
/// <summary> /// <summary>
@ -325,7 +345,33 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")] [SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual async Task<IActionResult> GetEPEnCoursCount([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin) public virtual async Task<IActionResult> GetEPEnCoursCount([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin)
{ {
int nbEpEnCours = 0;
try
{
nbEpEnCours = await epInformationService.GetEPEnCoursCount(idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
catch (Exception e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur inconnue est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
return Ok(nbEpEnCours);
//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(long?)); // return StatusCode(200, default(long?));
@ -337,13 +383,6 @@ namespace IO.Swagger.Controllers
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO)); // return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "0";
var example = exampleJson != null
? JsonConvert.DeserializeObject<long?>(exampleJson)
: default(long?); //TODO: Change the data returned
return new ObjectResult(example);
} }
/// <summary> /// <summary>
@ -568,7 +607,33 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")] [SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual async Task<IActionResult> GetEPSignes([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin) public virtual async Task<IActionResult> GetEPSignes([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin)
{ {
IEnumerable<EpInformationDTO> epSignes;
try
{
epSignes = await epInformationService.GetEPSignes(idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
catch (Exception e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur inconnue est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
return Ok(epSignes);
//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<EpInformationDTO>)); // return StatusCode(200, default(List<EpInformationDTO>));
@ -580,13 +645,6 @@ namespace IO.Swagger.Controllers
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO)); // return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n}, {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<EpInformationDTO>>(exampleJson)
: default(List<EpInformationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
} }
/// <summary> /// <summary>
@ -660,7 +718,33 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")] [SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual async Task<IActionResult> GetEPSignesCount([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin) public virtual async Task<IActionResult> GetEPSignesCount([FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri, [FromQuery]DateTime? dateDebut, [FromQuery]DateTime? dateFin)
{ {
int nbEpSignes;
try
{
nbEpSignes = await epInformationService.GetEPSignesCount(idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
catch (Exception e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = 500,
Message = "Une erreur inconnue est survenue sur le serveur",
};
return StatusCode(erreur.Code.Value, erreur);
}
return Ok(nbEpSignes);
//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(long?)); // return StatusCode(200, default(long?));
@ -671,14 +755,7 @@ namespace IO.Swagger.Controllers
// return StatusCode(403, default(ErreurDTO)); // return StatusCode(403, default(ErreurDTO));
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ... //TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO)); // return StatusCode(500, default(ErreurDTO)); //TODO: Change the data returned
string exampleJson = null;
exampleJson = "0";
var example = exampleJson != null
? JsonConvert.DeserializeObject<long?>(exampleJson)
: default(long?); //TODO: Change the data returned
return new ObjectResult(example);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save