Update API & schéma
continuous-integration/drone/push Build is failing Details

master
Louis DUFOUR 2 years ago
parent f9284d7b79
commit 3c63be52d4

File diff suppressed because one or more lines are too long

@ -1,25 +1,27 @@
using API.Dto; using API.Dto;
using API.Mapping; using API.Mapping;
using EFManager;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Model; using Model;
using StubLib; using StubLib;
namespace API.Controllers namespace API.Controllers
{ {
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
public class ChampionController : ControllerBase public class ChampionController : ControllerBase
{ {
private readonly StubData data = new StubData();
// Pour plus tard pour le momment c'est avec le stub
// private readonly IDataManager dataManager;
// private readonly ManagerData data;
private readonly StubData data;
private readonly ILogger<ChampionController> _logger; private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
public ChampionController(StubData manager, ILogger<ChampionController> logger)
{ {
_logger = logger; data = manager;
_logger = logger;
} }
/* /*
@ -59,52 +61,57 @@ namespace API.Controllers
List<ChampionDto> DtoChamps = new List<ChampionDto>(); List<ChampionDto> DtoChamps = new List<ChampionDto>();
// Chargement de la liste des champions Dto à partir des champions // Chargement de la liste des champions Dto à partir des champions
Champs.ToList().ForEach(c => DtoChamps.Add(c.ToDto())); Champs.ToList().ForEach(Champ => DtoChamps.Add(Champ.ToDto()));
return Ok(DtoChamps); return Ok(DtoChamps);
} }
[HttpGet] [HttpGet("count")]
[Route("{Name}")] public async Task<IActionResult> GetCount()
public async Task<ActionResult<ChampionDto>> GetChampById(int id)
{ {
// Récupération de la liste des champions try
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1); {
// Renvoie le nombre de champion
// Récupération du champion correspondant à l'id return Ok(data.ChampionsMgr.GetNbItems());
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) }
catch (Exception e)
{ {
return Ok(Champs.First().ToDto()); return BadRequest(e.Message);
} }
return BadRequest("404");
} }
[HttpGet("{Name}/Skins")]
public async Task<ActionResult<SkinDto>> GetSkinsChamp(string name) [HttpGet("{name}")]
public async Task<ActionResult<ChampionDto>> GetChampByName(string name)
{ {
// Récupération de la liste des champions try
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItemsByName(name, await data.ChampionsMgr.GetNbItemsByName(name), 1); {
// Récupération de la liste des champions
IEnumerable<Champion?> champion = await data.ChampionsMgr.GetItemsByName(name, 0, data.ChampionsMgr.GetNbItems().Result);
// Enregistrement des log
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampByName), name);
// Création du champion Dto
ChampionDto resultat = champion.First().ToDto();
// Vérification de sa véraciter
if (resultat == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok(resultat);
// Récupération du champion correspondant à l'id }
//if (await data.ChampionsMgr.GetNbItemsByName(name).Result) catch (Exception e)
{ {
// Converstion en Champion au lieu de champion IEnumerable return BadRequest(e.Message);
Champion champion = Champs.First(); }
}
// Récupération des skin du champion
IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
// Création de la liste de skin
List<SkinDto> skins = new List<SkinDto>();
// Ajout des skins dans la nouvelle liste
Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
return Ok(skins);
}
return BadRequest();
}
/**** Méthodes POST ****/ /**** Méthodes POST ****/
[HttpPost("Ajouter/{nom}")] [HttpPost("Ajouter/{nom}")]
public async Task<ActionResult> PostChampName(string nom) public async Task<ActionResult> PostChampName(string nom)
@ -115,7 +122,7 @@ namespace API.Controllers
// Ajout du champion dans la BD // Ajout du champion dans la BD
await data.ChampionsMgr.AddItem(champion); await data.ChampionsMgr.AddItem(champion);
return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto()); return CreatedAtAction(nameof(GetChampByName), new { Id = data.ChampionsMgr.GetNbItemsByName(nom) }, champion.ToDto());
} }
[HttpPost("Ajouter")] [HttpPost("Ajouter")]
@ -133,8 +140,7 @@ namespace API.Controllers
[HttpPost] [HttpPost]
public async Task<ActionResult> post([FromBody] ChampionDto championDto) public async Task<ActionResult> post([FromBody] ChampionDto championDto)
{ {
return CreatedAtAction(nameof(GetChampById), new { id = 1 }, return CreatedAtAction(nameof(GetChampByName), new { id = 1 }, await data.ChampionsMgr.AddItem(championDto.ToModel()));
await data.ChampionsMgr.AddItem(championDto.ToModel()));
} }
/**** Méthodes DELETE ****/ /**** Méthodes DELETE ****/
@ -154,7 +160,7 @@ namespace API.Controllers
} }
/**** Méthodes PUT ****/ /**** Méthodes PUT ****
[HttpPut("Modifier/{nom}")] [HttpPut("Modifier/{nom}")]
public async Task<ActionResult> PutChampName(string nom) public async Task<ActionResult> PutChampName(string nom)
@ -166,13 +172,13 @@ namespace API.Controllers
return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto()); return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto());
} }
/*[HttpPut("Modifier")] [HttpPut("Modifier")]
public async Task<IActionResult> PutChamp([FromBody] ChampionDto championDto) public async Task<IActionResult> PutChamp([FromBody] ChampionDto championDto)
{ {
Champion champion = championDto.ToModel(); Champion champion = championDto.ToModel();
await data.ChampionsMgr.UpdateItem(champion); await data.ChampionsMgr.UpdateItem(champion);
return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetItems(0, data.ChampionsMgr.GetNbItems().Result).Result.ToList().IndexOf(champion) }, champion); return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetItems(0, data.ChampionsMgr.GetNbItems().Result).Result.ToList().IndexOf(champion) }, champion);
}*/ }
*/
} }
} }

@ -1,6 +1,50 @@
namespace API.Controllers using API.Dto;
using EFManager;
using Microsoft.AspNetCore.Mvc;
using Model;
namespace API.Controllers
{ {
[ApiController]
[Route("[controller]")]
public class SkinController public class SkinController
{ {
private readonly ManagerData data;
private readonly ILogger<SkinController> _logger;
public SkinController(ManagerData manager, ILogger<SkinController> logger)
{
data = manager;
_logger = logger;
}
/*
[HttpGet("{Name}/Skins")]
public async Task<ActionResult<SkinDto>> GetSkinsChamp(string name)
{
// Récupération de la liste des champions
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItemsByName(name, await data.ChampionsMgr.GetNbItemsByName(name), 1);
// Récupération du champion correspondant à l'id
//if (await data.ChampionsMgr.GetNbItemsByName(name).Result)
{
// Converstion en Champion au lieu de champion IEnumerable
Champion champion = Champs.First();
// Récupération des skin du champion
IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
// Création de la liste de skin
List<SkinDto> skins = new List<SkinDto>();
// Ajout des skins dans la nouvelle liste
Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
return Ok(skins);
}
return BadRequest();
}*/
} }
} }

@ -17,8 +17,8 @@ namespace API.Dto
public IEnumerable<int> ValueCharac { get; set; } public IEnumerable<int> ValueCharac { get; set; }
public ChampionClass Class { get; set; } public ChampionClass Class { get; set; }
public ReadOnlyCollection<SkinDto> Skins { get; set; } public IEnumerable<SkinDto> Skins { get; set; }
public ImmutableHashSet<SkillDto> Skills { get; set; } public IEnumerable<SkillDto> Skills { get; set; }
public LargeImage Image { get; set; } public LargeImage Image { get; set; }
} }

@ -5,7 +5,7 @@ namespace API.Dto
public class SkinDto public class SkinDto
{ {
public string Name { get; set; } public string Name { get; set; }
public ChampionDto Champion { get; set; } public string ChampionName { get; set; }
public string Description { get; set; } public string Description { get; set; }
public float Price { get; set; } public float Price { get; set; }
public string Icon { get; set; } public string Icon { get; set; }

@ -24,8 +24,8 @@ namespace API.Mapping
ValueCharac = champion.Characteristics.Values, ValueCharac = champion.Characteristics.Values,
Class = champion.Class, Class = champion.Class,
Skins = (ReadOnlyCollection<SkinDto>)champion.Skins.Select(skin => skin.ToDto()), Skins = champion.Skins.Select(skin => skin.ToDto()),
Skills = (ImmutableHashSet<SkillDto>)champion.Skills.Select(skill => skill.ToDto()), Skills = champion.Skills.Select(skill => skill.ToDto()),
Image = champion.Image Image = champion.Image
}; };
} }

@ -16,7 +16,7 @@ namespace API.Mapping
return new SkinDto() return new SkinDto()
{ {
Name = skin.Name, Name = skin.Name,
Champion = skin.Champion.ToDto(), ChampionName = skin.Champion.Name,
Description = skin.Description, Description = skin.Description,
Price = skin.Price, Price = skin.Price,
Icon = skin.Icon, Icon = skin.Icon,
@ -30,7 +30,7 @@ namespace API.Mapping
{ {
throw new ArgumentNullException("DtoSkin null"); throw new ArgumentNullException("DtoSkin null");
} }
return new Skin(skinDto.Name, skinDto.Champion.ToModel(), skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description); return new Skin(skinDto.Name, new Champion(skinDto.Name), skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description);
} }
} }
} }

@ -2,6 +2,7 @@ using EFlib;
using EFManager; using EFManager;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model; using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -13,7 +14,10 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager, ManagerData>(); builder.Services.AddSingleton<ManagerData>();
builder.Services.AddScoped<StubData>();
// builder.Services.AddScoped<ManagerData>();
var app = builder.Build(); var app = builder.Build();

Binary file not shown.

@ -45,6 +45,18 @@ namespace EFManager
} }
} }
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
var toUpdate = parent.DbContext.Champions.Find(oldItem.Name);
try
{
toUpdate = newItem.ToEF(parent.DbContext);
parent.DbContext.SaveChanges();
}
catch(DbUpdateException) { }
return newItem;
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
if (orderingPropertyName != null) if (orderingPropertyName != null)
@ -64,16 +76,9 @@ namespace EFManager
} }
} }
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); return parent.DbContext.Champions.Count();
} }
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -97,27 +102,34 @@ namespace EFManager
} }
} }
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<int> GetNbItems() public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.Champions.Count(); throw new NotImplementedException();
} }
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<int> GetNbItemsByCharacteristic(string charName) public async Task<int> GetNbItemsByCharacteristic(string charName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -147,18 +159,6 @@ namespace EFManager
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
var toUpdate = parent.DbContext.Champions.Find(oldItem.Name);
try
{
toUpdate = newItem.ToEF(parent.DbContext);
parent.DbContext.SaveChanges();
}
catch(DbUpdateException) { }
return newItem;
}
} }
} }
} }

@ -11,12 +11,6 @@ namespace EFManager
{ {
public partial class ManagerData : IDataManager public partial class ManagerData : IDataManager
{ {
public ManagerData(SQLiteContext ContextData)
{
DbContext = ContextData;
ChampionsMgr = new ManagerChampion(this);
SkinsMgr = new ManagerSkin(this);
}
protected SQLiteContext DbContext { get; } protected SQLiteContext DbContext { get; }
public IChampionsManager ChampionsMgr { get; } public IChampionsManager ChampionsMgr { get; }
@ -26,5 +20,12 @@ namespace EFManager
public IRunesManager RunesMgr { get; } public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; } public IRunePagesManager RunePagesMgr { get; }
public ManagerData(SQLiteContext ContextData)
{
DbContext = ContextData;
ChampionsMgr = new ManagerChampion(this);
SkinsMgr = new ManagerSkin(this);
}
} }
} }

@ -48,6 +48,19 @@ namespace EFManager
} }
} }
public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
var toUpdate = parent.DbContext.Skins.Find(oldItem.Name);
try
{
toUpdate.Champion = parent.DbContext.Champions.Find(newItem.Champion.Name);
parent.DbContext.SaveChanges();
}
catch (DbUpdateException) { }
return newItem;
}
public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
if (orderingPropertyName != null) if (orderingPropertyName != null)
@ -67,19 +80,19 @@ namespace EFManager
} }
} }
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) public async Task<int> GetNbItems()
{ {
throw new NotImplementedException(); return parent.DbContext.Skins.Count();
} }
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<int> GetNbItems() public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
return parent.DbContext.Skins.Count(); throw new NotImplementedException();
} }
public Task<int> GetNbItemsByChampion(Champion? champion) public Task<int> GetNbItemsByChampion(Champion? champion)
@ -91,19 +104,6 @@ namespace EFManager
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
var toUpdate = parent.DbContext.Skins.Find(oldItem.Name);
try
{
toUpdate.Champion = parent.DbContext.Champions.Find(newItem.Champion.Name);
parent.DbContext.SaveChanges();
}
catch (DbUpdateException) { }
return newItem;
}
} }
} }
} }

@ -12,6 +12,6 @@ namespace EFlib
{ {
public class EFRune public class EFRune
{ {
// TODO
} }
} }

@ -13,5 +13,6 @@ namespace EFlib
{ {
public class EFRunePage public class EFRunePage
{ {
// TODO
} }
} }

@ -27,7 +27,7 @@ namespace Model
Task<int> GetNbItemsBySkill(string skill); Task<int> GetNbItemsBySkill(string skill);
Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false); Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false);
} }
public interface ISkinsManager : IGenericDataManager<Skin?> public interface ISkinsManager : IGenericDataManager<Skin?>
{ {

Loading…
Cancel
Save