add httpGet

pull/2/head
Bastien OLLIER 2 years ago
parent 5e9583329c
commit f57d5af384

@ -2,13 +2,15 @@
namespace apiLOL namespace apiLOL
{ {
public class ChampionMapper public static class ChampionMapper
{ {
public static ChampionDTO ToDTO(Champion champion) public static ChampionDTO ToDTO(this Champion champion)
{ {
ChampionDTO championDTO = new ChampionDTO(); ChampionDTO championDTO = new ChampionDTO();
championDTO.Name = champion.Name; championDTO.Name = champion.Name;
championDTO.Bio = champion.Bio; championDTO.Bio = champion.Bio;
Console.WriteLine(championDTO.Name);
return championDTO; return championDTO;
} }
} }

@ -1,49 +1,62 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using StubLib; using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 using StubLib;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace apiLOL.Controllers
{ namespace apiLOL.Controllers
[Route("api/[controller]")] {
[ApiController] [ApiController]
public class ControllerChampions : ControllerBase [Route("api/[controller]")]
{ public class ControllerChampions : Controller
public StubData.ChampionsManager ChampionsManager { get; set; } {
private readonly IDataManager data;
// GET: api/<ControllerLol> //public StubData.ChampionsManager ChampionsManager { get; set; }
[HttpGet]
public IEnumerable<string> Get() public ControllerChampions(IDataManager manager)
{
data = manager;
}
// GET: api/<ControllerLol>
[HttpGet]
public async Task<IActionResult> Get()
{ {
return new string[] { "value1", "value2" }; var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO());
return Ok(champs);
} }
// GET api/<ControllerLol>/5 // GET api/<ControllerLol>/5
[HttpGet("{id}")] [HttpGet("{id}")]
public string Get(int id) public async Task<IActionResult> Get(int id)
{ {
ChampionsManager.GetNbItemsByCharacteristic("Akali"); //ChampionsManager.GetNbItemsByCharacteristic("Akali");
ChampionMapper.ToDTO(ChampionsManager.GetNbItemsByCharacteristic("Akali")); //ChampionMapper.ToDTO(ChampionsManager.GetNbItemsByCharacteristic("Akali"));
//return new ChampionMapper.ToDTO(ChampionsManager.GetNbItemsByCharacteristic("Akali")); //return new ChampionMapper.ToDTO(ChampionsManager.GetNbItemsByCharacteristic("Akali"));
return "value"; //return "value";
} var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO());
return Ok(champs);
// POST api/<ControllerLol>
[HttpPost] }
public void Post([FromBody] string value)
{ // POST api/<ControllerLol>
} [HttpPost]
public void Post([FromBody] string value)
// PUT api/<ControllerLol>/5 {
[HttpPut("{id}")] }
public void Put(int id, [FromBody] string value)
{ // PUT api/<ControllerLol>/5
} [HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
// DELETE api/<ControllerLol>/5 {
[HttpDelete("{id}")] }
public void Delete(int id)
{ // DELETE api/<ControllerLol>/5
} [HttpDelete("{id}")]
} public void Delete(int id)
} {
}
}
}

@ -1,3 +1,6 @@
using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
@ -7,6 +10,8 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager,StubData>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

Loading…
Cancel
Save