diff --git a/Sources/Api-lol/Controllers/Champions.cs b/Sources/Api-lol/Controllers/Champions.cs index 09b7eb1..9a2b8a0 100644 --- a/Sources/Api-lol/Controllers/Champions.cs +++ b/Sources/Api-lol/Controllers/Champions.cs @@ -36,6 +36,7 @@ namespace Api_lol.Controllers public IActionResult Post(DtoChampions champDTO) { Champion tmp = champDTO.DtoToModel(); + data.ChampionsMgr.AddItem(tmp); return Ok(); } @@ -45,9 +46,13 @@ namespace Api_lol.Controllers [Route("{name}")] public async Task GetChampion(string name) { - var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Where(i => i.Name == name).First(); - DtoChampions result = champs.ModelToDto(); - return Ok(champs); + Champion champion = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).First(i => i.Name == name); + if ( champion == null) + { + return BadRequest(); + } + DtoChampions result = champion.ModelToDto(); + return Ok(result); } } diff --git a/Sources/Api-lol/Controllers/WeatherForecastController.cs b/Sources/Api-lol/Controllers/WeatherForecastController.cs deleted file mode 100644 index 3062377..0000000 --- a/Sources/Api-lol/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Api_lol.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/Sources/Api-lol/WeatherForecast.cs b/Sources/Api-lol/WeatherForecast.cs deleted file mode 100644 index f17e950..0000000 --- a/Sources/Api-lol/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Api_lol -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file diff --git a/Sources/Client/Client.csproj b/Sources/Client/Client.csproj index 1df4500..45516cd 100644 --- a/Sources/Client/Client.csproj +++ b/Sources/Client/Client.csproj @@ -8,8 +8,11 @@ + + + diff --git a/Sources/Client/ClientChampions.cs b/Sources/Client/ClientChampions.cs index 3cb6789..4f5e838 100644 --- a/Sources/Client/ClientChampions.cs +++ b/Sources/Client/ClientChampions.cs @@ -11,23 +11,29 @@ namespace Client public class ClientChampions { private readonly HttpClient httpClient_client; - private readonly string urlConstant = "Champions/"; + private readonly string urlConstant = "https://localhost:7081/Champions/"; - public ClientChampions(HttpClient httpClient_client) + public ClientChampions() { - this.httpClient_client = httpClient_client; + this.httpClient_client = new HttpClient(); } - public async void Get() + public async Task> Get() { - await tmp = httpClient_client.GetFromJsonAsync(urlConstant); + var tmp = await httpClient_client.GetFromJsonAsync>(urlConstant); return tmp; } - public void Post(DtoChampions champions) + public async Task Post(DtoChampions champions) { + await httpClient_client.PostAsJsonAsync(urlConstant, champions); + } + public async Task GetChampion(string name) + { + var tmp = await httpClient_client.GetFromJsonAsync(urlConstant+name); + return tmp; } } } diff --git a/Sources/Client/Program.cs b/Sources/Client/Program.cs index 3751555..b799e30 100644 --- a/Sources/Client/Program.cs +++ b/Sources/Client/Program.cs @@ -1,2 +1,43 @@ // See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); + + +using Client; +using DTO; +using EntityFramwork; +using EntityFramwork.Factories; +using Model; +using StubLib; + +/* +StubData tmp = new StubData(); +var tmpListe = await tmp.ChampionsMgr.GetItemsByName("Akali", 0, 6); +Champion champ = tmpListe.First(); +Factories facto = new Factories(); +EntityChampions entity = facto.ModelToEntity(champ); + +using ( BDDContext context = new BDDContext()) +{ + context.Add(entity); + context.SaveChanges(); +} +*/ +Console.WriteLine("Start"); +Console.ReadLine(); + +ClientChampions client = new ClientChampions(); +List champions = await client.Get(); +DtoChampions champ = await client.GetChampion("Akali"); +Console.WriteLine(champions.Count); +Console.WriteLine(champ.name); + + +DtoChampions dtoTest = new DtoChampions("toto"); +await client.Post(dtoTest); + +List champions2 = await client.Get(); +Console.WriteLine(champions2.Count); +DtoChampions champ2 = await client.GetChampion("toto"); +Console.WriteLine(champ2.name); + +Console.WriteLine("End"); +Console.ReadLine(); \ No newline at end of file diff --git a/Sources/DTO/DtoChampions.cs b/Sources/DTO/DtoChampions.cs index d975043..ae2bbb0 100644 --- a/Sources/DTO/DtoChampions.cs +++ b/Sources/DTO/DtoChampions.cs @@ -8,7 +8,6 @@ namespace DTO { public class DtoChampions { - public long id { get; set; } public string name { get; set; } public DtoChampions(string name) diff --git a/Sources/DTO/EntityChampions.cs b/Sources/DTO/EntityChampions.cs deleted file mode 100644 index 6097f9f..0000000 --- a/Sources/DTO/EntityChampions.cs +++ /dev/null @@ -1,14 +0,0 @@ -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/BDD-APILOL.db b/Sources/EntityFramwork/BDD-APILOL.db new file mode 100644 index 0000000..01f0722 Binary files /dev/null and b/Sources/EntityFramwork/BDD-APILOL.db differ diff --git a/Sources/EntityFramwork/BDDContext.cs b/Sources/EntityFramwork/BDDContext.cs index 3d2f575..7f054ac 100644 --- a/Sources/EntityFramwork/BDDContext.cs +++ b/Sources/EntityFramwork/BDDContext.cs @@ -10,6 +10,7 @@ namespace EntityFramwork public DbSet Champions { get; set; } + public DbSet Skins { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/Sources/EntityFramwork/EntityChampions.cs b/Sources/EntityFramwork/EntityChampions.cs index 6097f9f..4708116 100644 --- a/Sources/EntityFramwork/EntityChampions.cs +++ b/Sources/EntityFramwork/EntityChampions.cs @@ -1,4 +1,5 @@ -using System; +using Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,7 +9,15 @@ namespace DTO { public class EntityChampions { - public long id { get; set; } - public string name { get; set; } + public long Id { get; set; } + + public string Name { get; set; } + + public string Bio { get; set; } + + public string Icon { get; set; } + + //public List Skins { get; set; } + } } diff --git a/Sources/EntityFramwork/EntityFramwork.csproj b/Sources/EntityFramwork/EntityFramwork.csproj index 0d77119..b4abec4 100644 --- a/Sources/EntityFramwork/EntityFramwork.csproj +++ b/Sources/EntityFramwork/EntityFramwork.csproj @@ -18,6 +18,11 @@ + + + + + diff --git a/Sources/EntityFramwork/EntitySkins.cs b/Sources/EntityFramwork/EntitySkins.cs new file mode 100644 index 0000000..17ac2a4 --- /dev/null +++ b/Sources/EntityFramwork/EntitySkins.cs @@ -0,0 +1,26 @@ +using DTO; +using Model; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramwork +{ + public class EntitySkins + { + public long Id { get; set; } + public string Description { get; set; } + + public string Icon { get; set; } + + public float Price { get; set; } + + [ForeignKey("ChampionsForeignKey")] + public EntityChampions EntityChampion { get; set; } + + public long ChampionsForeignKey { get;set; } + } +} diff --git a/Sources/EntityFramwork/Factories/Factories.cs b/Sources/EntityFramwork/Factories/Factories.cs new file mode 100644 index 0000000..3c8bdf3 --- /dev/null +++ b/Sources/EntityFramwork/Factories/Factories.cs @@ -0,0 +1,20 @@ +using DTO; +using Model; + +namespace EntityFramwork.Factories +{ + public class Factories + { + public EntityChampions ModelToEntity(Champion champ) + { + EntityChampions entity = new EntityChampions(); + + entity.Name = champ.Name; + entity.Bio = champ.Bio; + entity.Icon = champ.Icon; + //entity.Skins = new List(champ.Skins); + + return entity; + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs b/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs deleted file mode 100644 index 5230da3..0000000 --- a/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -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 deleted file mode 100644 index 4756e16..0000000 --- a/Sources/EntityFramwork/Migrations/20230130130012_monNomDeMigration.cs +++ /dev/null @@ -1,34 +0,0 @@ -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/20230201131800_migrationTest.Designer.cs b/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.Designer.cs new file mode 100644 index 0000000..364cbd8 --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.Designer.cs @@ -0,0 +1,69 @@ +// +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("20230201131800_migrationTest")] + partial class migrationTest + { + /// + 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("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs b/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs new file mode 100644 index 0000000..73050ce --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + /// + public partial class migrationTest : 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), + Bio = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Description = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champions"); + + migrationBuilder.DropTable( + name: "Skins"); + } + } +} diff --git a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs index e846958..832c08b 100644 --- a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs +++ b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs @@ -18,18 +18,48 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("DTO.EntityChampions", b => { - b.Property("id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); - b.Property("name") + b.Property("Bio") .IsRequired() .HasColumnType("TEXT"); - b.HasKey("id"); + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); b.ToTable("Champions"); }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Skins"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 0f305e3..4ee80bf 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{3 EndProject 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}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{B1BDE539-7DC3-4DC7-A908-36119E468FA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaireApi", "TestUnitaireApi\TestUnitaireApi.csproj", "{1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -61,6 +63,10 @@ Global {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 + {1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -68,6 +74,7 @@ Global GlobalSection(NestedProjects) = preSolution {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} + {1FB0F7BE-AEEE-42FD-BCE9-C11AE6923E6C} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} diff --git a/Sources/TestUnitaireApi/TestChampions.cs b/Sources/TestUnitaireApi/TestChampions.cs new file mode 100644 index 0000000..74d9427 --- /dev/null +++ b/Sources/TestUnitaireApi/TestChampions.cs @@ -0,0 +1,42 @@ +using Api_lol.Controllers; +using DTO; +using Microsoft.AspNetCore.Mvc; +using StubLib; +using System.Net.Http.Json; +using System.Reflection; + +namespace TestUnitaireApi +{ + public class TestChampions + { + StubData stubChamps; + Champions controlleurChampion; + + public TestChampions() + { + this.stubChamps = new StubData(); + this.controlleurChampion = new Champions(null,stubChamps); + } + + + [Fact] + public async Task TestGetChampions() + { + var liste = await controlleurChampion.Get(); + + OkObjectResult tmp = liste as OkObjectResult; + if (tmp == null) + { + Assert.Fail("Liste okObject == null"); + return; + } + IEnumerable listeChamp = tmp.Value as IEnumerable; + if (listeChamp == null) + { + Assert.Fail("Liste champ == null"); + return; + } + Assert.Equal(6,listeChamp.Count()); + } + } +} \ No newline at end of file diff --git a/Sources/TestUnitaireApi/TestUnitaireApi.csproj b/Sources/TestUnitaireApi/TestUnitaireApi.csproj new file mode 100644 index 0000000..e5b2034 --- /dev/null +++ b/Sources/TestUnitaireApi/TestUnitaireApi.csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/Sources/TestUnitaireApi/Usings.cs b/Sources/TestUnitaireApi/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestUnitaireApi/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file