add : V2 of ControllerChampions
continuous-integration/drone/push Build is passing Details

API2
Nathan BOILEAU 2 years ago
parent 428501e7fa
commit d476aff59f

@ -13,6 +13,7 @@ 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;
@ -30,12 +31,15 @@ namespace apiLOL.Controllers
{
//FromQuery permet de filtrer dans la collection de champions en fonction du nom
_logger.LogInformation($"methode Get de ControllerChampions appelée index:{index}, count: {count} et name:{name}");
_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)).Where(Model => Model.Name.Contains(name)).Select(Model => Model.ToDTO());
var champs = (await data.ChampionsMgr.GetItems(index, await data.ChampionsMgr.GetNbItems())).Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count).Select(Model => Model.ToDTO());
var champs = (await data.ChampionsMgr.GetItems(index, await data.ChampionsMgr.GetNbItems()))
.Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count)
.Select(Model => Model.ToDTO());
var page = new ChampionPageDTO
{
@ -90,7 +94,8 @@ namespace apiLOL.Controllers
[HttpPut("{name}")]
public async Task<IActionResult> Put(string name, string bio)
{
_logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}");
_logger.LogInformation(
$"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}");
try
{
@ -125,4 +130,45 @@ namespace apiLOL.Controllers
}
}
[ApiController]
[Route("api/v2/[controller]")]
[ApiVersion("2.0")]
public class ControllerChampionsSecondVersion : Controller
{
private readonly ILogger _logger;
public ControllerChampionsSecondVersion(ILogger<ControllerChampions> log)
{
_logger = log;
}
// GET api/<ControllerSkins>/5
[HttpGet()]
public string Get(int id)
{
return "Version 2 of GET";
}
// POST api/<ControllerSkins>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<ControllerSkins>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<ControllerSkins>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
@ -15,6 +17,15 @@ builder.Services.AddSingleton<IDataManager,StubData>();
// Transient : une instance a chaque contruction d'objet
// Scoped : une instance par requete client
// Configure API versioning
builder.Services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ApiVersionReader = new HeaderApiVersionReader("api-version");
});
var app = builder.Build();
// Configure the HTTP request pipeline.

Loading…
Cancel
Save