Compare commits

...

1 Commits

Author SHA1 Message Date
David D'ALMEIDA 95c05e60a7 push
continuous-integration/drone/push Build is failing Details
2 years ago

@ -20,6 +20,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\v2\" />
<Folder Include="Controllers\v1\" />
<Folder Include="service\" />
</ItemGroup>

@ -11,7 +11,9 @@ using System.Xml.Linq;
namespace API_LoL_Project.Controllers
{
/*[Route("api/v{version:apiVersion}/[controller]")]*/
[Route("api/[controller]")]
/*[ApiVersion("1.0")]*/
[ApiController]
public class ChampionsController : ControllerBase
{
@ -39,33 +41,59 @@ namespace API_LoL_Project.Controllers
var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("No chamions found with Id");
return BadRequest("No chamions found with Id ");
_logger.LogWarning("No chamions found");
return BadRequest("No chamions found");
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);;
var champions = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<ChampionDTO> res = champions.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No chamions found with Id");
return BadRequest("No chamions found with Id ");
_logger.LogWarning("No chamions found ");
return BadRequest("No chamions found ");
}
return Ok(res);
}
catch (Exception e)
{
_logger.LogError("");
return BadRequest(e.Message);
}
}
/*// GET api/<ChampionController>/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<ChampionFullDTO>>> GetChampionsById(int 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());
if (res == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok(res);
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}*/
// GET api/<ChampionController>/5
[HttpGet("{name}")]
public async Task<ActionResult<ChampionDTO>> GetChampionsByName(string name)
public async Task<ActionResult<IEnumerable<ChampionFullDTO>>> GetChampionsByName(string name)
{
try
{
@ -73,7 +101,8 @@ namespace API_LoL_Project.Controllers
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_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)
{
_logger.LogWarning("No chamions found with {name}", name); ;
@ -187,4 +216,6 @@ namespace API_LoL_Project.Controllers
}*/
}
}

@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using Model;
using API_LoL_Project.Mapper;
using System.Xml.Linq;
using System;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -12,7 +14,7 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class RuneController : ControllerBase
{
public IRunesManager runesManager;
/*public IRunesManager runesManager;
// you should create a custom logger to be prety
private readonly ILogger<RuneController> _logger;
@ -26,7 +28,7 @@ namespace API_LoL_Project.Controllers
/*// GET: api/<RuneController>
*//*// GET: api/<RuneController>
[HttpGet]
public async Task<IEnumerable<RuneDTO>> Get()
{
@ -42,7 +44,7 @@ namespace API_LoL_Project.Controllers
return BadRequest(e.Message);
}
}*/
}*//*
// GET: api/<RuneController>
[HttpGet]
@ -79,21 +81,43 @@ namespace API_LoL_Project.Controllers
}
// GET api/<RuneController>/5
*//* // GET api/<RuneController>/5
[HttpGet("{id}")]
public string Get(int id)
public string GetRuneById(int id)
{
try
{
var rune = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
var rune = await runesManager.GetItemsByName
.(name, 0, await dataManager.GetNbItems());
RuneDto result = champion.First().toDTO();
return Ok(result);
}
catch (Exeption e)
}*//*
// GET api/<RuneController>/5
[HttpGet("{name}")]
public async string GetByRuneName(string name)
{
try
{
var rune = await runesManager
.GetItemsByName(name, 0, await runesManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetByRuneName), name);
RuneDTO res = rune.First().toFullDTO();
if (res == null)
{
_logger.LogWarning("No rune found with {name}", name); ;
return NotFound();
}
return Ok(res);
}
catch (Exception e)
{
return BadRequest(e.Message);
new HttpException(400, 'Cannot get rune :' + e.message);
}
@ -127,6 +151,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}*/
}
}

@ -9,7 +9,7 @@ namespace API_LoL_Project.Controllers
public class RunePageController : ControllerBase
{
// GET: api/<RunePageController>
[HttpGet]
/*[HttpGet]
public async Task<ActionResult<IEnumerable<RuneDTO>>> Get([FromQuery] Request.PageRequest request)
{
try
@ -65,6 +65,6 @@ namespace API_LoL_Project.Controllers
[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,20 +1,34 @@
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
namespace API_LoL_Project.Controllers
{
[Route("api/[controller]")]
/*[Route("api/[controller]")]
[ApiController]
public class SkinController : ControllerBase
{
public ISkinsManager dataManager;
private readonly ILogger<ChampionsController> _logger;
*//* public ChampionsController(IChampionsManager dataManager)
{
this.dataManager = dataManager;
}*//*
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)
public async Task<ActionResult<IEnumerable<SkinDto>>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await runesManager.GetNbItems();
var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
@ -23,12 +37,12 @@ namespace API_LoL_Project.Controllers
_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());
var skin = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable<SkinDto> res = skin.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
_logger.LogWarning("No runes found with Id");
return BadRequest("No runes found with Id ");
_logger.LogWarning("No skin founds");
return BadRequest("No skin founds");
}
return Ok(res);
}
@ -66,5 +80,5 @@ namespace API_LoL_Project.Controllers
public void Delete(int id)
{
}
}
}*/
}

@ -9,12 +9,38 @@ namespace API_LoL_Project.Mapper
public static ChampionDTO toDTO(this Champion item)
{
if (item == null)
{
var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
}
return new ChampionDTO() {
Name = item.Name,
Bio = item.Bio
};
}
public static ChampionFullDTO toFullDTO(this Champion item)
{
if (item == null)
{
var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
}
return new ChampionFullDTO()
{
Name = item.Name,
Bio = item.Bio,
Characteristics = item.Characteristics,
skills = item.Skills,
skins = item.Skins,
LargeImage = item.Image
};
}
public static Champion toModel(this ChampionDTO dto)
{

@ -0,0 +1,6 @@
namespace API_LoL_Project.Mapper
{
public class SkinsMappeur
{
}
}

@ -1,20 +1,22 @@
using Model;
using System.Collections.ObjectModel;
namespace DTO
{
public class ChampionDTO
{
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 class ChampionFullDTO
{
public string Name { get; set; }
public string Bio { get; set; }
public string Characteristics { get; set; }
public byte[] LargeImage { get; set; }
public ReadOnlyDictionary<string, int> Characteristics { get; set; }
public LargeImage LargeImage { get; set; }
public IEnumerable<Skin> skins { get; set; }
public IEnumerable<Skill> skills { 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; }
}
}

@ -1,6 +1,7 @@
using API_LoL_Project.Controllers;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Model;
using StubLib;
using System.Net;
@ -17,14 +18,15 @@ namespace Test_Api
{
var stubMgr = new StubData();
championCtrl = new ChampionsController(stubMgr);
championCtrl = new ChampionsController(stubMgr, new NullLogger<ChampionsController>());
}
[TestMethod]
public async Task TestGetChampions()
{
var getResult = await championCtrl.Get();
var getResult = await championCtrl.Get(new API_LoL_Project.Controllers.Request.PageRequest());
Console.WriteLine(getResult);
var objectRes = getResult as OkObjectResult;
Assert.AreEqual(200, objectRes.StatusCode);

Loading…
Cancel
Save