🚧 Beginning of link between DB and API
continuous-integration/drone/push Build is passing Details

API2
Nathan BOILEAU 2 years ago
commit 5aabac6125

@ -17,7 +17,11 @@ namespace EFLol
//public string Icon { get; set; }
//public LargeImage Image { get; set; }
//public ReadOnlyDictionary<string, int> Characteristics { get; private set; }
//private HashSet<Skill> skills = new HashSet<Skill>();
public ReadOnlyCollection<SkinEntity> Skins { get; set; }
}
public HashSet<SkillEntity> skills = new HashSet<SkillEntity>();
public Collection<SkinEntity> Skins { get; set; }
public Collection<RunePageEntity> ListRunePages { get; set; }
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace EFLol.DBDataManager
{
public static class DataConverter
{
public static Champion ChampionToPoco(this ChampionEntity champion)
{
return new Champion(champion.Name, champion.Bio);
}
public static ChampionEntity ChampionToEntity(this Champion champion)
{
return new ChampionEntity
{
Name = champion.Name,
Bio = champion.Bio
};
}
}
}

@ -0,0 +1,132 @@
using Model;
namespace EFLol.DBDataManager
{
public class EFDataManager : IDataManager
{
public IChampionsManager ChampionsMgr => new EFChampionManager();
public ISkinsManager SkinsMgr => throw new NotImplementedException();
public IRunesManager RunesMgr => throw new NotImplementedException();
public IRunePagesManager RunePagesMgr => throw new NotImplementedException();
}
public class EFChampionManager : IChampionsManager
{
private MyDbContext _context;
public async Task<Champion?> AddItem(Champion? item)
{
if (item == null)
{
return null;
}
var addItem = await _context.AddAsync(item);
await _context.SaveChangesAsync();
return addItem.Entity;
// Va chercher les info du context (Context.champions.get)(DbSet) et les map en champion model
// Dans Program.cs de API rajouter un scope (AddScope <IDataManager, EFDataManager>) -> Ca va dire que a chaque fois que j'utilise un IDataManager, il va créer un EFDataManager
}
public async Task<bool> DeleteItem(Champion? item)
{
if (item == null)
{
return false;
}
var deletedItem = _context.Remove(item);
await _context.SaveChangesAsync();
return true;
}
private Func<Champion, string, bool> filterByName = (champion, substring) =>
champion.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool @descending = false)
{
IEnumerable<Champion> champions = _context.Champions.Skip(index * count).Take(count).OrderBy(champion => orderingPropertyName).Select(champion => champion.ChampionToPoco());
return champions;
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null,
bool @descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null,
bool @descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null,
bool @descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool @descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null,
bool @descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool @descending = false)
{
throw new NotImplementedException();
}
}
}

@ -24,5 +24,10 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -11,8 +11,11 @@ namespace EFLol
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<SkillEntity> Skill { get; set; }
public DbSet<RunePageEntity> RunePages { get; set; }
public DbSet<RuneEntity> Runes { get; set; }
public MyDbContext()
public MyDbContext()
{ }
public MyDbContext(DbContextOptions<MyDbContext> options)
@ -32,6 +35,12 @@ namespace EFLol
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ChampionEntity>().Property(c => c.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<SkinEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
}
}
modelBuilder.Entity<SkillEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>().HasMany(p => p.skills).WithMany(p => p.champions).UsingEntity(j => j.ToTable("ChampionSkills"));
modelBuilder.Entity<RunePageEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<RuneEntity>().Property(s => s.Id).ValueGeneratedOnAdd();
}
}
}

@ -1,67 +1,105 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using EFLol;
using (var context = new MyDbContext())
internal class Program
{
// Clean the DB before starting
Console.WriteLine("Clean the DB before starting");
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
private static void Main(string[] args)
{
using (var context = new MyDbContext())
{
// Clean the DB before starting
Console.WriteLine("Clean the DB before starting");
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f };
SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f };
SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
ChampionEntity Zeus = new ChampionEntity
{
Name = "Zeus",
Bio = "Zeus is the god of the sky",
Skins = new ReadOnlyCollection<SkinEntity>(new List<SkinEntity> { black, white })
SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f };
SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f };
SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
};
ChampionEntity Hera = new ChampionEntity
{
Name = "Hera",
Bio = "Hera is the goddess of marriage",
Skins = new ReadOnlyCollection<SkinEntity>(new List<SkinEntity> { green })
};
ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" };
RuneEntity rune1 = new RuneEntity { Id = 1, Name = "rune1", Description = "super rune1" };
RuneEntity rune2 = new RuneEntity { Id = 2, Name = "rune2", Description = "super rune2" };
RuneEntity rune3 = new RuneEntity { Id = 3, Name = "rune3", Description = "super rune3" };
RunePageEntity runePage1 = new RunePageEntity { Id = 1, Name = "runepage1"/*, Runes = new Dictionary<Category, RuneEntity> { { Category.Major, rune1 } }*/ };
ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the god of the sky", Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white }) };
ChampionEntity Hera = new ChampionEntity { Name = "Hera", Bio = "Hera is the goddess of marriage", Skins = new Collection<SkinEntity>(new List<SkinEntity> { green }) };
ChampionEntity Poseidon = new ChampionEntity {
Name = "Poseidon", Bio = "Poseidon is the god of the sea",
ListRunePages = new Collection<RunePageEntity>(new List<RunePageEntity> { { runePage1 } })
};
using (var context = new MyDbContext())
{
// Crée des champions et les insère dans la base
Console.WriteLine("Creates and inserts new Champions");
context.Add(Zeus);
context.Add(Hera);
context.Add(Poseidon);
context.SaveChanges();
}
SkillEntity skill1 = new SkillEntity
{
Id = 1,
Name = "skill1",
Description = "super skill",
SkillType = SkillTypeEntity.Basic,
champions = new HashSet<ChampionEntity> { Zeus, Hera }
};
SkillEntity skill2 = new SkillEntity
{
Id = 2,
Name = "skill2",
Description = "super skill",
SkillType = SkillTypeEntity.Basic,
champions = new HashSet<ChampionEntity> { Zeus}
};
using (var context = new MyDbContext())
{
foreach (var n in context.Champions)
{
// Use LINQ to display the skins for each champion
var skins = from s in context.Skins
where n.Id == s.Id
select s;
Console.WriteLine($"Champion n°{n.Id} - {n.Name}");
}
context.SaveChanges();
}
Zeus.skills.Add(skill1);
Zeus.skills.Add(skill2);
using (var context = new MyDbContext())
{
foreach (var n in context.Skins)
{
Console.WriteLine($"Skin n°{n.Id} - {n.Name}" + (n.Price != null ? $" - {n.Price}" : ""));
}
context.SaveChanges();
Hera.skills.Add(skill1);
using (var context = new MyDbContext())
{
Console.WriteLine("Creates and inserts new Champions");
context.Add(Zeus);
context.Add(Hera);
context.Add(Poseidon);
context.Add(skill1);
context.Add(skill2);
context.SaveChanges();
}
using (var context = new MyDbContext())
{
foreach (var n in context.Champions)
{
// LINQ to select the skins of the current champion
var skins = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.Skins);
var runePage = context.Champions.Where(c => c.Id == n.Id).SelectMany(c => c.ListRunePages);
// Display the champion and its skins
Console.WriteLine($"Champion n°{n.Id} - {n.Name} : {skins.Count()} skins, {runePage.Count()} runePage");
}
context.SaveChanges();
}
using (var context = new MyDbContext())
{
foreach (var n in context.Skins)
{
Console.WriteLine($"Skin n°{n.Id} - {n.Name}" + (n.Price != null ? $" - {n.Price}" : ""));
}
context.SaveChanges();
}
using (var context = new MyDbContext())
{
foreach (var n in context.RunePages)
{
Console.WriteLine($"runePage n°{n.Id} - {n.Name}");
}
context.SaveChanges();
}
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFLol
{
public class RuneEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public RuneFamilyEntity RuneFamily { get; set; }
public Collection<RunePageEntity> ListRunePages { get; set; }
}
public enum RuneFamilyEntity
{
Unknown,
Precision,
Domination
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFLol
{
public class RunePageEntity
{
public int Id { get; set; }
public String Name { get; set; }
//public Dictionary<Category, RuneEntity> Runes { get; set; }
}
public enum Category
{
Major,
Minor1,
Minor2,
Minor3,
OtherMinor1,
OtherMinor2
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFLol
{
public class SkillEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public SkillTypeEntity SkillType { get; set; }
public HashSet<ChampionEntity> champions { get; set; }
}
public enum SkillTypeEntity
{
Unknown,
Basic,
Passive,
Ultimate
}
}

@ -35,10 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUnitaire", "TestUnitair
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LolApp", "LolApp\LolApp.csproj", "{0C898A04-092A-49AA-BE65-8AE818A2AF50}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewModels", "ViewModels\ViewModels.csproj", "{0ECDCB33-39F0-444B-B787-2EFDD9422870}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -73,16 +69,6 @@ Global
{5702F240-97BD-4757-918C-6E485C57D0EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5702F240-97BD-4757-918C-6E485C57D0EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5702F240-97BD-4757-918C-6E485C57D0EC}.Release|Any CPU.Build.0 = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Build.0 = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Deploy.0 = Release|Any CPU
{0ECDCB33-39F0-444B-B787-2EFDD9422870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0ECDCB33-39F0-444B-B787-2EFDD9422870}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0ECDCB33-39F0-444B-B787-2EFDD9422870}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0ECDCB33-39F0-444B-B787-2EFDD9422870}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -53,7 +53,13 @@ public class Champion : IEquatable<Champion>
Skins = new ReadOnlyCollection<Skin>(skins);
}
public ReadOnlyCollection<Skin> Skins { get; private set; }
public Champion(string name, string bio)
{
this.name = name;
this.bio = bio;
}
public ReadOnlyCollection<Skin> Skins { get; private set; }
private List<Skin> skins = new ();
public ReadOnlyDictionary<string, int> Characteristics { get; private set; }

@ -1,6 +1,7 @@
using EFLol;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System.Collections.ObjectModel;
namespace TestUnitaire
{
@ -9,14 +10,14 @@ namespace TestUnitaire
[Theory]
[InlineData("Zeus", "Dieu de la foudre", true)]
[InlineData("Hades", "Dieu des enfers", true)]
[InlineData("Aphrodite", "Déesse de l'amour", true)]
[InlineData("AresAresAresAresAresAresAresAresAresAres",
[InlineData(0,"Zeus", "Dieu de la foudre", true)]
[InlineData(10,"Hades", "Dieu des enfers", true)]
[InlineData(1,"Aphrodite", "Déesse de l'amour", true)]
[InlineData(10,"AresAresAresAresAresAresAresAresAresAres",
"Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" +
"Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" +
"Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre", false)]
public async Task TestAddInMemory(String name, String bio, bool expected)
public async Task TestAddChampionInMemory(int id, String name, String bio, bool expected)
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -28,11 +29,20 @@ namespace TestUnitaire
using (var context = new MyDbContext(options))
{
await context.Database.EnsureCreatedAsync();
var Dieu = new ChampionEntity
SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f };
SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f };
SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f };
RunePageEntity runePage1 = new RunePageEntity { Id = 1, Name = "runepage1"};
var Dieu = new ChampionEntity
{
Id = id,
Name = name,
Bio = bio
};
Bio = bio,
Skins = new Collection<SkinEntity>(new List<SkinEntity> { black, white, green }),
ListRunePages = new Collection<RunePageEntity>(new List<RunePageEntity> { { runePage1 } })
};
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
Assert.Null(found);
@ -45,24 +55,26 @@ namespace TestUnitaire
Assert.Equal(1, await context.Champions.CountAsync());
Assert.Equal(name, found.Name);
Assert.Equal(3,found.Skins.Count);
Assert.Equal(1, found.ListRunePages.Count);
// Test if the max length of the name is respected (30) and the max length of the bio is respected (256)
if (expected)
// Test if the max length of the name is respected (30) and the max length of the bio is respected (256)
if (expected)
{
Assert.True(found.Name.Length <= 30);
Assert.True(found.Bio.Length <= 256);
}
else
{
Assert.False(found.Bio.Length <= 256);
Assert.False(found.Name.Length <= 30);
Assert.False(found.Bio.Length <= 256);
}
}
}
[Fact]
public void ModifyTestInMemory()
public void TestModifyChampionInMemory()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -79,7 +91,7 @@ namespace TestUnitaire
ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." };
ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." };
ChampionEntity ewok = new ChampionEntity { Name = "Ewok", Bio = "Zeus is the king of the gods." };
ChampionEntity ewok = new ChampionEntity {Name = "Ewok", Bio = "Zeus is the king of the gods." };
context.Champions.Add(chewie);
@ -113,5 +125,54 @@ namespace TestUnitaire
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
}
}
}
[Theory]
[InlineData(0,"black", "super Skin", "icon1.png",190000000.2f,true)]
[InlineData(1,"White", "skin1", "icon1", 19, true)]
[InlineData(2,"Green", "skin", "icon1.jpg", -1, false)]
public async Task TestAddSkinToChampionInMemory(int id,String name, String description, String icon,float price,bool expected)
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new MyDbContext(options))
{
await context.Database.EnsureCreatedAsync();
var Dieu = new ChampionEntity
{
Id = 0,
Name = "Zeus",
Bio = "Dieu de la foudre",
Skins = new Collection<SkinEntity>()
};
SkinEntity item = new SkinEntity
{
Id = id,
Name = name,
Description = description,
Icon = icon,
Price = price
};
Dieu.Skins.Add(item);
ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus");
Assert.Null(found);
await context.Champions.AddAsync(Dieu);
await context.SaveChangesAsync();
found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name);
}
}
}
}

@ -12,12 +12,13 @@ namespace apiLOL.Controllers
public class ControllerChampions : Controller
{
private readonly IDataManager _data;
//private readonly IDataManager data;
private IChampionsManager _dataManager;
private readonly ILogger _logger;
public ControllerChampions(IDataManager manager, ILogger<ControllerChampions> log)
{
_data = manager;
_dataManager = manager.ChampionsMgr;
_logger = log;
}
@ -26,18 +27,17 @@ namespace apiLOL.Controllers
[ProducesResponseType(typeof(ChampionPageDTO), 200)]
public async Task<IActionResult> Get([FromQuery] int index = 0, int count = 10, string? name = "")
{
_logger.LogInformation($"methode Get de ControllerChampions appelée index:{index}, count: {count} et name:{name}");
int nbChampions = await _data.ChampionsMgr.GetNbItems();
//FromQuery permet de filtrer dans la collection de champions en fonction du nom
// Possible de faire une classe PageRequest pour gérer les paramètres index et count
_logger.LogInformation($"methode Get de ControllerChampions appelée");
int nbChampions = await _dataManager.GetNbItems();
_logger.LogInformation($"Nombre de champions : {nbChampions}");
var champions = await _data.ChampionsMgr.GetItems(index, nbChampions);
var filteredChampions = champions.Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count);
var championDTO = filteredChampions.Select(Model => Model.ToDTO());
var champs = (await _dataManager.GetItems(index, count)).Select(Model => Model.ToDTO());
var page = new ChampionPageDTO
{
Data = championDTO,
Data = champs,
Index = index,
Count = count,
TotalCount = nbChampions
@ -54,7 +54,7 @@ namespace apiLOL.Controllers
_logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}");
try
{
var champs = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1));
var champs = (await _dataManager.GetItemsByName(name, 0, 1));
return Ok(champs.First().ToDTO());
}
catch (Exception ex)
@ -72,7 +72,7 @@ namespace apiLOL.Controllers
try
{
Champion tmp = champDTO.ToModel();
Champion champion = await _data.ChampionsMgr.AddItem(tmp);
Champion champion = await _dataManager.AddItem(tmp);
ChampionDTO dtoChamp = champion.ToDTO();
return CreatedAtAction(nameof(GetChampion), new {name = dtoChamp.Name}, dtoChamp);
}
@ -91,7 +91,7 @@ namespace apiLOL.Controllers
try
{
var champs = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
var champs = (await _dataManager.GetItemsByName(name, 0, 1)).First();
champs.Bio = bio;
return Ok(champs.ToDTO());
}
@ -109,8 +109,8 @@ namespace apiLOL.Controllers
try
{
var champ = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
await _data.ChampionsMgr.DeleteItem(champ);
var champ = (await _dataManager.GetItemsByName(name, 0, 1)).First();
_dataManager.DeleteItem(champ);
return Ok(champ.ToDTO());
}
catch (Exception ex)

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.Mvc;
using EFLol.DBDataManager;
using Model;
using StubLib;
@ -12,7 +13,8 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager, StubData>();
//builder.Services.AddSingleton<IDataManager,StubData>();
builder.Services.AddScoped<IDataManager, EFDataManager>();
// Scoped et Transient sont des types de cycle de vie
// Transient : une instance a chaque contruction d'objet
// Scoped : une instance par requete client
@ -35,6 +37,7 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();

Loading…
Cancel
Save