From 33157a2e13b30997ea3e6e7f9b0c01e91a70232a Mon Sep 17 00:00:00 2001 From: "victor.gaborit" Date: Fri, 15 Mar 2024 23:21:27 +0100 Subject: [PATCH] debut utilisation methode d'extension pour Lesson mais elles ne marchent pas toutes pour le moment --- .../API/Controllers/LessonsController.cs | 22 +++++++++---------- API_SQLuedo/Dto/ContentLessonDTO.cs | 10 +++++---- .../OrderCriteria/LessonOrderCriteria.cs | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/API_SQLuedo/API/Controllers/LessonsController.cs b/API_SQLuedo/API/Controllers/LessonsController.cs index 19b8f42..b88034a 100644 --- a/API_SQLuedo/API/Controllers/LessonsController.cs +++ b/API_SQLuedo/API/Controllers/LessonsController.cs @@ -42,12 +42,12 @@ namespace API.Controllers [HttpGet("lesson/{id:int}")] [ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(string), 404)] - public IActionResult GetLessonById(int id) + public async Task GetLessonById(int id) { try { _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) { @@ -59,12 +59,12 @@ namespace API.Controllers [HttpGet("lesson/{title:alpha}")] [ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(string), 404)] - public IActionResult GetLessonByTitle(string title) + public async Task GetLessonByTitle(string title) { try { _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) { @@ -76,13 +76,13 @@ namespace API.Controllers [HttpDelete("lesson/{id:int}")] [ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(string), 404)] - public IActionResult DeleteLesson(int id) + public async Task DeleteLesson(int id) { - var success = _dataService.lessonService.DeleteLesson(id); + var success = await _dataService.lessonService.DeleteItem(id); if (success) { _logger.LogInformation("[INFORMATION] La leçon avec l'id {id} a été supprimé.", id); - return Ok(_dataService.lessonService.DeleteLesson(id)); + return Ok(); } else { @@ -94,21 +94,21 @@ namespace API.Controllers [HttpPost] [ProducesResponseType(typeof(LessonDTO), 201)] [ProducesResponseType(typeof(string), 400)] - public IActionResult CreateLesson([FromBody] LessonDTO dto) + public async Task CreateLesson([FromBody] LessonDTO dto) { if (dto.Title == null || dto.LastPublisher == null) { return BadRequest(); } _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}")] [ProducesResponseType(typeof(LessonDTO), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 404)] - public IActionResult UpdateLesson(int id, [FromBody] LessonDTO lessonDTO) + public async Task UpdateLesson(int id, [FromBody] LessonDTO lessonDTO) { if (id != lessonDTO.Id) { @@ -126,7 +126,7 @@ namespace API.Controllers if (lessonDTO != null) { _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(id, lessonDTO)); } _logger.LogError("[ERREUR] Aucune leçon trouvée avec l'id {id}.", id); diff --git a/API_SQLuedo/Dto/ContentLessonDTO.cs b/API_SQLuedo/Dto/ContentLessonDTO.cs index 357d634..af098c4 100644 --- a/API_SQLuedo/Dto/ContentLessonDTO.cs +++ b/API_SQLuedo/Dto/ContentLessonDTO.cs @@ -5,7 +5,11 @@ public abstract class ContentLessonDTO public int Id { get; set; } public string ContentContent { 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) { @@ -22,7 +26,5 @@ public abstract class ContentLessonDTO LessonId = lessonId; } - protected ContentLessonDTO() - { - } + } \ No newline at end of file diff --git a/API_SQLuedo/Model/OrderCriteria/LessonOrderCriteria.cs b/API_SQLuedo/Model/OrderCriteria/LessonOrderCriteria.cs index db06097..16210d3 100644 --- a/API_SQLuedo/Model/OrderCriteria/LessonOrderCriteria.cs +++ b/API_SQLuedo/Model/OrderCriteria/LessonOrderCriteria.cs @@ -5,5 +5,6 @@ public enum LessonOrderCriteria None, ByTitle, ByLastPublisher, - ByLastEdit + ByLastEdit, + ById, } \ No newline at end of file