Merge branch 'master' into Mobile_APP
continuous-integration/drone/push Build is failing Details

pull/10/head
Louis DUFOUR 2 years ago
commit ab98c86c07

@ -10,31 +10,42 @@ namespace API.Controllers
[Route("[controller]")] [Route("[controller]")]
public class ChampionController : ControllerBase public class ChampionController : ControllerBase
{ {
private readonly ILogger<ChampionController> _logger;
private readonly StubData data = new StubData(); private readonly StubData data = new StubData();
private readonly IDataManager dataManager; // Pour plus tard pour le momment c'est avec le stub // Pour plus tard pour le momment c'est avec le stub
// private readonly IDataManager dataManager;
private const string Apichampion = "api/champion"; private readonly ILogger<ChampionController> _logger;
private readonly HttpClient _client;
public ChampionController(ILogger<ChampionController> logger) public ChampionController(ILogger<ChampionController> logger)
{ {
_logger = logger; _logger = logger;
} }
/* public championHttpManager(HttpClient client) /*
{
_client = client; private const string Apichampion = "api/champion";
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet"); private readonly HttpClient _client;
}
public championHttpManager(HttpClient client)
{
public async Task<IEnumerable<ChampionDto>> getJson() _client = client;
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet");
}
public async Task<IEnumerable<ChampionDto>> getJson()
{
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
var reponse = await _client.GetAsync("api/champion");
return champions;
}
public async void addchampion(ChampionDto champion)
{ {
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>(); _clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
var reponse = await _client.GetAsync("api/champion"); }
return champions; */
}*/
/**** Méthodes GET ****/ /**** Méthodes GET ****/
@ -57,10 +68,10 @@ namespace API.Controllers
[Route("{id}")] [Route("{id}")]
public async Task<ActionResult<ChampionDto>> GetChampById(int id) public async Task<ActionResult<ChampionDto>> GetChampById(int id)
{ {
BadRequest("404"); // Récupération de la liste des champions
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1); 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) if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
{ {
return Ok(Champs.First().ToDto()); return Ok(Champs.First().ToDto());
@ -71,23 +82,23 @@ namespace API.Controllers
[HttpGet("{id}/Skins")] [HttpGet("{id}/Skins")]
public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id) public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id)
{ {
// Récupération du champion // Récupération de la liste des champions
IEnumerable<Champion?> ChampNum = await data.ChampionsMgr.GetItems(id, 1); 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) if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
{ {
// Converstion en Champion au lieu de champion IEnumerable // Converstion en Champion au lieu de champion IEnumerable
Champion champion = ChampNum.First(); Champion champion = Champs.First();
// Récupération des skin du champion // Récupération des skin du champion
IEnumerable<Skin?> ListeSkin = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
// Création de la liste de skin // Création de la liste de skin
List<SkinDto> skins = new List<SkinDto>(); List<SkinDto> skins = new List<SkinDto>();
// Ajout des skins dans la nouvelle liste // Ajout des skins dans la nouvelle liste
ListeSkin.ToList().ForEach(Skin => skins.Add(Skin.ToDto())); Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
return Ok(skins); return Ok(skins);
} }
@ -98,34 +109,34 @@ namespace API.Controllers
[HttpPost("Ajouter/{nom}")] [HttpPost("Ajouter/{nom}")]
public async Task<ActionResult> PostChampName(string nom) public async Task<ActionResult> PostChampName(string nom)
{ {
// Création d'un champion avec son nom
Champion champion = new Champion(nom); Champion champion = new Champion(nom);
// 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(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto());
} }
[HttpPost("Ajouter")] [HttpPost("Ajouter")]
public async Task<IActionResult> PostChamp([FromBody] ChampionDto championDto) public async Task<ActionResult> PostChamp([FromBody] ChampionDto championDto)
{ {
// Convertie le championDto en model (a était ajouté via l'API)
Champion champion = championDto.ToModel(); Champion champion = championDto.ToModel();
// Ajout du champion en BD
await data.ChampionsMgr.AddItem(champion); await data.ChampionsMgr.AddItem(champion);
return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto); return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto);
} }
[HttpPost] [HttpPost]
public async Task<IActionResult> post([FromBody] ChampionDto championDto) public async Task<ActionResult> post([FromBody] ChampionDto championDto)
{ {
return CreatedAtAction(nameof(GetChampById), new { id = 1 }, return CreatedAtAction(nameof(GetChampById), new { id = 1 },
await data.ChampionsMgr.AddItem(championDto.ToModel())); await data.ChampionsMgr.AddItem(championDto.ToModel()));
} }
/*public async void addchampion(ChampionDto champion)
{
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
}
*/
/**** Méthodes DELETE ****/ /**** Méthodes DELETE ****/
[HttpDelete("Supprimer/{id}")] [HttpDelete("Supprimer/{id}")]
@ -143,7 +154,6 @@ namespace API.Controllers
} }
/**** Méthodes PUT ****/ /**** Méthodes PUT ****/
[HttpPut("Modifier/{nom}")] [HttpPut("Modifier/{nom}")]

@ -0,0 +1,6 @@
namespace API.Controllers
{
public class RuneController
{
}
}

@ -0,0 +1,6 @@
namespace API.Controllers
{
public class RunePageController
{
}
}

@ -0,0 +1,6 @@
namespace API.Controllers
{
public class SkillController
{
}
}

@ -0,0 +1,6 @@
namespace API.Controllers
{
public class SkinController
{
}
}

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

@ -0,0 +1,6 @@
namespace API.Dto
{
public class RuneDto
{
}
}

@ -0,0 +1,6 @@
namespace API.Dto
{
public class RunePageDto
{
}
}

@ -0,0 +1,11 @@
using Model;
namespace API.Dto
{
public class SkillDto
{
public string Name { get; set; }
public string Description { get; set; }
public SkillType Type { get; set; }
}
}

@ -5,10 +5,10 @@ namespace API.Dto
public class SkinDto public class SkinDto
{ {
public string Name { get; set; } public string Name { get; set; }
public Champion Champion { get; set; } public ChampionDto Champion { 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; }
public LargeImage Image { get; set; } public LargeImage Image { get; set; }
public string Description { get; set; }
} }
} }

@ -21,11 +21,14 @@ namespace API.Mapping
Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule
Bio = champion.Bio, Bio = champion.Bio,
Icon = champion.Icon, Icon = champion.Icon,
Keydic = champion.Characteristics.Keys, Keydic = champion.Characteristics.Keys,
Valuedic = champion.Characteristics.Values, Valuedic = champion.Characteristics.Values,
Class = champion.Class, Class = champion.Class,
Image = champion.Image, Skins = champion.Skins,
Skins = champion.Skins Skills = champion.Skills,
Image = champion.Image
}; };
} }
public static Champion ToModel(this ChampionDto champion) public static Champion ToModel(this ChampionDto champion)

@ -0,0 +1,6 @@
namespace API.Mapping
{
public class RuneMapper
{
}
}

@ -0,0 +1,6 @@
namespace API.Mapping
{
public class RunePageMapper
{
}
}

@ -0,0 +1,33 @@
using API.Dto;
using Model;
namespace API.Mapping
{
public static class SkillMapper
{
public static SkillDto ToDto(this Skill skill)
{
if (skill == null)
{
throw new ArgumentNullException("Skill null");
}
return new SkillDto()
{
Name = skill.Name,
Description = skill.Description,
Type = skill.Type
};
}
public static Skill ToSkill(this SkillDto skillDto)
{
if (skillDto == null)
{
throw new ArgumentNullException("SkinDto null");
}
return new Skill(skillDto.Name, skillDto.Type, skillDto.Description);
}
}
}

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

@ -17,7 +17,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

@ -1,4 +1,5 @@
using EFlib; using EFlib;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Model; using Model;
@ -10,39 +11,109 @@ namespace EFManager
public async Task<Champion?> AddItem(Champion? item) public async Task<Champion?> AddItem(Champion? item)
{ {
//await context.AddAsync(item.); TO DO if (item == null)
return null;
await context.AddAsync(item.toEF());
await context.SaveChangesAsync(); await context.SaveChangesAsync();
return item; return item;
} }
public Task<bool> DeleteItem(Champion? item) public Task<bool> DeleteItem(Champion? item)
{ {
throw new NotImplementedException(); if (item == null)
return false;
context.Remove(item.toEF());
await context.SaveChangesAsync();
return true;
} }
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); IQueryable<Champion> query = Champions.Skip(index).Take(count);
if (!string.IsNullOrEmpty(orderingPropertyName))
{
query = descending ?
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
}
return await query.ToListAsync();
} }
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, 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(); IQueryable<Champion> query = Champions
.Where(c => c.Characteristics.ContainsKey(charName))
.Skip(index)
.Take(count);
if (!string.IsNullOrEmpty(orderingPropertyName))
{
query = descending ?
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
}
return await query.ToListAsync();
} }
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, 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(); IQueryable<Champion> query = Champions
.Where(c => c.Class == championClass)
.Skip(index)
.Take(count);
if (!string.IsNullOrEmpty(orderingPropertyName))
{
query = descending ?
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
}
return await query.ToListAsync();
} }
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{ {
throw new NotImplementedException(); IQueryable<Champion> query = Champions
.Where(c => c.Name.Contains(substring))
.Skip(index)
.Take(count);
if (!string.IsNullOrEmpty(orderingPropertyName))
{
query = descending ?
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
}
return await query.ToListAsync();
} }
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, 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(); IQueryable<Champion> query = Champions;
if (runePage != null)
{
query = query.Where(c => c.RunePageId == runePage.Id);
}
query = query.Skip(index).Take(count);
if (!string.IsNullOrEmpty(orderingPropertyName))
{
query = descending ?
query.OrderByDescending(c => EF.Property<object>(c, orderingPropertyName)) :
query.OrderBy(c => EF.Property<object>(c, orderingPropertyName));
}
return await query.ToListAsync();
} }
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -62,7 +133,7 @@ namespace EFManager
public Task<int> GetNbItemsByCharacteristic(string charName) public Task<int> GetNbItemsByCharacteristic(string charName)
{ {
throw new NotImplementedException(); return await context.Where(c => c.Characteristics.Any(ch => ch.Name == charName)).CountAsync();
} }
public Task<int> GetNbItemsByClass(ChampionClass championClass) public Task<int> GetNbItemsByClass(ChampionClass championClass)

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFManager
{
internal class ManagerRune
{
}
}

@ -11,6 +11,6 @@ namespace EFlib
{ {
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public SkillType SkillType { get; set; } public SkillType Type { get; set; }
} }
} }

@ -1,13 +1,16 @@
namespace EFlib using Model;
namespace EFlib
{ {
public class EFSkin public class EFSkin
{ {
/**** Attributs ****/ /**** Attributs ****/
public string Name { get; set; } public string Name { get; set; }
public EFChampion champion { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public float Price { get; set; } public float Price { get; set; }
public EFChampion champion { get; set; } public LargeImage Image { get; set; }
} }
} }

@ -13,7 +13,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

@ -1,16 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace EFlib
{
internal class SqlServerContext : DbContext
{
/**** Attributs ****/
public DbSet<EFChampion> Champions { get; set; }
/**** Méthodes ****/
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer($"@\"Server=(localdb)\\mssqllocaldb;Database=projet.dbloulou.mdf;");
}
}
}

@ -15,7 +15,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

@ -9,7 +9,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

@ -9,7 +9,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Loading…
Cancel
Save