Ajout des bonnes routes des controller
continuous-integration/drone/push Build is passing Details

deploiement
Clement CHIEU 1 year ago
parent 037d3c5d7d
commit 3a6693646c

@ -1,13 +1,18 @@
using Asp.Versioning;
using Dto;
using Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model.OrderCriteria;
using Shared;
using Shared.Mapper;
namespace API.Controllers;
public class BlackListController(ILogger<UsersController> logger, IBlackListService<BlackListDto> blackListService) : ControllerBase
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class BlackListController(ILogger<UsersController> logger, IBlackListService<BlackListDto> blackListService)
: ControllerBase
{
[HttpGet("user/ban/{page:int}/{number:int}")]
[ProducesResponseType(typeof(IEnumerable<BlackListDto>), 200)]
@ -24,7 +29,7 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
logger.LogInformation("[INFORMATION] {nb} Email(s) banni(s) trouvé(s)", users.Count);
return Ok(users);
}
[HttpGet("user/ban/number")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
@ -34,7 +39,7 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
logger.LogInformation("[INFORMATION] {nb} Email(s) banni(s) trouvé(s)", nb);
return Ok(nb);
}
[HttpPost("user/ban")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -44,12 +49,13 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
if (res != null)
{
logger.LogInformation("[INFORMATION] Utilisateur banni avec l'email {email} a été trouvé.", email);
return Ok(res);
return Ok(res);
}
logger.LogError("[ERREUR] Aucun utilisateur banni trouvé avec l'email {email}.", email);
return NotFound("Utilisateur non trouvé !");
}
[HttpDelete("user/ban/{username:alpha}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
@ -58,7 +64,8 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
var success = blackListService.BanUser(username);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été banni pour 2 ans.", username);
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été banni pour 2 ans.",
username);
return Ok();
}
else
@ -67,7 +74,7 @@ public class BlackListController(ILogger<UsersController> logger, IBlackListServ
return NotFound();
}
}
[HttpPost("user/unban")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]

@ -5,135 +5,135 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class InquiriesController : Controller
{
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class InquiriesController : Controller
{
private readonly IInquiryService<InquiryDto> _inquiryDataService;
private readonly IInquiryService<InquiryDto> _inquiryDataService;
private readonly ILogger<InquiriesController> _logger;
private readonly ILogger<InquiriesController> _logger;
public InquiriesController(IInquiryService<InquiryDto> inquiryDataService, ILogger<InquiriesController> logger)
{
_inquiryDataService = inquiryDataService;
_logger = logger;
}
public InquiriesController(IInquiryService<InquiryDto> inquiryDataService, ILogger<InquiriesController> logger)
[HttpGet("inquiries/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetInquiries(int page, int number, InquiryOrderCriteria orderCriteria)
{
var nbInquiry = _inquiryDataService.GetInquiries(page, number, orderCriteria).Count();
if (nbInquiry == 0)
{
_inquiryDataService = inquiryDataService;
_logger = logger;
_logger.LogError("[ERREUR] Aucune enquête trouvée.");
return StatusCode(204);
}
[HttpGet("inquiries/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetInquiries(int page, int number, InquiryOrderCriteria orderCriteria)
{
var nbInquiry = _inquiryDataService.GetInquiries(page, number, orderCriteria).Count();
if (nbInquiry == 0)
{
_logger.LogError("[ERREUR] Aucune enquête trouvée.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
return Ok(_inquiryDataService.GetInquiries(page, number, orderCriteria));
}
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
return Ok(_inquiryDataService.GetInquiries(page, number, orderCriteria));
[HttpGet("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryById(int id)
{
try
{
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été trouvé.", id);
return Ok(_inquiryDataService.GetInquiryById(id));
}
[HttpGet("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryById(int id)
catch (ArgumentException)
{
try
{
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été trouvé.", id);
return Ok(_inquiryDataService.GetInquiryById(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
}
[HttpGet("inquiry/{title:alpha}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryByTitle(string title)
[HttpGet("inquiry/{title:alpha}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetInquiryByTitle(string title)
{
try
{
try
{
_logger.LogInformation("[INFORMATION] L'enquête avec le titre {title} a été trouvé.", title);
return Ok(_inquiryDataService.GetInquiryByTitle(title));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title);
return NotFound();
}
_logger.LogInformation("[INFORMATION] L'enquête avec le titre {title} a été trouvé.", title);
return Ok(_inquiryDataService.GetInquiryByTitle(title));
}
[HttpDelete("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteInquiry(int id)
catch (ArgumentException)
{
var success = _inquiryDataService.DeleteInquiry(id);
if (success)
{
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été supprimé.", id);
return Ok(_inquiryDataService.DeleteInquiry(id));
}
else
{
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
_logger.LogError("[ERREUR] Aucune enquête trouvée avec le titre {title}.", title);
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(InquiryDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateInquiry([FromBody] InquiryDto dto)
[HttpDelete("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteInquiry(int id)
{
var success = _inquiryDataService.DeleteInquiry(id);
if (success)
{
if (dto.Title == null || dto.Description == null)
{
return BadRequest();
}
_logger.LogInformation(
"[INFORMATION] Une enquête a été créé : title - {title}, description - {description}, isUser - {isUser}",
dto.Title, dto.Description, dto.IsUser);
return Created(nameof(GetInquiries),
_inquiryDataService.CreateInquiry(dto.Title, dto.Description, dto.IsUser));
_logger.LogInformation("[INFORMATION] L'enquête avec l'id {id} a été supprimé.", id);
return Ok(_inquiryDataService.DeleteInquiry(id));
}
else
{
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
}
[HttpPut("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateInquiry(int id, [FromBody] InquiryDto InquiryDto)
[HttpPost]
[ProducesResponseType(typeof(InquiryDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateInquiry([FromBody] InquiryDto dto)
{
if (dto.Title == null || dto.Description == null)
{
if (id != InquiryDto.Id)
{
_logger.LogError("[ERREUR] Problème ID - La mise à jour de l'enquête avec l'id {id} a échouée.", id);
return BadRequest();
}
return BadRequest();
}
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour de l'enquête avec l'id {id} a échouée.", id);
return BadRequest();
}
_logger.LogInformation(
"[INFORMATION] Une enquête a été créé : title - {title}, description - {description}, isUser - {isUser}",
dto.Title, dto.Description, dto.IsUser);
return Created(nameof(GetInquiries),
_inquiryDataService.CreateInquiry(dto.Title, dto.Description, dto.IsUser));
}
if (InquiryDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de l'enquête avec l'id {id} a été effectuée", id);
return Ok(_inquiryDataService.UpdateInquiry(id, InquiryDto));
}
[HttpPut("inquiry/{id:int}")]
[ProducesResponseType(typeof(InquiryDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateInquiry(int id, [FromBody] InquiryDto InquiryDto)
{
if (id != InquiryDto.Id)
{
_logger.LogError("[ERREUR] Problème ID - La mise à jour de l'enquête avec l'id {id} a échouée.", id);
return BadRequest();
}
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour de l'enquête avec l'id {id} a échouée.", id);
return BadRequest();
}
if (InquiryDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de l'enquête avec l'id {id} a été effectuée", id);
return Ok(_inquiryDataService.UpdateInquiry(id, InquiryDto));
}
_logger.LogError("[ERREUR] Aucune enquête trouvée avec l'id {id}.", id);
return NotFound();
}
}

@ -1,155 +1,153 @@
using System.Net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Dto;
using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class LessonsController : Controller
{
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class LessonsController : Controller
{
private readonly ILessonService<LessonDto> _lessonDataService;
private readonly ILessonService<LessonDto> _lessonDataService;
private readonly ILogger<LessonsController> _logger;
private readonly ILogger<LessonsController> _logger;
public LessonsController(ILessonService<LessonDto> lessonDataService, ILogger<LessonsController> logger)
{
_lessonDataService = lessonDataService;
_logger = logger;
}
public LessonsController(ILessonService<LessonDto> lessonDataService, ILogger<LessonsController> logger)
[HttpGet("lessons/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetLessons(int page, int number, LessonOrderCriteria orderCriteria)
{
var nbLesson = _lessonDataService.GetLessons(page, number, orderCriteria).Count();
if (nbLesson == 0)
{
_lessonDataService = lessonDataService;
_logger = logger;
_logger.LogError("[ERREUR] Aucune leçon trouvée.");
return StatusCode(204);
}
[HttpGet("lessons/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetLessons(int page, int number, LessonOrderCriteria orderCriteria)
{
var nbLesson = _lessonDataService.GetLessons(page, number, orderCriteria).Count();
if (nbLesson == 0)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Leçon(s) trouvée(s)", nbLesson);
return Ok(_lessonDataService.GetLessons(page, number, orderCriteria));
}
_logger.LogInformation("[INFORMATION] {nb} Leçon(s) trouvée(s)", nbLesson);
return Ok(_lessonDataService.GetLessons(page, number, orderCriteria));
[HttpGet("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonById(int id)
{
try
{
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été trouvé.", id);
return Ok(_lessonDataService.GetLessonById(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
}
}
[HttpGet("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonById(int id)
[HttpGet("lesson/{title:alpha}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonByTitle(string title)
{
try
{
try
{
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été trouvé.", id);
return Ok(_lessonDataService.GetLessonById(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
}
_logger.LogInformation("[INFORMATION] La leçon avec le titre {title} a été trouvé.", title);
return Ok(_lessonDataService.GetLessonByTitle(title));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec le titre {title}.", title);
return NotFound();
}
}
[HttpGet("lesson/{title:alpha}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonByTitle(string title)
[HttpDelete("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteLesson(int id)
{
var success = _lessonDataService.DeleteLesson(id);
if (success)
{
try
{
_logger.LogInformation("[INFORMATION] La leçon avec le titre {title} a été trouvé.", title);
return Ok(_lessonDataService.GetLessonByTitle(title));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec le titre {title}.", title);
return NotFound();
}
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été supprimé.", id);
return Ok(_lessonDataService.DeleteLesson(id));
}
else
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
}
}
[HttpDelete("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteLesson(int id)
[HttpPost]
[ProducesResponseType(typeof(LessonDto), 201)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 500)]
public IActionResult CreateLesson([FromBody] LessonDto dto)
{
if (dto.Title == null || dto.LastPublisher == null)
{
return BadRequest();
}
try
{
var success = _lessonDataService.DeleteLesson(id);
if (success)
var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now));
if (createdLesson != null)
{
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été supprimé.", id);
return Ok(_lessonDataService.DeleteLesson(id));
_logger.LogInformation(
"[INFORMATION] Une leçon a été créé : title - {title}, lastPublisher - {publisher}, lastEdit - {lastEdit}",
dto.Title, dto.LastPublisher, dto.LastEdit);
return Created(nameof(GetLessons), createdLesson);
}
else
{
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
return StatusCode(500);
}
}
[HttpPost]
[ProducesResponseType(typeof(LessonDto), 201)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 500)]
public IActionResult CreateLesson([FromBody] LessonDto dto)
catch (ArgumentException e)
{
if (dto.Title == null || dto.LastPublisher == null)
{
return BadRequest();
}
try
{
var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now));
if (createdLesson != null)
{
_logger.LogInformation(
"[INFORMATION] Une leçon a été créé : title - {title}, lastPublisher - {publisher}, lastEdit - {lastEdit}",
dto.Title, dto.LastPublisher, dto.LastEdit);
return Created(nameof(GetLessons), createdLesson);
}
else
{
return StatusCode(500);
}
}
catch (ArgumentException e)
{
_logger.LogError("[ERREUR] " + e.Message);
return Created();
}
_logger.LogError("[ERREUR] " + e.Message);
return Created();
}
}
[HttpPut("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateLesson(int id, [FromBody] LessonDto LessonDto)
[HttpPut("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateLesson(int id, [FromBody] LessonDto LessonDto)
{
if (id != LessonDto.Id)
{
if (id != LessonDto.Id)
{
_logger.LogError("[ERREUR] Problème ID - La mise à jour de la leçon avec l'id {id} a échouée.", id);
return BadRequest();
}
if (!ModelState.IsValid)
{
_logger.LogError("[ERREUR] Problème controlleur - La mise à jour de la leçon avec l'id {id} a échouée.",
id);
return BadRequest();
}
if (LessonDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id);
return Ok(_lessonDataService.UpdateLesson(id, LessonDto));
}
_logger.LogError("[ERREUR] Problème ID - La mise à jour de la leçon avec l'id {id} a échouée.", id);
return BadRequest();
}
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
if (!ModelState.IsValid)
{
_logger.LogError("[ERREUR] Problème controlleur - La mise à jour de la leçon avec l'id {id} a échouée.",
id);
return BadRequest();
}
if (LessonDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id);
return Ok(_lessonDataService.UpdateLesson(id, LessonDto));
}
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);
return NotFound();
}
}

@ -5,139 +5,138 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class ParagraphsController : Controller
{
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class ParagraphsController : Controller
{
private readonly IParagraphService<ParagraphDto> _paragraphDataService;
private readonly IParagraphService<ParagraphDto> _paragraphDataService;
private readonly ILogger<ParagraphsController> _logger;
private readonly ILogger<ParagraphsController> _logger;
public ParagraphsController(IParagraphService<ParagraphDto> paragraphDataService,
ILogger<ParagraphsController> logger)
{
_paragraphDataService = paragraphDataService;
_logger = logger;
}
public ParagraphsController(IParagraphService<ParagraphDto> paragraphDataService,
ILogger<ParagraphsController> logger)
[HttpGet("paragraphs/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria)
{
var nbParagraph = _paragraphDataService.GetParagraphs(page, number, orderCriteria).ToList().Count;
if (nbParagraph == 0)
{
_paragraphDataService = paragraphDataService;
_logger = logger;
_logger.LogError("[ERREUR] Aucun paragraphe trouvé.");
return StatusCode(204);
}
[HttpGet("paragraphs/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria)
{
var nbParagraph = _paragraphDataService.GetParagraphs(page, number, orderCriteria).ToList().Count;
if (nbParagraph == 0)
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Paragraphe(s) trouvé(s)", nbParagraph);
return Ok(_paragraphDataService.GetParagraphs(page, number, orderCriteria));
}
_logger.LogInformation("[INFORMATION] {nb} Paragraphe(s) trouvé(s)", nbParagraph);
return Ok(_paragraphDataService.GetParagraphs(page, number, orderCriteria));
[HttpGet("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetParagraphById(int id)
{
try
{
_logger.LogInformation("[INFORMATION] Le paragraphe avec l'id {id} a été trouvé.", id);
return Ok(_paragraphDataService.GetParagraphById(id));
}
[HttpGet("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetParagraphById(int id)
catch (ArgumentException)
{
try
{
_logger.LogInformation("[INFORMATION] Le paragraphe avec l'id {id} a été trouvé.", id);
return Ok(_paragraphDataService.GetParagraphById(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
}
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
}
}
[HttpGet("paragraph/{title:alpha}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetParagraphByTitle(string title)
[HttpGet("paragraph/{title:alpha}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetParagraphByTitle(string title)
{
try
{
try
{
_logger.LogInformation("[INFORMATION] Le paragraphe avec le titre {title} a été trouvé.", title);
return Ok(_paragraphDataService.GetParagraphByTitle(title));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec le titre {title}.", title);
return NotFound();
}
_logger.LogInformation("[INFORMATION] Le paragraphe avec le titre {title} a été trouvé.", title);
return Ok(_paragraphDataService.GetParagraphByTitle(title));
}
[HttpDelete("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteParagraph(int id)
catch (ArgumentException)
{
var success = _paragraphDataService.DeleteParagraph(id);
if (success)
{
_logger.LogInformation("[INFORMATION] Le paragraphe avec l'id {id} a été supprimé.", id);
return Ok(_paragraphDataService.DeleteParagraph(id));
}
else
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
}
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec le titre {title}.", title);
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(ParagraphDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateParagraph([FromBody] ParagraphDto dto)
[HttpDelete("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteParagraph(int id)
{
var success = _paragraphDataService.DeleteParagraph(id);
if (success)
{
if (dto.ContentTitle == null || dto.ContentContent == null || dto.Title == null || dto.Content == null || dto.Info == null || dto.Query == null ||
dto.Comment == null)
{
return BadRequest();
}
_logger.LogInformation(
"[INFORMATION] Un paragraphe a été créé : title - {title}, content - {content}, info - {info}, query - {query}, comment - {comment}",
dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
return Created(nameof(GetParagraphs),
_paragraphDataService.CreateParagraph(dto.ContentTitle, dto.ContentContent,dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment,
dto.LessonId));
_logger.LogInformation("[INFORMATION] Le paragraphe avec l'id {id} a été supprimé.", id);
return Ok(_paragraphDataService.DeleteParagraph(id));
}
else
{
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
}
}
[HttpPut("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateParagraph(int id, [FromBody] ParagraphDto ParagraphDto)
[HttpPost]
[ProducesResponseType(typeof(ParagraphDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateParagraph([FromBody] ParagraphDto dto)
{
if (dto.ContentTitle == null || dto.ContentContent == null || dto.Title == null || dto.Content == null || dto.Info == null || dto.Query == null ||
dto.Comment == null)
{
if (id != ParagraphDto.Id)
{
_logger.LogError("[ERREUR] Problème ID - La mise à jour du paragraphe avec l'id {id} a échouée.", id);
return BadRequest();
}
return BadRequest();
}
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour du paragraphe avec l'id {id} a échouée.", id);
return BadRequest();
}
_logger.LogInformation(
"[INFORMATION] Un paragraphe a été créé : title - {title}, content - {content}, info - {info}, query - {query}, comment - {comment}",
dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
return Created(nameof(GetParagraphs),
_paragraphDataService.CreateParagraph(dto.ContentTitle, dto.ContentContent,dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment,
dto.LessonId));
}
if (ParagraphDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour du paragraphe avec l'id {id} a été effectuée", id);
return Ok(_paragraphDataService.UpdateParagraph(id, ParagraphDto));
}
[HttpPut("paragraph/{id:int}")]
[ProducesResponseType(typeof(ParagraphDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateParagraph(int id, [FromBody] ParagraphDto ParagraphDto)
{
if (id != ParagraphDto.Id)
{
_logger.LogError("[ERREUR] Problème ID - La mise à jour du paragraphe avec l'id {id} a échouée.", id);
return BadRequest();
}
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour du paragraphe avec l'id {id} a échouée.", id);
return BadRequest();
}
if (ParagraphDto != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour du paragraphe avec l'id {id} a été effectuée", id);
return Ok(_paragraphDataService.UpdateParagraph(id, ParagraphDto));
}
_logger.LogError("[ERREUR] Aucun paragraphe trouvé avec l'id {id}.", id);
return NotFound();
}
}

@ -5,203 +5,202 @@ using Model.OrderCriteria;
using Shared;
using Asp.Versioning;
namespace API.Controllers
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class SuccessesController : Controller
{
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class SuccessesController : Controller
private readonly ISuccessService<SuccessDto> _successDataService;
private readonly ILogger<SuccessesController> _logger;
public SuccessesController(ISuccessService<SuccessDto> successDataService, ILogger<SuccessesController> logger)
{
_successDataService = successDataService;
_logger = logger;
}
[HttpGet("successes/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 204)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult GetSuccesses(int page, int number, SuccessOrderCriteria orderCriteria)
{
if (page < 1 || number < 1)
{
_logger.LogError("[ERREUR] La page ou le nombre de succès est inférieur à 1.");
return BadRequest("La page ou le nombre de succès est inférieur à 1.");
}
var nbUser = _successDataService.GetSuccesses(page, number, orderCriteria).ToList().Count;
if (nbUser == 0)
{
_logger.LogError("[ERREUR] Aucun Succès trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Succès(s) trouvé(s)", nbUser);
return Ok(_successDataService.GetSuccesses(page, number, orderCriteria));
}
[HttpGet("success/user/{id:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetSuccessByUserId(int id)
{
if (id < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur est inférieur à 1.");
return BadRequest("L'id de l'utilisateur est inférieur à 1.");
}
try
{
_logger.LogInformation("[INFORMATION] Le succès avec l'id de l'utilisateur {id} a été trouvé.", id);
return Ok(_successDataService.GetSuccessesByUserId(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id de l'utilisateur {id}.", id);
return NotFound("Aucun utilisateur trouvé avec l'id de l'utilisateur.");
}
}
[HttpGet("success/inquiry/{id:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetSuccessByInquiryId(int id)
{
if (id < 1)
{
_logger.LogError("[ERREUR] L'id de l'enquête doit être inférieur à 1.");
return BadRequest("L'id de l'enquête doit être inférieur à 1.");
}
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id de l'enquête {inquiryId} a été trouvé.",
id);
return Ok(_successDataService.GetSuccessesByInquiryId(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id de l'enquête {inquiryId}.", id);
return NotFound("Aucune enquête trouvée avec l'id de l'enquête.");
}
}
[HttpDelete("success/{idUser:int}/{idInquiry:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteSuccess(int idUser, int idInquiry)
{
if (idUser < 1 || idInquiry < 1)
{
_logger.LogInformation("[INFORMATION] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
var success = _successDataService.DeleteSuccess(idUser, idInquiry);
if (success)
{
_logger.LogInformation("[INFORMATION] Le succès avec l'id {id} a été supprimé.", idUser);
return Ok(success);
}
else
{
_logger.LogError("[ERREUR] Aucun succès trouvé avec l'id {id}.", idUser);
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(SuccessDto), 201)]
[ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateSuccess([FromBody] SuccessDto dto)
{
if (dto.UserId < 1 || dto.InquiryId < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
try
{
var s = _successDataService.CreateSuccess(dto.UserId, dto.InquiryId, dto.IsFinished);
_logger.LogInformation(
"[INFORMATION] Un succès a été créé : userId - {userId}, inquiryId - {inquiryId}, isFinished - {isFinished}",
dto.UserId, dto.InquiryId, dto.IsFinished);
return Created(nameof(GetSuccesses), s);
}
catch (Exception e)
{
return HandleError(e);
}
}
[HttpPut("success/{idUser:int}/{idInquiry:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateSuccess(int idUser, int idInquiry, [FromBody] SuccessDto successDto)
{
if (idUser < 1 || idInquiry < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
if (idUser != successDto.UserId || idInquiry != successDto.InquiryId)
{
_logger.LogError(
"[ERREUR] Problème ID - La mise à jour du succès avec l'id de l'utilisateur {id} a échouée.",
idUser);
return BadRequest();
}
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour du succès avec l'id de l'utilisateur {id} a échouée.",
idUser);
return BadRequest();
}
try
{
var s = _successDataService.UpdateSuccess(idUser, idInquiry, successDto);
_logger.LogInformation(
"[INFORMATION] La mise à jour du succès avec l'id de l'utilisateur {id} a été effectuée", idUser);
return Ok(s);
}
catch (Exception e)
{
return HandleError(e);
}
}
private IActionResult HandleError(Exception e)
{
private readonly ISuccessService<SuccessDto> _successDataService;
private readonly ILogger<SuccessesController> _logger;
public SuccessesController(ISuccessService<SuccessDto> successDataService, ILogger<SuccessesController> logger)
{
_successDataService = successDataService;
_logger = logger;
}
[HttpGet("successes/{page:int}/{number:int}/{orderCriteria}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 204)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult GetSuccesses(int page, int number, SuccessOrderCriteria orderCriteria)
{
if (page < 1 || number < 1)
{
_logger.LogError("[ERREUR] La page ou le nombre de succès est inférieur à 1.");
return BadRequest("La page ou le nombre de succès est inférieur à 1.");
}
var nbUser = _successDataService.GetSuccesses(page, number, orderCriteria).ToList().Count;
if (nbUser == 0)
{
_logger.LogError("[ERREUR] Aucun Succès trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Succès(s) trouvé(s)", nbUser);
return Ok(_successDataService.GetSuccesses(page, number, orderCriteria));
}
[HttpGet("success/user/{id:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetSuccessByUserId(int id)
{
if (id < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur est inférieur à 1.");
return BadRequest("L'id de l'utilisateur est inférieur à 1.");
}
try
{
_logger.LogInformation("[INFORMATION] Le succès avec l'id de l'utilisateur {id} a été trouvé.", id);
return Ok(_successDataService.GetSuccessesByUserId(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id de l'utilisateur {id}.", id);
return NotFound("Aucun utilisateur trouvé avec l'id de l'utilisateur.");
}
}
[HttpGet("success/inquiry/{id:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetSuccessByInquiryId(int id)
{
if (id < 1)
{
_logger.LogError("[ERREUR] L'id de l'enquête doit être inférieur à 1.");
return BadRequest("L'id de l'enquête doit être inférieur à 1.");
}
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id de l'enquête {inquiryId} a été trouvé.",
id);
return Ok(_successDataService.GetSuccessesByInquiryId(id));
}
catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id de l'enquête {inquiryId}.", id);
return NotFound("Aucune enquête trouvée avec l'id de l'enquête.");
}
}
[HttpDelete("success/{idUser:int}/{idInquiry:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteSuccess(int idUser, int idInquiry)
{
if (idUser < 1 || idInquiry < 1)
{
_logger.LogInformation("[INFORMATION] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
var success = _successDataService.DeleteSuccess(idUser, idInquiry);
if (success)
{
_logger.LogInformation("[INFORMATION] Le succès avec l'id {id} a été supprimé.", idUser);
return Ok(success);
}
else
{
_logger.LogError("[ERREUR] Aucun succès trouvé avec l'id {id}.", idUser);
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(SuccessDto), 201)]
[ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateSuccess([FromBody] SuccessDto dto)
{
if (dto.UserId < 1 || dto.InquiryId < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
try
{
var s = _successDataService.CreateSuccess(dto.UserId, dto.InquiryId, dto.IsFinished);
_logger.LogInformation(
"[INFORMATION] Un succès a été créé : userId - {userId}, inquiryId - {inquiryId}, isFinished - {isFinished}",
dto.UserId, dto.InquiryId, dto.IsFinished);
return Created(nameof(GetSuccesses), s);
}
catch (Exception e)
{
return HandleError(e);
}
}
[HttpPut("success/{idUser:int}/{idInquiry:int}")]
[ProducesResponseType(typeof(SuccessDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateSuccess(int idUser, int idInquiry, [FromBody] SuccessDto successDto)
{
if (idUser < 1 || idInquiry < 1)
{
_logger.LogError("[ERREUR] L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
return BadRequest("L'id de l'utilisateur ou de l'enquête doit être supérieur à 1.");
}
if (idUser != successDto.UserId || idInquiry != successDto.InquiryId)
{
_logger.LogError(
"[ERREUR] Problème ID - La mise à jour du succès avec l'id de l'utilisateur {id} a échouée.",
idUser);
return BadRequest();
}
if (!ModelState.IsValid)
{
_logger.LogError(
"[ERREUR] Problème controlleur - La mise à jour du succès avec l'id de l'utilisateur {id} a échouée.",
idUser);
return BadRequest();
}
try
{
var s = _successDataService.UpdateSuccess(idUser, idInquiry, successDto);
_logger.LogInformation(
"[INFORMATION] La mise à jour du succès avec l'id de l'utilisateur {id} a été effectuée", idUser);
return Ok(s);
}
catch (Exception e)
{
return HandleError(e);
}
}
private IActionResult HandleError(Exception e)
{
switch (e.Message)
{
case { } msg when msg.Contains("userId"):
_logger.LogError("[ERREUR] Impossible de trouver l'utilisateur pour la manipulation du succès");
return NotFound("Impossible de trouver l'utilisateur pour la manipulation du succès");
case { } msg when msg.Contains("inquiryId"):
_logger.LogError("[ERREUR] Impossible de trouver l'enquête pour la manipulation du succès");
return NotFound("Impossible de trouver l'enquête pour la manipulation du succès");
case { } msg when msg.Contains("success"):
_logger.LogError("[ERREUR] Impossible de manipuler le succès car il n'existe pas");
return Conflict("Impossible de manipuler le succès car il n'existe pas");
default:
_logger.LogError("[ERREUR] Erreur inattendue, impossible de manipuler le succès");
return BadRequest("Erreur inattendue, impossible de manipuler le succès");
}
switch (e.Message)
{
case { } msg when msg.Contains("userId"):
_logger.LogError("[ERREUR] Impossible de trouver l'utilisateur pour la manipulation du succès");
return NotFound("Impossible de trouver l'utilisateur pour la manipulation du succès");
case { } msg when msg.Contains("inquiryId"):
_logger.LogError("[ERREUR] Impossible de trouver l'enquête pour la manipulation du succès");
return NotFound("Impossible de trouver l'enquête pour la manipulation du succès");
case { } msg when msg.Contains("success"):
_logger.LogError("[ERREUR] Impossible de manipuler le succès car il n'existe pas");
return Conflict("Impossible de manipuler le succès car il n'existe pas");
default:
_logger.LogError("[ERREUR] Erreur inattendue, impossible de manipuler le succès");
return BadRequest("Erreur inattendue, impossible de manipuler le succès");
}
}
}

@ -5,194 +5,193 @@ using Microsoft.AspNetCore.Mvc;
using Shared;
using Model.OrderCriteria;
namespace API.Controllers
namespace API.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class UsersController(ILogger<UsersController> logger, IUserService<UserDto> userService) : ControllerBase
{
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class UsersController(ILogger<UsersController> logger, IUserService<UserDto> userService) : ControllerBase
[HttpGet("users/{page:int}/{number:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetUsers(int page, int number, UserOrderCriteria orderCriteria)
{
[HttpGet("users/{page:int}/{number:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetUsers(int page, int number, UserOrderCriteria orderCriteria)
{
var users = userService.GetUsers(page, number, orderCriteria).ToList();
if (users.Count == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
return Ok(users);
var users = userService.GetUsers(page, number, orderCriteria).ToList();
if (users.Count == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
[HttpGet("users/not-admin/{page:int}/{number:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNotAdminUsers(int page, int number, UserOrderCriteria orderCriteria)
{
var users = userService.GetNotAdminUsers(page, number, orderCriteria).ToList();
if (users.Count == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
return Ok(users);
}
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
return Ok(users);
}
[HttpGet("users/number")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNumberOfUsers()
{
var users = userService.GetNumberOfUsers();
if (users == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
[HttpGet("users/not-admin/{page:int}/{number:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNotAdminUsers(int page, int number, UserOrderCriteria orderCriteria)
{
var users = userService.GetNotAdminUsers(page, number, orderCriteria).ToList();
if (users.Count == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
logger.LogInformation("[INFORMATION] {users} Utilisateur(s) trouvé(s)", users);
return Ok(new KeyValuePair<string,int>("nbUsers", users));
logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", users.Count);
return Ok(users);
}
[HttpGet("users/number")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 204)]
public IActionResult GetNumberOfUsers()
{
var users = userService.GetNumberOfUsers();
if (users == 0)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
[HttpGet("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserById(int id)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
return Ok(userService.GetUserById(id));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
logger.LogInformation("[INFORMATION] {users} Utilisateur(s) trouvé(s)", users);
return Ok(new KeyValuePair<string,int>("nbUsers", users));
}
[HttpGet("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserById(int id)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
return Ok(userService.GetUserById(id));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
}
[HttpGet("user/{username:alpha}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserByUsername(string username)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
return Ok(userService.GetUserByUsername(username));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username);
return NotFound("Utilisateur non trouvé !");
}
}
[HttpGet("user/email/{email}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetByEmail(string email)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {email} a été trouvé.", email);
return Ok(userService.GetUserByEmail(email));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {email}.", email);
return NotFound();
}
[HttpGet("user/{username:alpha}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetUserByUsername(string username)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
return Ok(userService.GetUserByUsername(username));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username);
return NotFound("Utilisateur non trouvé !");
}
}
[HttpGet("user/email/{email}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult GetByEmail(string email)
{
try
{
logger.LogInformation("[INFORMATION] Utilisateur avec l'username {email} a été trouvé.", email);
return Ok(userService.GetUserByEmail(email));
}
catch (ArgumentException)
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {email}.", email);
return NotFound();
}
}
[HttpDelete("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteUser(int id)
{
var success = userService.DeleteUser(id);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
return Ok();
}
else
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
[HttpDelete("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteUser(int id)
{
var success = userService.DeleteUser(id);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
return Ok();
}
else
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
}
[HttpDelete("user/username/{username:alpha}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteUserByUsername(string username)
{
var success = userService.DeleteUserByUsername(username);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été supprimé.", username);
return Ok();
}
else
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le pseudo {username}.", username);
return NotFound();
}
[HttpDelete("user/username/{username:alpha}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteUserByUsername(string username)
{
var success = userService.DeleteUserByUsername(username);
if (success)
{
logger.LogInformation("[INFORMATION] L'utilisateur avec le pseudo {username} a été supprimé.", username);
return Ok();
}
else
{
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le pseudo {username}.", username);
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(UserDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateUser([FromBody] UserDto dto)
{
if (dto.Username == null || dto.Password == null || dto.Email == null)
{
return BadRequest();
}
// return Ok(userService.CreateUser(username, password, email, isAdmin));
logger.LogInformation(
"[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}",
dto.Username, dto.Password, dto.Email, dto.IsAdmin);
return Created(nameof(GetUsers),
userService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
[HttpPost]
[ProducesResponseType(typeof(UserDto), 201)]
[ProducesResponseType(typeof(string), 400)]
public IActionResult CreateUser([FromBody] UserDto dto)
{
if (dto.Username == null || dto.Password == null || dto.Email == null)
{
return BadRequest();
}
[HttpPut("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateUser(int id, [FromBody] UserDto UserDto)
{
if (id != UserDto.Id)
{
logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
return BadRequest();
}
// return Ok(userService.CreateUser(username, password, email, isAdmin));
logger.LogInformation(
"[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}",
dto.Username, dto.Password, dto.Email, dto.IsAdmin);
return Created(nameof(GetUsers),
userService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
}
if (!ModelState.IsValid)
{
logger.LogError(
"[ERREUR] Problème controller - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
return BadRequest();
}
[HttpPut("user/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateUser(int id, [FromBody] UserDto UserDto)
{
if (id != UserDto.Id)
{
logger.LogError("[ERREUR] Problème ID - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
return BadRequest();
}
if (UserDto != null)
{
logger.LogInformation("[INFORMATION] La mise à jour de l'utilisateur avec l'id {id} a été effectuée",
id);
return Ok(userService.UpdateUser(id, UserDto));
}
if (!ModelState.IsValid)
{
logger.LogError(
"[ERREUR] Problème controller - La mise à jour de l'utilisateur avec l'id {id} a échouée.", id);
return BadRequest();
}
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
if (UserDto != null)
{
logger.LogInformation("[INFORMATION] La mise à jour de l'utilisateur avec l'id {id} a été effectuée",
id);
return Ok(userService.UpdateUser(id, UserDto));
}
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
}
Loading…
Cancel
Save