debut utilisation methode d'extension pour Lesson mais elles ne marchent pas toutes pour le moment
continuous-integration/drone/push Build is failing Details

MethodeExtensions
Victor GABORIT 1 year ago
parent 4b1490023d
commit 33157a2e13

@ -42,12 +42,12 @@ namespace API.Controllers
[HttpGet("lesson/{id:int}")] [HttpGet("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(LessonDTO), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonById(int id) public async Task<IActionResult> GetLessonById(int id)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été trouvé.", id); _logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été trouvé.", id);
return Ok(_dataService.lessonService.GetLessonById(id)); return Ok( await _dataService.lessonService.GetItems(1, 1, null, LessonOrderCriteria.ById.ToString().Substring(2), id));
} }
catch (ArgumentException) catch (ArgumentException)
{ {
@ -59,12 +59,12 @@ namespace API.Controllers
[HttpGet("lesson/{title:alpha}")] [HttpGet("lesson/{title:alpha}")]
[ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(LessonDTO), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
public IActionResult GetLessonByTitle(string title) public async Task<IActionResult> GetLessonByTitle(string title)
{ {
try try
{ {
_logger.LogInformation("[INFORMATION] La leçon avec le titre {title} a été trouvé.", title); _logger.LogInformation("[INFORMATION] La leçon avec le titre {title} a été trouvé.", title);
return Ok(_dataService.lessonService.GetLessonByTitle(title)); return Ok(await _dataService.lessonService.GetItems(1, 1, null, LessonOrderCriteria.ByTitle.ToString().Substring(2), title));
} }
catch (ArgumentException) catch (ArgumentException)
{ {
@ -76,13 +76,13 @@ namespace API.Controllers
[HttpDelete("lesson/{id:int}")] [HttpDelete("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(LessonDTO), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
public IActionResult DeleteLesson(int id) public async Task<IActionResult> DeleteLesson(int id)
{ {
var success = _dataService.lessonService.DeleteLesson(id); var success = await _dataService.lessonService.DeleteItem(id);
if (success) if (success)
{ {
_logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été supprimé.", id); _logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été supprimé.", id);
return Ok(_dataService.lessonService.DeleteLesson(id)); return Ok();
} }
else else
{ {
@ -94,21 +94,21 @@ namespace API.Controllers
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(LessonDTO), 201)] [ProducesResponseType(typeof(LessonDTO), 201)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
public IActionResult CreateLesson([FromBody] LessonDTO dto) public async Task<IActionResult> CreateLesson([FromBody] LessonDTO dto)
{ {
if (dto.Title == null || dto.LastPublisher == null) if (dto.Title == null || dto.LastPublisher == null)
{ {
return BadRequest(); return BadRequest();
} }
_logger.LogInformation("[INFORMATION] Une leçon a été créé : title - {title}, lastPublisher - {publisher}, lastEdit - {lastEdit}", dto.Title, dto.LastPublisher, dto.LastEdit); _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), _dataService.lessonService.CreateLesson(dto.Title, dto.LastPublisher, dto.LastEdit)); return Created(nameof(GetLessons), await _dataService.lessonService.AddItem(dto));
} }
[HttpPut("lesson/{id:int}")] [HttpPut("lesson/{id:int}")]
[ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(LessonDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
public IActionResult UpdateLesson(int id, [FromBody] LessonDTO lessonDTO) public async Task<IActionResult> UpdateLesson(int id, [FromBody] LessonDTO lessonDTO)
{ {
if (id != lessonDTO.Id) if (id != lessonDTO.Id)
{ {
@ -126,7 +126,7 @@ namespace API.Controllers
if (lessonDTO != null) if (lessonDTO != null)
{ {
_logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id); _logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id);
return Ok(_dataService.lessonService.UpdateLesson(id, lessonDTO)); return Ok(await _dataService.lessonService.UpdateItem<LessonDTO>(id, lessonDTO));
} }
_logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id); _logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id);

@ -7,6 +7,10 @@ public abstract class ContentLessonDTO
public string ContentTitle { get; set; } public string ContentTitle { get; set; }
public int LessonId { get; set; } public int LessonId { get; set; }
protected ContentLessonDTO()
{
}
protected ContentLessonDTO(int id, string contentContent, string contentTitle, int lessonId) protected ContentLessonDTO(int id, string contentContent, string contentTitle, int lessonId)
{ {
Id = id; Id = id;
@ -22,7 +26,5 @@ public abstract class ContentLessonDTO
LessonId = lessonId; LessonId = lessonId;
} }
protected ContentLessonDTO()
{
}
} }

@ -5,5 +5,6 @@ public enum LessonOrderCriteria
None, None,
ByTitle, ByTitle,
ByLastPublisher, ByLastPublisher,
ByLastEdit ByLastEdit,
ById,
} }
Loading…
Cancel
Save