@ -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 . Get LessonById (id ) ) ;
return Ok ( await _dataService . lessonService . Get Items( 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 . Get LessonByTitle (title ) ) ;
return Ok ( await _dataService . lessonService . Get Items( 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 . Delete Lesson ( id ) ;
var success = await _dataService . lessonService . Delete Item ( 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 . Update Lesson( id , lessonDTO ) ) ;
return Ok ( await _dataService . lessonService . Update Item< 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 ) ;