diff --git a/Sources/EntityFrameWorkLib/ChampionEntity.cs b/Sources/EntityFrameWorkLib/ChampionEntity.cs index b3514c7..df9864d 100644 --- a/Sources/EntityFrameWorkLib/ChampionEntity.cs +++ b/Sources/EntityFrameWorkLib/ChampionEntity.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Shared; @@ -13,16 +14,22 @@ namespace EntityFrameWorkLib public int UniqueId { get; set; } public string Name { get; set; } - [Required] + //[Required] [MaxLength(256)] public string Bio { get; set; } public string Icon { get; set; } - [Required] + //[Required] public ChampionClass Class { get; set; } - public LargeImageEntity? LargeImageEntity { get; set; } + public Collection Skins { get; set; } + + public LargeImageEntity? LargeImage { get; set; } + + public HashSet skills = new HashSet(); + + public Collection ListRunePages { get; set; } } } diff --git a/Sources/EntityFrameWorkLib/LargeImageEntity.cs b/Sources/EntityFrameWorkLib/LargeImageEntity.cs index 26d6886..0641a02 100644 --- a/Sources/EntityFrameWorkLib/LargeImageEntity.cs +++ b/Sources/EntityFrameWorkLib/LargeImageEntity.cs @@ -8,13 +8,13 @@ namespace EntityFrameWorkLib [Key] public Guid Id { get; set; } - [Required] + //[Required] public string Base64 { get; set; } - [Required] + //[Required] public int championId { get; set; } - [Required] + //[Required] public ChampionEntity champion { get; set; } } } diff --git a/Sources/EntityFrameWorkLib/LolContext.cs b/Sources/EntityFrameWorkLib/LolContext.cs index 8d2869c..bb2011f 100644 --- a/Sources/EntityFrameWorkLib/LolContext.cs +++ b/Sources/EntityFrameWorkLib/LolContext.cs @@ -9,6 +9,9 @@ namespace EntityFrameWorkLib public DbSet Champions { get; set; } public DbSet Skill { get; set; } public DbSet LargeImage { get; set; } + public DbSet Runes { get; set; } + public DbSet RunesPage { get; set; } + public DbSet Skins { get; set; } public LolContext() { } public LolContext(DbContextOptions options) @@ -25,18 +28,28 @@ namespace EntityFrameWorkLib protected override void OnModelCreating(ModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); //Définition de la clé primaire de ChampionEntity modelBuilder.Entity().HasKey(n => n.UniqueId); //Définition du mode de generation de la clé : génération à l'insertion modelBuilder.Entity().Property(n => n.UniqueId).ValueGeneratedOnAdd(); modelBuilder.Entity() - .HasOne(c => c.LargeImageEntity) + .HasOne(c => c.LargeImage) .WithOne(li => li.champion) .HasForeignKey(li => li.championId); - base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .Property(s => s.Name) + .ValueGeneratedOnAdd(); + + modelBuilder.Entity() + .Property(s => s.Id) + .ValueGeneratedOnAdd(); + modelBuilder.Entity() + .Property(s => s.Name) + .ValueGeneratedOnAdd(); } } diff --git a/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.Designer.cs b/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.Designer.cs new file mode 100644 index 0000000..003f7c7 --- /dev/null +++ b/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.Designer.cs @@ -0,0 +1,225 @@ +// +using System; +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + [DbContext(typeof(LolContext))] + [Migration("20230326210027_MyMigration")] + partial class MyMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.4"); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.Property("UniqueId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SkillEntityName") + .HasColumnType("TEXT"); + + b.HasKey("UniqueId"); + + b.HasIndex("SkillEntityName"); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("championId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("championId") + .IsUnique(); + + b.ToTable("LargeImage"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("RuneFamily") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Runes"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChampionEntityUniqueId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RuneEntityName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ChampionEntityUniqueId"); + + b.HasIndex("RuneEntityName"); + + b.ToTable("RunesPage"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("SkillType") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skill"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionEntityUniqueId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityUniqueId"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.HasOne("EntityFrameWorkLib.SkillEntity", null) + .WithMany("champions") + .HasForeignKey("SkillEntityName"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", "champion") + .WithOne("LargeImage") + .HasForeignKey("EntityFrameWorkLib.LargeImageEntity", "championId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("champion"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", null) + .WithMany("ListRunePages") + .HasForeignKey("ChampionEntityUniqueId"); + + b.HasOne("EntityFrameWorkLib.RuneEntity", null) + .WithMany("ListRunePages") + .HasForeignKey("RuneEntityName"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", null) + .WithMany("Skins") + .HasForeignKey("ChampionEntityUniqueId"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.Navigation("LargeImage"); + + b.Navigation("ListRunePages"); + + b.Navigation("Skins"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b => + { + b.Navigation("ListRunePages"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b => + { + b.Navigation("champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.cs b/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.cs new file mode 100644 index 0000000..a4c5f62 --- /dev/null +++ b/Sources/EntityFrameWorkLib/Migrations/20230326210027_MyMigration.cs @@ -0,0 +1,175 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + /// + public partial class MyMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Runes", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + RuneFamily = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Runes", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Skill", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + SkillType = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skill", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + UniqueId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Class = table.Column(type: "INTEGER", nullable: false), + SkillEntityName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.UniqueId); + table.ForeignKey( + name: "FK_Champions_Skill_SkillEntityName", + column: x => x.SkillEntityName, + principalTable: "Skill", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "LargeImage", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Base64 = table.Column(type: "TEXT", nullable: false), + championId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LargeImage", x => x.Id); + table.ForeignKey( + name: "FK_LargeImage_Champions_championId", + column: x => x.championId, + principalTable: "Champions", + principalColumn: "UniqueId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RunesPage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + ChampionEntityUniqueId = table.Column(type: "INTEGER", nullable: true), + RuneEntityName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_RunesPage", x => x.Id); + table.ForeignKey( + name: "FK_RunesPage_Champions_ChampionEntityUniqueId", + column: x => x.ChampionEntityUniqueId, + principalTable: "Champions", + principalColumn: "UniqueId"); + table.ForeignKey( + name: "FK_RunesPage_Runes_RuneEntityName", + column: x => x.RuneEntityName, + principalTable: "Runes", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false), + ChampionEntityUniqueId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + table.ForeignKey( + name: "FK_Skins_Champions_ChampionEntityUniqueId", + column: x => x.ChampionEntityUniqueId, + principalTable: "Champions", + principalColumn: "UniqueId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Champions_SkillEntityName", + table: "Champions", + column: "SkillEntityName"); + + migrationBuilder.CreateIndex( + name: "IX_LargeImage_championId", + table: "LargeImage", + column: "championId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_RunesPage_ChampionEntityUniqueId", + table: "RunesPage", + column: "ChampionEntityUniqueId"); + + migrationBuilder.CreateIndex( + name: "IX_RunesPage_RuneEntityName", + table: "RunesPage", + column: "RuneEntityName"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionEntityUniqueId", + table: "Skins", + column: "ChampionEntityUniqueId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "LargeImage"); + + migrationBuilder.DropTable( + name: "RunesPage"); + + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropTable( + name: "Runes"); + + migrationBuilder.DropTable( + name: "Champions"); + + migrationBuilder.DropTable( + name: "Skill"); + } + } +} diff --git a/Sources/EntityFrameWorkLib/Migrations/LolContextModelSnapshot.cs b/Sources/EntityFrameWorkLib/Migrations/LolContextModelSnapshot.cs new file mode 100644 index 0000000..a51d0b9 --- /dev/null +++ b/Sources/EntityFrameWorkLib/Migrations/LolContextModelSnapshot.cs @@ -0,0 +1,222 @@ +// +using System; +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + [DbContext(typeof(LolContext))] + partial class LolContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.4"); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.Property("UniqueId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SkillEntityName") + .HasColumnType("TEXT"); + + b.HasKey("UniqueId"); + + b.HasIndex("SkillEntityName"); + + b.ToTable("Champions"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("championId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("championId") + .IsUnique(); + + b.ToTable("LargeImage"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("RuneFamily") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Runes"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChampionEntityUniqueId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RuneEntityName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ChampionEntityUniqueId"); + + b.HasIndex("RuneEntityName"); + + b.ToTable("RunesPage"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("SkillType") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.ToTable("Skill"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionEntityUniqueId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityUniqueId"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.HasOne("EntityFrameWorkLib.SkillEntity", null) + .WithMany("champions") + .HasForeignKey("SkillEntityName"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.LargeImageEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", "champion") + .WithOne("LargeImage") + .HasForeignKey("EntityFrameWorkLib.LargeImageEntity", "championId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("champion"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RunePageEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", null) + .WithMany("ListRunePages") + .HasForeignKey("ChampionEntityUniqueId"); + + b.HasOne("EntityFrameWorkLib.RuneEntity", null) + .WithMany("ListRunePages") + .HasForeignKey("RuneEntityName"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkinEntity", b => + { + b.HasOne("EntityFrameWorkLib.ChampionEntity", null) + .WithMany("Skins") + .HasForeignKey("ChampionEntityUniqueId"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ChampionEntity", b => + { + b.Navigation("LargeImage"); + + b.Navigation("ListRunePages"); + + b.Navigation("Skins"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.RuneEntity", b => + { + b.Navigation("ListRunePages"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.SkillEntity", b => + { + b.Navigation("champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameWorkLib/RuneEntity.cs b/Sources/EntityFrameWorkLib/RuneEntity.cs index 6fca3d2..432bb2a 100644 --- a/Sources/EntityFrameWorkLib/RuneEntity.cs +++ b/Sources/EntityFrameWorkLib/RuneEntity.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using Shared; @@ -8,15 +9,17 @@ namespace EntityFrameWorkLib public class RuneEntity { [Key] - [MaxLength(256)] + //[MaxLength(256)] public string Name { get; set; } - [Required] + //[Required] [MaxLength(500)] public string Description { get; set; } - [Required] + //[Required] public RuneFamily RuneFamily { get; set; } + + public Collection ListRunePages { get; set; } } } diff --git a/Sources/EntityFrameWorkLib/SkillEntity.cs b/Sources/EntityFrameWorkLib/SkillEntity.cs index e0a15e2..74c6b8d 100644 --- a/Sources/EntityFrameWorkLib/SkillEntity.cs +++ b/Sources/EntityFrameWorkLib/SkillEntity.cs @@ -10,12 +10,14 @@ namespace EntityFrameWorkLib [MaxLength(256)] public string Name { get; set; } - [Required] + //[Required] [MaxLength(500)] public string Description { get; set; } - [Required] + //[Required] public SkillType SkillType { get; set; } + + public HashSet champions { get; set; } } } diff --git a/Sources/EntityFrameWorkLib/SkinEntity.cs b/Sources/EntityFrameWorkLib/SkinEntity.cs index 6be476d..fdbd9e8 100644 --- a/Sources/EntityFrameWorkLib/SkinEntity.cs +++ b/Sources/EntityFrameWorkLib/SkinEntity.cs @@ -9,13 +9,13 @@ namespace EntityFrameWorkLib [MaxLength(256)] public string Name { get; set; } - [Required] + //[Required] [MaxLength(500)] public string Description { get; set; } public string Icon { get; set; } - [Required] + //[Required] public float Price { get; set; } } } diff --git a/Sources/Tests/ConsoleDB/Program.cs b/Sources/Tests/ConsoleDB/Program.cs index 8f0a4b9..5983f08 100644 --- a/Sources/Tests/ConsoleDB/Program.cs +++ b/Sources/Tests/ConsoleDB/Program.cs @@ -22,7 +22,7 @@ ChampionEntity jax = new ChampionEntity Icon = "icon jax", Bio = "test bio jax", Class = ChampionClass.Fighter, - LargeImageEntity = largeImage + LargeImage = largeImage }; ChampionEntity darius = new ChampionEntity { diff --git a/Sources/Tests/ConsoleDB/projet.Champions.db b/Sources/Tests/ConsoleDB/projet.Champions.db deleted file mode 100644 index 27306d0..0000000 Binary files a/Sources/Tests/ConsoleDB/projet.Champions.db and /dev/null differ diff --git a/Sources/WebApiLol/ChampionDTO.cs b/Sources/WebApiLol/ChampionDTO.cs index ca10c5b..653aaac 100644 --- a/Sources/WebApiLol/ChampionDTO.cs +++ b/Sources/WebApiLol/ChampionDTO.cs @@ -3,7 +3,6 @@ namespace WebApiLol { public class ChampionDTO { - public int UniqueId { get; set; } public string Name { get; set; } diff --git a/Sources/WebApiLol/ChampionPageDTO.cs b/Sources/WebApiLol/ChampionPageDTO.cs new file mode 100644 index 0000000..16bcafa --- /dev/null +++ b/Sources/WebApiLol/ChampionPageDTO.cs @@ -0,0 +1,15 @@ +using System; +namespace WebApiLol +{ + public class ChampionPageDTO + { + public IEnumerable Data { get; set; } + + public int Index { get; set; } + + public int Count { get; set; } + + public int TotalCount { get; set; } + } +} + diff --git a/Sources/WebApiLol/Controllers/ChampionController.cs b/Sources/WebApiLol/Controllers/ChampionController.cs index b463652..8a7b586 100644 --- a/Sources/WebApiLol/Controllers/ChampionController.cs +++ b/Sources/WebApiLol/Controllers/ChampionController.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; +using System.Xml.Linq; using Microsoft.AspNetCore.Mvc; +using Model; using StubLib; using WebApiLol.Converter; @@ -14,18 +17,35 @@ public class ChampionController : ControllerBase { private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); + private IChampionsManager _dataManager; private readonly ILogger _logger; - public ChampionController(ILogger logger) + public ChampionController(IDataManager manager,ILogger logger) { + _dataManager = manager.ChampionsMgr; _logger = logger; } [HttpGet] - public async Task Get() + [ProducesResponseType(typeof(ChampionPageDTO), 200)] + public async Task Get([FromQuery] int index = 0, int count = 10, string? name = "") { - var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems()); - return Ok(list.Select(champion => champion?.toDTO())); + _logger.LogInformation($"methode Get de ControllerChampions appelée"); + int nbChampions = await _dataManager.GetNbItems(); + _logger.LogInformation($"Nombre de champions : {nbChampions}"); + var champs = (await _dataManager.GetItemsByName(name, index, int.MaxValue)) + .Where(champ => string.IsNullOrEmpty(name) || champ.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase)) + .Take(count) + .Select(Model => Model.toDTO()); + + var page = new ChampionPageDTO + { + Data = champs, + Index = index, + Count = champs.Count(), + TotalCount = nbChampions + }; + return Ok(page); } [HttpGet("name")] diff --git a/Sources/WebApiLol/Controllers/WeatherForecastController.cs b/Sources/WebApiLol/Controllers/WeatherForecastController.cs deleted file mode 100644 index 0e39eb8..0000000 --- a/Sources/WebApiLol/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -//using Microsoft.AspNetCore.Mvc; - -//namespace WebApiLol.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 = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), -// TemperatureC = Random.Shared.Next(-20, 55), -// Summary = Summaries[Random.Shared.Next(Summaries.Length)] -// }) -// .ToArray(); -// } -//} -