merging
continuous-integration/drone/push Build is passing Details

Cleaning
David D'ALMEIDA 2 years ago
commit 93b1ec94da

@ -1,71 +0,0 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class RunePageController : ControllerBase
{
/* // GET: api/<RunePageController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await runesManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
// GET api/<RunePageController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<RunePageController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<RunePageController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<RunePageController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}*/
}
}

@ -1,70 +0,0 @@
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SkillController : ControllerBase
{
/* // GET: api/<SkillController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await runesManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
// GET api/<SkillController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<SkillController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<SkillController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<SkillController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}*/
}
}

@ -1,80 +0,0 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SkinController : ControllerBase
{
/* public ISkinsManager dataManager;
private readonly ILogger<ChampionsController> _logger;
public SkinController(IDataManager dataManager, ILogger<ChampionsController> logger)
{
this.dataManager = dataManager.SkinsMgr;
this._logger = logger;
}
// GET: api/<SkinController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
// GET api/<SkinController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<SkinController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<SkinController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<SkinController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}*/
}
}

@ -327,7 +327,9 @@ namespace API_LoL_Project.Controllers.version1
}
// degradation du modèle cleitn ell est dédié au cliens
[HttpGet("/count")]
// GET: api/champions/Count
[HttpGet("/count", Name = "GetChampionCount")]
public async Task<ActionResult<int>> NbChampions()
{
var nbChampions = await dataManager.GetNbItems();

@ -1,18 +1,18 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using API_LoL_Project.Mapper;
using API_LoL_Project.Controllers.Response;
using API_LoL_Project.Middleware;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers
namespace API_LoL_Project.Controllers.version1
{
[Route("api/[controller]")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class RuneController : ControllerBase
{
public IRunesManager dataManager;
@ -24,7 +24,7 @@ namespace API_LoL_Project.Controllers
{
this.dataManager = dataManager.RunesMgr;
this._logger = logger;
_logger = logger;
}

@ -0,0 +1,219 @@
using API_LoL_Project.Controllers.Response;
using API_LoL_Project.Middleware;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Model;
using ApiMappeur;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers.version1
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class RunePageController : ControllerBase
{
private IRunePagesManager dataManager;
private readonly ILogger<RunePageController> _logger;
public RunePageController(IDataManager dataManager, ILogger<RunePageController> logger)
{
this.dataManager = dataManager.RunePagesMgr;
_logger = logger;
}
// GET: api/v1/<RunePageController>
[HttpGet]
public async Task<ActionResult<PageResponse<RunePageDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
if (request.count * request.index >= totalcount)
{
_logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount);
return BadRequest("To many object is asked the max is : " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runesP = await dataManager.GetItems(request.index, request.count == 0 ? totalcount : request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
IEnumerable<RunePageDTO> res = runesP.Select(c => c.ToDto());
if (res.Count() <= 0 || res == null)
{
_logger.LogError("No RunePage found the total count is {totalcount} ", totalcount);
return BadRequest("No RunePage found : totalcount is : " + totalcount);
}
var respList = res.Select(r => new LolResponse<RunePageDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
}
));
var pageResponse = new PageResponse<RunePageDTO>(respList, request.index, request.count, totalcount);
return Ok(pageResponse);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest(e.Message);
}
}
[HttpGet("{name}")]
public async Task<ActionResult<IEnumerable<LolResponse<RunePageDTO>>>> GetRunePageByName(string name)
{
if (name == null || name == "")
{
var message = string.Format("Can not get Rune PAge without the name (is empty)");
_logger.LogWarning(message); ;
return BadRequest(message);
}
_logger.LogInformation("Executing {Action} with name : {runePageName}", nameof(GetRunePageByName), name);
try
{
var totalcount = await dataManager.GetNbItemsByName(name);
if (totalcount <= 0)
{
_logger.LogError("No chamions found with this name {name} in the dataContext", name); ;
return NotFound("No chamions found with this name: " + name + "in the dataContext");
}
var champion = await dataManager.GetItemsByName(name, 0, totalcount);
_logger.LogInformation($"========================= {champion} ================================================"); ;
if (champion.Count() <= 0 || champion == null)
{
_logger.LogError($"No chamions found with {name} executing {nameof(GetRunePageByName)}"); ;
return NotFound("No chamions found with" + name);
}
IEnumerable<RunePageDTO> res = champion.Select(c => c.ToDto());
/*ChampionFullDTO res = champion.First().toFullDTO();//.First*/
var respList = res.Select(r => new LolResponse<RunePageDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
}
));
return Ok(respList);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest("Somthing goes wrong caching the RunePage controller : " + e.Message);
}
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] RunePageDTO runePage)
{
_logger.LogInformation("method {Action} - RUNEPAGE call with {item}", nameof(Post), runePage);
try
{
if (await dataManager.GetNbItemsByName(runePage.Name) == 0)
{
return CreatedAtAction(nameof(Get),
(await dataManager.AddItem(runePage.ToModel())).ToDto());
}
_logger.LogWarning($"Name : {runePage.Name} is already exist");
return BadRequest($"Name : {runePage.Name} is already exist");
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
[HttpPut("{name}")]
public async Task<IActionResult> Put(string name, [FromBody] RunePageDTO value)
{
try
{
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name);
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champion == null)
{
_logger.LogError("No chamions found with {name} in the dataBase", name); ;
return NotFound();
}
var savedUpdatedRunePage = await dataManager.UpdateItem(champion.First(), value.ToModel());
if (savedUpdatedRunePage == null)
{
_logger.LogWarning("The updated RunePage not returned {name}", name); ;
return BadRequest();
}
return Ok(savedUpdatedRunePage);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest(e.Message);
}
}
[HttpDelete("{name}")]
public async Task<IActionResult> Delete(string name)
{
_logger.LogInformation("method {Action} - RUNEPAGE call with {name}", nameof(Delete), name);
try
{
var dtos = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (dtos == null)
{
_logger.LogWarning("{name} was not found", name);
return NotFound($"{name} was not found");
}
await dataManager.DeleteItem(dtos.First());
return NoContent();
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
// GET: api/<RunePageController>/count
[HttpGet("/countRunePage", Name = "GetRunePageCount")]
public async Task<ActionResult<int>> NbRunePage()
{
_logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbRunePage));
try
{
var nbRunePage = await dataManager.GetNbItems();
return Ok(nbRunePage);
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
}
}

@ -412,13 +412,27 @@ namespace API_LoL_Project.Controllers.version2
return Ok(res);
}
// degradation du modèle cleitn ell est dédié au cliens
[HttpGet("/count")]
// degradation du modèle cleitn ell est dédié au client
// GET: api/champions/Count
[HttpGet("/count", Name = "GetChampionCount")]
public async Task<ActionResult<int>> NbChampions()
{
var nbChampions = await dataManager.GetNbItems();
return Ok(nbChampions);
_logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbChampions));
try
{
var nbChampions = await dataManager.GetNbItems();
return Ok(nbChampions);
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
[HttpGet("count/class/{championClass}")]
public async Task<ActionResult<int>> GetChampionCountByClass(ChampionClass championClass)
{

@ -0,0 +1,189 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using API_LoL_Project.Controllers.Response;
using API_LoL_Project.Middleware;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers.version2
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("2.0")]
[ApiController]
public class RuneController : ControllerBase
{
public IRunesManager dataManager;
// you should create a custom logger to be prety
private readonly ILogger<RuneController> _logger;
public RuneController(IDataManager dataManager, ILogger<RuneController> logger)
{
this.dataManager = dataManager.RunesMgr;
_logger = logger;
}
/*// GET: api/<RuneController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> GetAllRunes([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
if (request.count * request.index >= totalcount)
{
_logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount);
return BadRequest("To many object is asked the max is : " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ;
var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() <= 0 || res == null)
{
_logger.LogError("No runes found the total count is {totalcount} ", totalcount);
return BadRequest("No runes found : totalcount is : " + totalcount);
}
var respList = res.Select(r => new LolResponce<RuneDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
}
));
var pageResponse = new PageResponse<RuneDTO>(respList, request.index, request.count, totalcount);
return Ok(pageResponse);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message);
return BadRequest(e.Message);
}
}
*/
// GET: api/<RuneController>
/* [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await runesManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
*/
/*
[HttpGet("{name}")]
public async Task<ActionResult<LolResponce<RuneDTO>>> GetRuneByName(string name)
{
try
{
var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name);
RuneDTO res = rune.First().toDTO();
if (res == null)
{
_logger.LogWarning("No runes found with {name}", name); ;
return NotFound();
}
var links = new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
};
var response = new LolResponce<RuneDTO>(res, links);
return Ok(response);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
}*/
/* // GET api/<RuneController>/5
[HttpGet("{id}")]
public string Get(int id)
{
try
{
var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
RuneDto result = champion.First().toDTO();
return Ok(result);
}
catch (Exeption e)
{
new HttpException(400, 'Cannot get rune :' + e.message);
}
}*/
// POST api/<RuneController>
// PUT api/<RuneController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<RuneController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

@ -0,0 +1,218 @@
using API_LoL_Project.Controllers.Response;
using API_LoL_Project.Middleware;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Model;
using ApiMappeur;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers.version2
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("2.0")]
[ApiController]
public class RunePageController : ControllerBase
{
private IRunePagesManager dataManager;
private readonly ILogger<RunePageController> _logger;
public RunePageController(IDataManager dataManager, ILogger<RunePageController> logger)
{
this.dataManager = dataManager.RunePagesMgr;
_logger = logger;
}
// GET: api/<RunePageController>
[HttpGet]
public async Task<ActionResult<PageResponse<RunePageDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
if (request.count * request.index >= totalcount)
{
_logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount);
return BadRequest("To many object is asked the max is : " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runesP = await dataManager.GetItems(request.index, request.count == 0 ? totalcount : request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending);
IEnumerable<RunePageDTO> res = runesP.Select(c => c.ToDto());
if (res.Count() <= 0 || res == null)
{
_logger.LogError("No RunePage found the total count is {totalcount} ", totalcount);
return BadRequest("No RunePage found : totalcount is : " + totalcount);
}
var respList = res.Select(r => new LolResponse<RunePageDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
}
));
var pageResponse = new PageResponse<RunePageDTO>(respList, request.index, request.count, totalcount);
return Ok(pageResponse);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest(e.Message);
}
}
// GET: api/<RunePageController>
[HttpGet("{name}")]
public async Task<ActionResult<IEnumerable<LolResponse<RunePageDTO>>>> GetRunePageByName(string name)
{
if (name == null || name == "")
{
var message = string.Format("Can not get Rune PAge without the name (is empty)");
_logger.LogWarning(message); ;
return BadRequest(message);
}
_logger.LogInformation("Executing {Action} with name : {runePageName}", nameof(GetRunePageByName), name);
try
{
var totalcount = await dataManager.GetNbItemsByName(name);
if (totalcount <= 0)
{
_logger.LogError("No RunePage found with this name {name} in the dataContext", name); ;
return NotFound("No RunePage found with this name: " + name + "in the dataContext");
}
var runeP = await dataManager.GetItemsByName(name, 0, totalcount);
_logger.LogInformation($"========================= {runeP} ================================================"); ;
if (runeP.Count() <= 0 || runeP == null)
{
_logger.LogError($"No RunePage found with {name} executing {nameof(GetRunePageByName)}"); ;
return NotFound("No RunePage found with" + name);
}
IEnumerable<RunePageDTO> res = runeP.Select(c => c.ToDto());
var respList = res.Select(r => new LolResponse<RunePageDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
}
));
return Ok(respList);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest("Somthing goes wrong caching the RunePage controller : " + e.Message);
}
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] RunePageDTO runePage)
{
_logger.LogInformation("method {Action} - RUNEPAGE call with {item}", nameof(Post), runePage);
try
{
if (await dataManager.GetNbItemsByName(runePage.Name) == 0)
{
return CreatedAtAction(nameof(Get),
(await dataManager.AddItem(runePage.ToModel())).ToDto());
}
_logger.LogWarning($"Name : {runePage.Name} is already exist");
return BadRequest($"Name : {runePage.Name} is already exist");
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
[HttpPut("{name}")]
public async Task<IActionResult> Put(string name, [FromBody] RunePageDTO value)
{
try
{
_logger.LogInformation("Executing {Action} with name : {RunePageName}", nameof(Put), name);
var runeP = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (runeP == null)
{
_logger.LogError("No RunePage found with {name} in the dataBase", name); ;
return NotFound();
}
var savedUpdatedRunePage = await dataManager.UpdateItem(runeP.First(), value.ToModel());
if (savedUpdatedRunePage == null)
{
_logger.LogWarning("The updated RunePage not returned {name}", name); ;
return BadRequest();
}
return Ok(savedUpdatedRunePage);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message);
return BadRequest(e.Message);
}
}
[HttpDelete("{name}")]
public async Task<IActionResult> Delete(string name)
{
_logger.LogInformation("method {Action} - RUNEPAGE call with {name}", nameof(Delete), name);
try
{
var dtos = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (dtos == null)
{
_logger.LogWarning("{name} was not found", name);
return NotFound($"{name} was not found");
}
await dataManager.DeleteItem(dtos.First());
return NoContent();
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
// GET: api/<RunePageController>/count
[HttpGet("/countRunePage", Name = "GetRunePageCount") ]
public async Task<ActionResult<int>> NbRunePage()
{
_logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbRunePage));
try
{
var nbRunePage = await dataManager.GetNbItems();
return Ok(nbRunePage);
}
catch (Exception error)
{
_logger.LogError(error.Message);
return BadRequest(error.Message);
}
}
}
}

@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers.version2
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("2.0")]
[ApiController]
public class SkillController : ControllerBase
{
/* // GET: api/<SkillController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await runesManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
// GET api/<SkillController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<SkillController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<SkillController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<SkillController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}*/
}
}

@ -0,0 +1,81 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers.version2
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("2.0")]
[ApiController]
public class SkinController : ControllerBase
{
/* public ISkinsManager dataManager;
private readonly ILogger<ChampionsController> _logger;
public SkinController(IDataManager dataManager, ILogger<ChampionsController> logger)
{
this.dataManager = dataManager.SkinsMgr;
this._logger = logger;
}
// GET: api/<SkinController>
[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
var runes = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
return BadRequest(e.Message);
}
}
// GET api/<SkinController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<SkinController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<SkinController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<SkinController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}*/
}
}

@ -50,7 +50,7 @@ namespace API_LoL_Project
{
var info = new OpenApiInfo()
{
Title = ".NET Core (.NET 6) Web API",
Title = ".NET Core (.NET 6) Web API For Lol",
Version = desc.ApiVersion.ToString()
};

@ -1,39 +0,0 @@
using DTO;
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class ChampionMapper {
public static ChampionEntity ToEntity(this Champion item)
{
return new()
{
Name = item.Name,
Bio = item.Bio,
Icon = item.Icon,
Class = item.Class,
Image = new() { Base64 = item.Image.Base64 },
};
}
public static Champion ToModel(this ChampionDTO dto)
{
if (dto == null)
{
var message = string.Format("Champion with name = {} nhhoddt found", dto.Name);
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/}
return new(dto.Name);
}
public static Champion ToModel(this ChampionEntity entity)
{
return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio);
}
}
}

@ -1,31 +0,0 @@
namespace API_LoL_Project.Mapper
{
using DTO;
using Model;
namespace API_LoL_Project.Mapper
{
public static class RuneMapper
{
public static RuneDTO ToDTO(this Rune item)
{
return new RuneDTO()
{
Name = item.Name,
Family = item.Family,
};
}
public static Rune ToModel(this RuneDTO dto)
{
/*if (dto == null)
{
*//* var message = string.Format("Champion with name = {} not found", dto.Name);
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//*
}*/
return new Rune(dto.Name, dto.Family);
}
}
}
}

@ -1,10 +0,0 @@
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class RunePageMapper
{
}
}

@ -1,13 +0,0 @@
using DTO;
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class SkinMapper
{
}
}

@ -19,6 +19,7 @@ builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionaryConverter<string, int>());
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
@ -58,6 +59,7 @@ if (app.Environment.IsDevelopment())
description.GroupName.ToUpperInvariant());
}
});
}
app.UseHttpsRedirection();

@ -1,6 +1,4 @@
using API_LoL_Project.Mapper;
using ApiMappeur;
using DTO;
using DTO;
using Entities;
using Model;

@ -1,29 +1,35 @@
 using DTO;
using Model;
using System.Text;
using Rune = Model.Rune;
namespace API_LoL_Project.Mapper
{
namespace ApiMappeur
{
public static class RuneMapper
{
public static RuneDTO ToDTO(this Rune item)
{
return new RuneDTO()
{
Name = item.Name,
Family = item.Family,
};
}
return new RuneDTO
{
Name = item.Name,
Description = item.Description,
Family = item.Family,
Icon = item.Icon,
Image = item.Image
};
}
public static Rune ToModel(this RuneDTO dto)
{
/*if (dto == null)
{
*//* var message = string.Format("Champion with name = {} not found", dto.Name);
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//*
}*/
return new Rune(dto.Name, dto.Family);
}
/*if (dto == null)
{
*//* var message = string.Format("Champion with name = {} not found", dto.Name);
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//*
}*/
return new Rune(dto.Name, dto.Family, dto.Icon, dto.Image.Base64, dto.Description);
}
}
}

@ -1,10 +0,0 @@
using Entities;
using Model;
namespace ApiMappeur
{
public static class RunePageMapper
{
}
}

@ -0,0 +1,77 @@
using DTO;
using Shared;
using Rune = Model.Rune;
using Model;
namespace ApiMappeur
{
/* public static class RunePageMappeur
{
public static RunePageDTO ToDto(this RunePage runePage)
{
var runePageDTO = new RunePageDTO
{
Name = runePage.Name,
Runes = new Dictionary<Category, RuneDTO>()
};
foreach (var runeCategory in Enum.GetValues(typeof(Category)).Cast<Category>())
{
var rune = runePage[runeCategory];
if (rune != null)
{
runePageDTO.Runes[runeCategory] = rune.ToDTO();
}
}
return runePageDTO;
}
public static RunePage ToModel(this RunePageDTO runePageDto)
{
var entity = new RunePage(runePageDto.Name);
foreach (var kvp in runePageDto.Runes)
{
var category = kvp.Key;
var runeDTO = kvp.Value;
var rune = new Rune(runeDTO.Name, runeDTO.Family, runeDTO.Icon, runeDTO.Image.Base64, runeDTO.Description);
entity[category] = rune;
}
return entity;}
}*/
public static class RunePageMappeur
{
public static RunePageDTO ToDto(this RunePage runePage)
{
return new RunePageDTO()
{
Name = runePage.Name,
Runes = runePage.Runes.ToDictionary(c => c.Key.ToString(), r => r.Value.ToDTO())
};
}
public static RunePage ToModel(this RunePageDTO runePageDto)
{
Category category;
Dictionary<Category, Rune> runDico = runePageDto.Runes.ToDictionary(
r => (Category)Enum.Parse(typeof(Category), r.Key),
r => r.Value.ToModel()
);
var runePage = new RunePage(runePageDto.Name);
foreach (var rune in runePageDto.Runes)
{
if (!Enum.TryParse<Category>(rune.Key, true, out category))
{
continue;
}
runePage[category] = rune.Value.ToModel();
}
return runePage;
}
}
}

@ -0,0 +1,15 @@
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class RunePageDTO
{
public string Name { get; set; }
public Dictionary<string, RuneDTO> Runes { get; set; }
}
}

@ -16,5 +16,17 @@ namespace DTO
public ImageDTO LargeImage { get; set; }
}
public class SkinFullDto
{
public string Champion { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
public ImageDTO LargeImage { get; set; }
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test_Api
{
public class RunePageControllerTest
{
}
}
Loading…
Cancel
Save