log
continuous-integration/drone/push Build is failing Details

API2
Bastien OLLIER 2 years ago
parent fb75fbb6be
commit c405b64fa2

@ -26,19 +26,23 @@ namespace apiLOL.Controllers
// GET: api/<ControllerLol>
[HttpGet]
public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10)
public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10, [FromQuery]string name = "")
{
//FromQuery permet de filtrer dans la collection de champions en fonction du nom
// Possible de faire une classe PageRequest pour gérer les paramètres index et count
_logger.LogInformation($"methode Get de ControllerChampions appelée"); //Context dans les logs
_logger.LogInformation($"methode Get de ControllerChampions appelée index:{index}, count: {count} et name:{name}");
int nbChampions = await data.ChampionsMgr.GetNbItems();
_logger.LogInformation($"Nombre de champions : {nbChampions}");
var champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO());
Task<IEnumerable<Champion?>> champs;
if(name.Equals(name))
champs = (Task<IEnumerable<Champion?>>)(await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO());
else
champs = (Task<IEnumerable<Champion?>>)(await data.ChampionsMgr.GetItemsByName(name, index, count)).Select(Model => Model.ToDTO());
var page = new ChampionPageDTO
{
Data = champs,
Data = (IEnumerable<ChampionDTO>)champs,
Index = index,
Count = count,
TotalCount = nbChampions
@ -58,10 +62,11 @@ namespace apiLOL.Controllers
var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1));
return Ok(champs.First().ToDTO());
}
catch
catch(Exception ex)
{
_logger.LogInformation($"erreur methode Get de ControllerChampions: {ex}");
return BadRequest("erreur de nom de champion");
} //Attraper l'excpetion et la logger
}
}
@ -79,8 +84,9 @@ namespace apiLOL.Controllers
ChampionDTO dtoChamp = champion.ToDTO();
return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp);
}
catch
catch (Exception ex)
{
_logger.LogInformation($"erreur methode Post de ControllerChampions: {ex}");
return BadRequest("le champion existe deja");
}
}
@ -97,8 +103,9 @@ namespace apiLOL.Controllers
champs.Bio = bio;
return Ok(champs.ToDTO());
}
catch
catch (Exception ex)
{
_logger.LogInformation($"erreur methode Put de ControllerChampions: {ex}");
return BadRequest("erreur de nom de champion");
}
}
@ -112,11 +119,12 @@ namespace apiLOL.Controllers
try
{
var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
data.ChampionsMgr.DeleteItem(champ); // await
await data.ChampionsMgr.DeleteItem(champ);
return Ok(champ.ToDTO());
}
catch
catch (Exception ex)
{
_logger.LogInformation($"erreur methode Delete de ControllerChampions: {ex}");
return BadRequest("erreur de nom de champion");
}
}

Loading…
Cancel
Save