Commentaire utile

API2
nathan boileau 2 years ago
parent aef5c416af
commit b659748ca5

@ -29,6 +29,7 @@ namespace TestUnitaire
// Assert
// IS the champion added to the list, number of champions in the list + 1
Assert.Equal(nbInListBefore + 1, nbInListAfter);
// Test le code de retour
}

@ -13,6 +13,8 @@ namespace apiLOL.Controllers
public class ControllerChampions : Controller
{
private readonly IDataManager data;
// EFdata manager qui implémente l'interface IDataManager
// coté client : Refaire un APIdata manager qui implémente l'interface IDataManager
private readonly ILogger _logger;
public ControllerChampions(IDataManager manager, ILogger<ControllerChampions> log)
@ -28,7 +30,7 @@ namespace apiLOL.Controllers
{
//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");
_logger.LogInformation($"methode Get de ControllerChampions appelée"); //Context dans les logs
int nbChampions = await data.ChampionsMgr.GetNbItems();
_logger.LogInformation($"Nombre de champions : {nbChampions}");
@ -59,7 +61,7 @@ namespace apiLOL.Controllers
catch
{
return BadRequest("erreur de nom de champion");
}
} //Attraper l'excpetion et la logger
}
@ -103,12 +105,12 @@ namespace apiLOL.Controllers
// DELETE api/<ControllerLol>/5
[HttpDelete("{name}")]
public async Task<IActionResult> Delete(String name)
public async Task<IActionResult> Delete(string name)
{
try
{
var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
data.ChampionsMgr.DeleteItem(champ);
data.ChampionsMgr.DeleteItem(champ); // await
return Ok(champ.ToDTO());
}
catch

@ -11,6 +11,9 @@ builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager,StubData>();
// Scoped et Transient sont des types de cycle de vie
// Transient : une instance a chaque contruction d'objet
// Scoped : une instance par requete client
var app = builder.Build();

Loading…
Cancel
Save