|
|
|
@ -121,13 +121,25 @@ public class ActivityController : Controller
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<ActionResult<ActivityDto>> GetActivity(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetActivity), id);
|
|
|
|
|
|
|
|
|
|
var activity = await _activityService.GetActivityByIdAsync(id);
|
|
|
|
|
if (activity == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
_logger.LogError("Activity with id {id} not found", id);
|
|
|
|
|
|
|
|
|
|
return NotFound($"Activity with id {id} not found");
|
|
|
|
|
}
|
|
|
|
|
return Ok(activity.ToDto());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(e, "Error while getting activity by id {id}", id);
|
|
|
|
|
return Problem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public async Task<IActionResult> PutActivity(int id, ActivityDto activityDto)
|
|
|
|
@ -145,15 +157,44 @@ public class ActivityController : Controller
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supprime une activity spécifique.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">L'identifiant de l'activity à supprimer.</param>
|
|
|
|
|
/// <returns>Action result.</returns>
|
|
|
|
|
/// <response code="200">Activity supprimé avec succès.</response>
|
|
|
|
|
/// <response code="404">Activity non trouvé.</response>
|
|
|
|
|
/// <response code="500">Erreur interne du serveur.</response>
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
[ProducesResponseType(404)]
|
|
|
|
|
[ProducesResponseType(500)]
|
|
|
|
|
public async Task<IActionResult> DeleteActivity(int id)
|
|
|
|
|
{
|
|
|
|
|
var result = await _activityService.DeleteActivity(id);
|
|
|
|
|
if (!result)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
_logger.LogInformation("Executing {Action} with parameters: {Parameters} for {Id}", nameof(DeleteActivity), null,id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var activity = await _activityService.GetActivityByIdAsync(id);
|
|
|
|
|
if (activity == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("Activity with id {id} not found", id);
|
|
|
|
|
return NotFound($"Activity with id {id} not found");
|
|
|
|
|
}
|
|
|
|
|
var isDeleted = await _activityService.DeleteActivity(id);
|
|
|
|
|
if(!isDeleted)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("Error while deleting activity with id {id}", id);
|
|
|
|
|
return Problem("Error while deleting activity");
|
|
|
|
|
}
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(e, "Error while deleting activity");
|
|
|
|
|
return Problem();
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|