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,24 +1,26 @@
using API.Dto;
using API.Mapping;
using EFManager;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
namespace API.Controllers
{
[ApiController]
[Route("[controller]")]
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;
public ChampionController(ILogger<ChampionController> logger)
public ChampionController(StubData manager, ILogger<ChampionController> logger)
{
data = manager;
_logger = logger;
}
@ -59,52 +61,57 @@ namespace API.Controllers
List<ChampionDto> DtoChamps = new List<ChampionDto>();
// 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);
}
[HttpGet]
[Route("{Name}")]
public async Task<ActionResult<ChampionDto>> GetChampById(int id)
[HttpGet("count")]
public async Task<IActionResult> GetCount()
{
// Récupération de la liste des champions
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1);
// Récupération du champion correspondant à l'id
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
try
{
// Renvoie le nombre de champion
return Ok(data.ChampionsMgr.GetNbItems());
}
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)
{
// 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)
[HttpGet("{name}")]
public async Task<ActionResult<ChampionDto>> GetChampByName(string name)
{
try
{
// Converstion en Champion au lieu de champion IEnumerable
Champion champion = Champs.First();
// Récupération de la liste des champions
IEnumerable<Champion?> champion = await data.ChampionsMgr.GetItemsByName(name, 0, data.ChampionsMgr.GetNbItems().Result);
// Récupération des skin du champion
IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
// Enregistrement des log
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampByName), name);
// Création de la liste de skin
List<SkinDto> skins = new List<SkinDto>();
// Création du champion Dto
ChampionDto resultat = champion.First().ToDto();
// Ajout des skins dans la nouvelle liste
Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
// Vérification de sa véraciter
if (resultat == null)
{
_logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok(resultat);
return Ok(skins);
}
return BadRequest();
catch (Exception e)
{
return BadRequest(e.Message);
}
}
/**** Méthodes POST ****/
[HttpPost("Ajouter/{nom}")]
public async Task<ActionResult> PostChampName(string nom)
@ -115,7 +122,7 @@ namespace API.Controllers
// Ajout du champion dans la BD
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")]
@ -133,8 +140,7 @@ namespace API.Controllers
[HttpPost]
public async Task<ActionResult> post([FromBody] ChampionDto championDto)
{
return CreatedAtAction(nameof(GetChampById), new { id = 1 },
await data.ChampionsMgr.AddItem(championDto.ToModel()));
return CreatedAtAction(nameof(GetChampByName), new { id = 1 }, await data.ChampionsMgr.AddItem(championDto.ToModel()));
}
/**** Méthodes DELETE ****/
@ -154,7 +160,7 @@ namespace API.Controllers
}
/**** Méthodes PUT ****/
/**** Méthodes PUT ****
[HttpPut("Modifier/{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());
}
/*[HttpPut("Modifier")]
[HttpPut("Modifier")]
public async Task<IActionResult> PutChamp([FromBody] ChampionDto championDto)
{
Champion champion = championDto.ToModel();
await data.ChampionsMgr.UpdateItem(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
{
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 ChampionClass Class { get; set; }
public ReadOnlyCollection<SkinDto> Skins { get; set; }
public ImmutableHashSet<SkillDto> Skills { get; set; }
public IEnumerable<SkinDto> Skins { get; set; }
public IEnumerable<SkillDto> Skills { get; set; }
public LargeImage Image { get; set; }
}

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

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

@ -16,7 +16,7 @@ namespace API.Mapping
return new SkinDto()
{
Name = skin.Name,
Champion = skin.Champion.ToDto(),
ChampionName = skin.Champion.Name,
Description = skin.Description,
Price = skin.Price,
Icon = skin.Icon,
@ -30,7 +30,7 @@ namespace API.Mapping
{
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 Microsoft.EntityFrameworkCore;
using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args);
@ -13,7 +14,10 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager, ManagerData>();
builder.Services.AddSingleton<ManagerData>();
builder.Services.AddScoped<StubData>();
// builder.Services.AddScoped<ManagerData>();
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)
{
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)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
public async Task<int> GetNbItems()
{
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)
@ -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();
}
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();
}
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();
}
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)
{
throw new NotImplementedException();
@ -147,18 +159,6 @@ namespace EFManager
{
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 ManagerData(SQLiteContext ContextData)
{
DbContext = ContextData;
ChampionsMgr = new ManagerChampion(this);
SkinsMgr = new ManagerSkin(this);
}
protected SQLiteContext DbContext { get; }
public IChampionsManager ChampionsMgr { get; }
@ -26,5 +20,12 @@ namespace EFManager
public IRunesManager RunesMgr { 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)
{
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();
}
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)
@ -91,19 +104,6 @@ namespace EFManager
{
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
{
// TODO
}
}

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

Loading…
Cancel
Save