diff --git a/Sources/Api-lol/Controllers/Champions.cs b/Sources/Api-lol/Controllers/Champions.cs index f7fd835..09b7eb1 100644 --- a/Sources/Api-lol/Controllers/Champions.cs +++ b/Sources/Api-lol/Controllers/Champions.cs @@ -14,46 +14,40 @@ namespace Api_lol.Controllers { private readonly IDataManager data; - private readonly ILogger _logger; + private readonly ILogger logger; + public Champions(ILogger logger,IDataManager manager) { - _logger = logger; + this.logger = logger; data = manager; } [HttpGet] - public IActionResult Get() + public async Task Get() { - List champs = new List(); - champs = data.ChampionsMgr.GetItems(0,6); - + var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ModelToDto()); + return Ok(champs); } [HttpPost] - public IActionResult Post(DtoChampions champHttp) + public IActionResult Post(DtoChampions champDTO) { - champ.Add(champHttp.DtoToModel()); - return Ok(champ); + Champion tmp = champDTO.DtoToModel(); + return Ok(); } [HttpGet] [Route("{name}")] - public IActionResult GetChampion(string name) + public async Task GetChampion(string name) { - foreach (var champion in data.ChampionsMgr.GetItems(0, data.ChampionsMgr.GetNbItems) - { - if (champion.Name == name) - { - - return Ok(champion); - } - } - return BadRequest("Name incorrect"); + var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Where(i => i.Name == name).First(); + DtoChampions result = champs.ModelToDto(); + return Ok(champs); } } diff --git a/Sources/Client/Client.csproj b/Sources/Client/Client.csproj new file mode 100644 index 0000000..1df4500 --- /dev/null +++ b/Sources/Client/Client.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + diff --git a/Sources/Client/ClientChampions.cs b/Sources/Client/ClientChampions.cs new file mode 100644 index 0000000..3cb6789 --- /dev/null +++ b/Sources/Client/ClientChampions.cs @@ -0,0 +1,33 @@ +using DTO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Json; +using System.Text; +using System.Threading.Tasks; + +namespace Client +{ + public class ClientChampions + { + private readonly HttpClient httpClient_client; + private readonly string urlConstant = "Champions/"; + + public ClientChampions(HttpClient httpClient_client) + { + this.httpClient_client = httpClient_client; + } + + + public async void Get() + { + await tmp = httpClient_client.GetFromJsonAsync(urlConstant); + return tmp; + } + + public void Post(DtoChampions champions) + { + + } + } +} diff --git a/Sources/Client/Program.cs b/Sources/Client/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Sources/Client/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Sources/DTO/Class1.cs b/Sources/DTO/Class1.cs deleted file mode 100644 index a440c7c..0000000 --- a/Sources/DTO/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DTO -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/Sources/DTO/EntityChampions.cs b/Sources/DTO/EntityChampions.cs new file mode 100644 index 0000000..6097f9f --- /dev/null +++ b/Sources/DTO/EntityChampions.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class EntityChampions + { + public long id { get; set; } + public string name { get; set; } + } +} diff --git a/Sources/EntityFramwork/BDDContext.cs b/Sources/EntityFramwork/BDDContext.cs index f8ef07b..3d2f575 100644 --- a/Sources/EntityFramwork/BDDContext.cs +++ b/Sources/EntityFramwork/BDDContext.cs @@ -5,10 +5,11 @@ namespace EntityFramwork { public class BDDContext : DbContext { + public BDDContext() { } public BDDContext(DbContextOptions option) : base(option) { } - public DbSet Champions { get; set; } + public DbSet Champions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/Sources/EntityFramwork/EntityChampions.cs b/Sources/EntityFramwork/EntityChampions.cs new file mode 100644 index 0000000..6097f9f --- /dev/null +++ b/Sources/EntityFramwork/EntityChampions.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class EntityChampions + { + public long id { get; set; } + public string name { get; set; } + } +} diff --git a/Sources/EntityFramwork/EntityFramwork.csproj b/Sources/EntityFramwork/EntityFramwork.csproj index 085c177..0d77119 100644 --- a/Sources/EntityFramwork/EntityFramwork.csproj +++ b/Sources/EntityFramwork/EntityFramwork.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + $(MSBuildProjectDirectory) diff --git a/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs b/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs new file mode 100644 index 0000000..5230da3 --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs @@ -0,0 +1,39 @@ +// +using EntityFramwork; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + [DbContext(typeof(BDDContext))] + [Migration("20230130130012_monNomDeMigration")] + partial class monNomDeMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.cs b/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.cs new file mode 100644 index 0000000..4756e16 --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + /// + public partial class monNomDeMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champions"); + } + } +} diff --git a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs new file mode 100644 index 0000000..e846958 --- /dev/null +++ b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs @@ -0,0 +1,36 @@ +// +using EntityFramwork; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + [DbContext(typeof(BDDContext))] + partial class BDDContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index c78cfc3..0f305e3 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -19,7 +19,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api-lol", "Api-lol\Api-lol. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramwork", "EntityFramwork\EntityFramwork.csproj", "{2225E38B-8445-40D2-A2FE-9F90F7ACD463}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramwork", "EntityFramwork\EntityFramwork.csproj", "{2225E38B-8445-40D2-A2FE-9F90F7ACD463}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{B1BDE539-7DC3-4DC7-A908-36119E468FA8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,6 +57,10 @@ Global {2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Debug|Any CPU.Build.0 = Debug|Any CPU {2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Release|Any CPU.ActiveCfg = Release|Any CPU {2225E38B-8445-40D2-A2FE-9F90F7ACD463}.Release|Any CPU.Build.0 = Release|Any CPU + {B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1BDE539-7DC3-4DC7-A908-36119E468FA8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE