solving merge error
continuous-integration/drone/push Build is failing Details

Dave_Test_Api
David D'ALMEIDA 2 years ago
commit 7e119a10de

@ -22,6 +22,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Controllers\version2\" />
<Folder Include="Controllers\version1\" />
<Folder Include="service\" /> <Folder Include="service\" />
</ItemGroup> </ItemGroup>

@ -1,16 +1,20 @@
using API_LoL_Project.Mapper; using API_LoL_Project.Controllers.Response;
using API_LoL_Project.Mapper;
using API_LoL_Project.Middleware; using API_LoL_Project.Middleware;
using DTO; using DTO;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Model; using Model;
using StubLib; using StubLib;
using System.Collections.Generic;
using System.Text.Json;
using System.Xml.Linq; using System.Xml.Linq;
// 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
{ {
/*[Route("api/v{version:apiVersion}/[controller]")]*/
[Route("api/[controller]")] [Route("api/[controller]")]
/*[ApiVersion("1.0")]*/
[ApiController] [ApiController]
public class ChampionsController : ControllerBase public class ChampionsController : ControllerBase
{ {
@ -29,42 +33,58 @@ namespace API_LoL_Project.Controllers
// GET: api/<ChampionController> // GET: api/<ChampionController>/getAllChampions
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<ChampionDTO>>> Get([FromQuery] Request.PageRequest request) public async Task<ActionResult<PageResponse<ChampionDTO>>> Get([FromQuery] Request.PageRequest request)
{ {
try try
{ {
var totalcount = await dataManager.GetNbItems(); var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount) if (request.count * request.index >= totalcount)
{ {
_logger.LogWarning("No chamions found with Id"); _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount);
return BadRequest("No chamions found with Id "); return BadRequest("To many object is asked the max is : " + totalcount);
} }
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);;
var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, request.descending); _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ;
var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<ChampionDTO> res = champions.Select(c => c.ToDTO()); IEnumerable<ChampionDTO> res = champions.Select(c => c.ToDTO());
if (res.Count() <= 0 || res == null) if (res.Count() <= 0 || res == null)
{ {
_logger.LogWarning("No chamions found with Id"); _logger.LogError("No chamions found the total count is {totalcount} ", totalcount);
return BadRequest("No chamions found with Id "); return BadRequest("No chamions found : totalcount is : " + totalcount);
} }
return Ok(res);
var respList = res.Select(r => new LolResponce<ChampionDTO>
(
r,
new List<EndPointLink>
{
EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Get)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "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<ChampionDTO>(respList, request.index, request.count, totalcount);
return Ok(pageResponse);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message); return BadRequest(e.Message);
} }
} }
/*// GET api/<ChampionController>/5
// GET api/<ChampionController>/5 [HttpGet("{id}")]
[HttpGet("{name}")] public async Task<ActionResult<IEnumerable<ChampionFullDTO>>> GetChampionsById(int name)
public async Task<ActionResult<ChampionDTO>> GetChampionsByName(string name)
{ {
try try
{ {
@ -72,10 +92,11 @@ namespace API_LoL_Project.Controllers
var champion = await dataManager var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems()); .GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
ChampionDTO res = champion.First().ToDTO(); IEnumerable<ChampionFullDTO> res = champion.Select(c => c.toFullDTO());
if (res == null) if (res == null)
{ {
_logger.LogWarning("No chamions found with {name}", name); ; _logger.LogWarning("No chamions found with {name}", name); ;
return NotFound(); return NotFound();
} }
return Ok(res); return Ok(res);
@ -85,6 +106,79 @@ namespace API_LoL_Project.Controllers
{ {
return BadRequest(e.Message); return BadRequest(e.Message);
}
}*/
// GET: api/<ChampionController>/LargeImage
[HttpGet("image/{name}")]
public async Task<ActionResult<ImageDTO>> GetChampionsImage(string name)
{
try
{
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
/* IEnumerable<ChampionFullDTO> res = champion.Select(c => c.toFullDTO());//.First*/
ChampionFullDTO res = champion.First().toFullDTO();//.First
if (res == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok(res.LargeImage);
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
// GET api/<ChampionController>/name
[HttpGet("{name}")]
public async Task<ActionResult<LolResponce<ChampionFullDTO>>> GetChampionsByName(string name)
{
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
try
{
var totalcount = await dataManager.GetNbItemsByName(name);
if (totalcount <= 0)
{
_logger.LogWarning("No chamions found with this name {name}", name); ;
return BadRequest("No chamions found with this name: " + name);
}
var champion = await dataManager.GetItemsByName(name, 0, totalcount);
/* IEnumerable<ChampionFullDTO> res = champion.Select(c => c.toFullDTO());//.First*/
if (champion.Count() <= 0 || champion == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound("No chamions found with" + name);
}
ChampionFullDTO res = champion.First().toFullDTO();//.First
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<ChampionFullDTO>(res, links);
return Ok(response);
}
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest("Somthing goes wrong caching the Champions controller : " + e.Message);
} }
} }
@ -97,31 +191,46 @@ namespace API_LoL_Project.Controllers
{ {
var newChampion = value.ToModel(); var newChampion = value.ToModel();
await dataManager.AddItem(newChampion); await dataManager.AddItem(newChampion);
return CreatedAtAction(nameof(Get), newChampion) ; // can we check with a method
//var savedChampions = await dataManager.GetItemsByName(newChampion.name, 0, await dataManager.GetNbItems())
/*if (savedChampions.Count() >= 0 || res == null)
{
_logger.LogWarning("No chamions found ");
return BadRequest("No chamions found ");
}*/
_logger.LogInformation("Sucessfully saved Champions : " + newChampion.Name);
return CreatedAtAction(nameof(Get), newChampion);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message); return BadRequest(e.Message);
} }
} }
// should change for id cause model implementation use filteringbyName to getItemByNAme and it use substring
// PUT api/<ChampionController>/5 // PUT api/<ChampionController>/5
[HttpPut("{name}")] [HttpPut("{name}")]
public async Task<IActionResult> Put(string name, [FromBody] ChampionDTO value) public async Task<IActionResult> Put(string name, [FromBody] ChampionDTO value)
{ {
try try
{ {
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name);
var champion = await dataManager var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems()); .GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champion == null)
{
_logger.LogError("No chamions found with {name} in the dataBase", name); ;
return NotFound();
}
await dataManager.UpdateItem(champion.First(), value.ToModel()); await dataManager.UpdateItem(champion.First(), value.ToModel());
return Ok(); return Ok();
} }
catch(Exception e) catch (Exception e)
{ {
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message); return BadRequest(e.Message);
} }
} }
@ -132,17 +241,20 @@ namespace API_LoL_Project.Controllers
{ {
try try
{ {
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(Delete), name);
var champion = await dataManager var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems()); .GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champion != null) await dataManager.DeleteItem(champion.First()); if (champion != null) await dataManager.DeleteItem(champion.First());
else else
{ {
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound(); return NotFound();
} }
return Ok(); return Ok();
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message); return BadRequest(e.Message);
} }
@ -158,17 +270,48 @@ namespace API_LoL_Project.Controllers
}*/ }*/
[HttpGet("/{name}/skins")] [HttpGet("/{name}/skins")]
public async Task<ActionResult<Skin>> GetChampionsSkins(string name) public async Task<ActionResult<SkinDto>> GetChampionsSkins(string name)
{ {
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkins), name);
var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champions == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
//skinsDTO //skinsDTO
IEnumerable<Skin> res = champions.First().Skins; IEnumerable<SkinDto> res = champions.First().Skins.Select(c => c.ToDto());
if (res == null)
{
_logger.LogWarning("No skins found for {name}", name); ;
return NotFound();
}
return Ok(res); return Ok(res);
} }
[HttpGet("/{name}/skills")] /* [HttpGet("/{name}/skills")]
public async Task<ActionResult<Skin>> GetChampionsSkills(string name) public async Task<ActionResult<SkillDto>> GetChampionsSkills(string name)
{
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name);
var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champions == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
//skinsDTO
IEnumerable<SkillDto> res = champions.First().Skills.to;
if (res == null)
{
_logger.LogWarning("No skins found for {name}", name); ;
return NotFound();
}
return Ok(res);
}*/
[HttpPost("/{name}/skills")]
public async Task<ActionResult<IEnumerable<SkinDto>>> AddChampionsSkills(string name)
{ {
var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
//SkillDTO //SkillDTO
@ -177,13 +320,14 @@ namespace API_LoL_Project.Controllers
return Ok(res); return Ok(res);
} }
/*[HttpGet("/{name}/skins")] // degradation du modèle cleitn ell est dédié au cliens
public async Task<ActionResult<Skill> NbChampions() [HttpGet("/count")]
public async Task<ActionResult<int>> NbChampions()
{ {
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); var nbChampions = await dataManager.GetNbItems();
IEnumerable<ChampionDTO> res = champions.Select(c => c.toDTO()); return Ok(nbChampions);
return Ok(res); }
}*/
} }
} }

@ -3,8 +3,26 @@
public class PageRequest public class PageRequest
{ {
public string? orderingPropertyName { get; set; } = null; public string? orderingPropertyName { get; set; } = null;
public bool descending { get; set; } = false; public bool? descending { get; set; } = false;
// const int maxPageSize = 50;
// public int PageNumber { get; set; } = 1;
public int index { get; set; } = 1; public int index { get; set; } = 1;
public int count { get; set; } = 1; public int count { get; set; } = 1;
/*
//max lentght
private int _pageSize;
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = (value > maxPageSize) ? maxPageSize : value;
}
}*/
} }
} }

@ -0,0 +1,22 @@
namespace API_LoL_Project.Controllers.Response
{
public class EndPointLink
{
public string Href { get; set; }
public string Rel { get; set; }
public string Method { get; set; }
public EndPointLink()
{
}
public EndPointLink(string href, string rel, string method)
{
Href = href;
Rel = rel;
Method = method;
}
public static EndPointLink To(string href, string rel = "self", string method = "GET")
{
return new EndPointLink { Href = href, Rel = rel, Method = method };
}
}
}

@ -1,6 +1,22 @@
namespace API_LoL_Project.Controllers.Response using API_LoL_Project.Middleware;
namespace API_LoL_Project.Controllers.Response
{ {
public class PageResponse public class PageResponse<T>
{ {
public IEnumerable<LolResponce<T>> Data { get; set; }
public int Index { get; set; } = 1;
public int TotalCount { get; set; } = 1;
public int Count { get; set; } = 1;
public PageResponse(IEnumerable<LolResponce<T>> data, int indexRequested, int countRequested, int totalCount)
{
this.Data = data;
this.Index = indexRequested;
this.TotalCount = totalCount;
this.Count = countRequested;
}
} }
} }

@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Model; using Model;
using API_LoL_Project.Mapper; 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 // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -12,40 +14,71 @@ namespace API_LoL_Project.Controllers
[ApiController] [ApiController]
public class RuneController : ControllerBase public class RuneController : ControllerBase
{ {
/*public IRunesManager runesManager; public IRunesManager dataManager;
// you should create a custom logger to be prety // you should create a custom logger to be prety
private readonly ILogger<RuneController> _logger; private readonly ILogger<RuneController> _logger;
public RuneController(IDataManager dataManager, ILogger<RuneController> logger) public RuneController(IDataManager dataManager, ILogger<RuneController> logger)
{ {
this.runesManager = dataManager.RunesMgr; this.dataManager = dataManager.RunesMgr;
this._logger = logger; this._logger = logger;
} }
*//*// GET: api/<RuneController> // GET: api/<RuneController>
[HttpGet] [HttpGet]
public async Task<IEnumerable<RuneDTO>> Get() public async Task<ActionResult<IEnumerable<RuneDTO>>> GetAllRunes([FromQuery] Request.PageRequest request)
{ {
try try
{ {
var runes = await runesManager.GetItems(0, await runesManager.GetNbItems()); 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()); IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
return Ok(res); 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) catch (Exception e)
{ {
_logger.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString()); _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message);
return BadRequest(e.Message); return BadRequest(e.Message);
} }
}*//* }
// GET: api/<RuneController> // GET: api/<RuneController>
[HttpGet] /* [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request) public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{ {
try try
@ -54,12 +87,12 @@ namespace API_LoL_Project.Controllers
if (request.count + request.index > totalcount) if (request.count + request.index > totalcount)
{ {
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount); _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
return BadRequest("to many rows ask the max is " + totalcount) ; return BadRequest("to many rows ask the max is " + totalcount);
} }
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); _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)); 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()); IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null) if (res.Count() >= 0 || res == null)
{ {
@ -77,9 +110,45 @@ namespace API_LoL_Project.Controllers
} }
*/
[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);
// GET api/<RuneController>/5 }
catch (Exception e)
{
_logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
}
/* // GET api/<RuneController>/5
[HttpGet("{id}")] [HttpGet("{id}")]
public string Get(int id) public string Get(int id)
{ {
@ -97,24 +166,10 @@ namespace API_LoL_Project.Controllers
} }
} }*/
// POST api/<RuneController> // POST api/<RuneController>
[HttpPost]
public void Post([FromBody] string value)
{
try
{
await dataManager.AddItem(value.toModel());
return Ok();
}
catch ()
{
new HttpException(400, 'Cannot create rune')
}
}
// PUT api/<RuneController>/5 // PUT api/<RuneController>/5
[HttpPut("{id}")] [HttpPut("{id}")]
@ -127,6 +182,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")] [HttpDelete("{id}")]
public void Delete(int id) public void Delete(int id)
{ {
}*/ }
} }
} }

@ -9,7 +9,7 @@ namespace API_LoL_Project.Controllers
[ApiController] [ApiController]
public class RunePageController : ControllerBase public class RunePageController : ControllerBase
{ {
/* // GET: api/<RunePageController> /* // GET: api/<RunePageController>
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request) public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{ {

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc; 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 // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -8,13 +10,21 @@ namespace API_LoL_Project.Controllers
[ApiController] [ApiController]
public class SkinController : ControllerBase public class SkinController : ControllerBase
{ {
/* // GET: api/<SkinController> /* 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] [HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request) public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{ {
try try
{ {
var totalcount = await runesManager.GetNbItems(); var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount) if (request.count + request.index > totalcount)
{ {
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount); _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
@ -23,7 +33,7 @@ namespace API_LoL_Project.Controllers
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); _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)); 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()); IEnumerable<RuneDTO> res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null) if (res.Count() >= 0 || res == null)
{ {

@ -10,9 +10,10 @@ namespace API_LoL_Project.Mapper
{ {
if (item == null) if (item == null)
{ {
var message = string.Format("Champion with name = {} nhhoddt found", item.Name); var message = string.Format("Champion cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/ */
throw new Exception(message);
} }
return new ChampionDTO() { return new ChampionDTO() {
Name = item.Name, Name = item.Name,
@ -35,17 +36,19 @@ namespace API_LoL_Project.Mapper
{ {
if (item == null) if (item == null)
{ {
var message = string.Format("Champion with name = {} nhhoddt found", item.Name); var message = string.Format("Champion with name = {} not found", item.Name);
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/ */
throw new Exception(message);
} }
return new ChampionFullDTO() return new ChampionFullDTO()
{ {
Name = item.Name, Name = item.Name,
Bio = item.Bio, Bio = item.Bio,
skills = item.Skills, skills = item.Skills,
skins = item.Skins, skins = item.Skins.Select(i => i.ToDto()),
LargeImage = item.Image.Base64 LargeImage = item.Image.ToDTO()
}; };
@ -56,9 +59,12 @@ namespace API_LoL_Project.Mapper
{ {
if (dto == null) if (dto == null)
{ {
var message = string.Format("Champion with name = {} nhhoddt found", dto.Name); var message = string.Format("Champion cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/} */
throw new Exception(message);
}
return new(dto.Name); return new(dto.Name);
} }

@ -0,0 +1,23 @@
using DTO;
using Model;
namespace API_LoL_Project.Mapper
{
public static class ImageMappeur
{
public static ImageDTO ToDTO(this LargeImage item)
{
if (item == null)
{
var message = string.Format("Image cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
}
return new ImageDTO()
{
base64 = item.Base64
};
}
}
}

@ -8,6 +8,23 @@ namespace API_LoL_Project.Mapper
{ {
public static Skin ToModel(this SkinEntity entity)
{
throw new NotImplementedException();
}
public static SkinDto ToDto(this Skin item)
{
return new SkinDto()
{
Name = item.Name,
Description = item.Description,
Icon = item.Icon,
Price = item.Price
};
}
} }
} }

@ -0,0 +1,7 @@
namespace API_LoL_Project.Middleware
{
public class HateosMiddleware
{
}
}

@ -0,0 +1,18 @@
using API_LoL_Project.Controllers.Response;
using System.Net;
namespace API_LoL_Project.Middleware
{
public class LolResponce<T>
{
public T Data { get; set; }
public List<EndPointLink> Links { get; set; } = null;
public LolResponce(T data , List<EndPointLink>? links)
{
this.Data = data;
this.Links = links;
}
}
}

@ -1,5 +1,6 @@
using Model; using Model;
using System.Buffers.Text; using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
namespace DTO namespace DTO
{ {
@ -7,18 +8,24 @@ namespace DTO
{ {
public string Name { get; set; } public string Name { get; set; }
public string Bio { get; set; } public string Bio { get; set; }
public string Icon { get; set; }
/*public string Icon { get; set; } /*public string Icon { get; set; }
*/ */
} }
public class ChampionFullDTO public class ChampionFullDTO
{ {
/*[Required(ErrorMessage = "Name is required")]
[StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/
public string Name { get; set; } public string Name { get; set; }
public string Bio { get; set; } public string Bio { get; set; }
public string Characteristics { get; set; } public ReadOnlyDictionary<string, int> Characteristics { get; set; }
public string LargeImage { get; set; } public ImageDTO LargeImage { get; set; }
public IEnumerable<Skin> skins { get; set; } public IEnumerable<SkinDto> skins { get; set; }
public IEnumerable<Skill> skills { get; set; } public IEnumerable<Skill> skills { get; set; }
} }
} }

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class ImageDTO
{
public string base64 { get; set; }
}
}

@ -14,9 +14,9 @@ namespace DTO
public string Description { get; set; } public string Description { get; set; }
public RuneFamily Family { get; set; } public RuneFamily Family { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public LargeImage Image { get; set; } public LargeImage Image { get; set; }
} }

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class SkillDto
{
public string Name { get; set; }
public string Description { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class SkinDto
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}

@ -26,8 +26,11 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}"
<<<<<<< HEAD
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityMappers", "EntityMappers\EntityMappers.csproj", "{3A70A719-4F42-4CC3-846A-53437F3B4CC5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityMappers", "EntityMappers\EntityMappers.csproj", "{3A70A719-4F42-4CC3-846A-53437F3B4CC5}"
=======
>>>>>>> david_next_step
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

Loading…
Cancel
Save