From e40792b45b00810e69b21b7fccf12ec3dac60002 Mon Sep 17 00:00:00 2001 From: Louwar Date: Wed, 22 Mar 2023 13:27:03 +0100 Subject: [PATCH] Update Mapper EF & lib EF --- Sources/API/Mapping/RuneMapper.cs | 1 + Sources/API/Mapping/RunePageMapper.cs | 1 + Sources/EFMapping/EFChampionMapper.cs | 3 +- Sources/EFMapping/EFCharacteristicsMapper.cs | 11 +++++-- Sources/EFMapping/EFLargeImageMapper.cs | 14 ++++++++- Sources/EFMapping/EFSkillMapper.cs | 11 ++----- Sources/EFMapping/EFSkinMapper.cs | 27 +++++++++++------- Sources/EFlib/EFSkill.cs | 1 + ...=> 20230322115837_myMigration.Designer.cs} | 6 ++-- ...ation.cs => 20230322115837_myMigration.cs} | 26 ++++++++--------- .../Migrations/SQLiteContextModelSnapshot.cs | 4 +-- Sources/EFlib/projet.dbloulou.db | Bin 73728 -> 73728 bytes 12 files changed, 63 insertions(+), 42 deletions(-) rename Sources/EFlib/Migrations/{20230321114141_myMigration.Designer.cs => 20230322115837_myMigration.Designer.cs} (97%) rename Sources/EFlib/Migrations/{20230321114141_myMigration.cs => 20230322115837_myMigration.cs} (88%) diff --git a/Sources/API/Mapping/RuneMapper.cs b/Sources/API/Mapping/RuneMapper.cs index 5315396..876e091 100644 --- a/Sources/API/Mapping/RuneMapper.cs +++ b/Sources/API/Mapping/RuneMapper.cs @@ -2,5 +2,6 @@ { public class RuneMapper { + // TO DO } } diff --git a/Sources/API/Mapping/RunePageMapper.cs b/Sources/API/Mapping/RunePageMapper.cs index 3a21079..a093791 100644 --- a/Sources/API/Mapping/RunePageMapper.cs +++ b/Sources/API/Mapping/RunePageMapper.cs @@ -2,5 +2,6 @@ { public class RunePageMapper { + // TO DO } } diff --git a/Sources/EFMapping/EFChampionMapper.cs b/Sources/EFMapping/EFChampionMapper.cs index 58e9bd0..4053663 100644 --- a/Sources/EFMapping/EFChampionMapper.cs +++ b/Sources/EFMapping/EFChampionMapper.cs @@ -23,7 +23,6 @@ namespace EFMapping Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList() }; - } return EfChampion; @@ -31,7 +30,7 @@ namespace EFMapping public static Champion toModel(this EFChampion EFChamp) { - var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio); + var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, EFChamp.Image.Base64, EFChamp.Bio); if (EFChamp.Skills != null) foreach (var skill in EFChamp.Skills) { champion.AddSkill(skill.toModel()); } if (EFChamp.Characteristics != null) foreach (var charac in EFChamp.Characteristics) { champion.AddCharacteristics(charac.toModel()); } return champion; diff --git a/Sources/EFMapping/EFCharacteristicsMapper.cs b/Sources/EFMapping/EFCharacteristicsMapper.cs index 4559293..306a968 100644 --- a/Sources/EFMapping/EFCharacteristicsMapper.cs +++ b/Sources/EFMapping/EFCharacteristicsMapper.cs @@ -2,6 +2,7 @@ using Model; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -25,7 +26,13 @@ namespace EFMapping return EfCharacteristics; } - public static Tuple toModel(this EFCharacteristics charac) - => new(charac.Name, charac.Value); + public static ReadOnlyDictionary toModel(this EFCharacteristics charac) + { + var dict = new Dictionary + { + { charac.Name, charac.Value } + }; + return new(dict); + } } } diff --git a/Sources/EFMapping/EFLargeImageMapper.cs b/Sources/EFMapping/EFLargeImageMapper.cs index b9e02e7..0d41920 100644 --- a/Sources/EFMapping/EFLargeImageMapper.cs +++ b/Sources/EFMapping/EFLargeImageMapper.cs @@ -10,7 +10,19 @@ namespace EFMapping { public static class EFLargeImageMapper { - public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 }; + public static EFLargeImage toEF(this LargeImage LargeImage, SQLiteContext context) + { + var EfLargeImage = context.LargeImages.Find(LargeImage.Base64); + if (EfLargeImage == null) + { + return new() + { + Id = Guid.NewGuid(), + Base64 = LargeImage.Base64 + }; + } + return EfLargeImage; + } public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64); } } diff --git a/Sources/EFMapping/EFSkillMapper.cs b/Sources/EFMapping/EFSkillMapper.cs index e244c43..292c717 100644 --- a/Sources/EFMapping/EFSkillMapper.cs +++ b/Sources/EFMapping/EFSkillMapper.cs @@ -10,7 +10,7 @@ namespace EFMapping { public static class EFSkillMapper { - public static EFSkill toEF(this Skill skill, EFChampion champion, SQLiteContext context) + public static EFSkill toEF(this Skill skill, SQLiteContext context) { var EfSkill = context.Skills.Find(skill.Name); if (EfSkill == null) @@ -19,16 +19,11 @@ namespace EFMapping { Name = skill.Name, Description = skill.Description, - Type = skill.Type, - Champion = new List() { champion } + Type = skill.Type }; } - EfSkill!.Champions?.Add(champion); return EfSkill; } - - - public static Skill toModel(this EFSkill skill) - => new(skill.Name, skill.Type, skill.Description); + public static Skill toModel(this EFSkill skill)=> new(skill.Name, skill.Type, skill.Description); } } diff --git a/Sources/EFMapping/EFSkinMapper.cs b/Sources/EFMapping/EFSkinMapper.cs index 2dda7c0..641e3be 100644 --- a/Sources/EFMapping/EFSkinMapper.cs +++ b/Sources/EFMapping/EFSkinMapper.cs @@ -10,20 +10,25 @@ namespace EFMapping { public static class EFSkinMapper { - public static EFSkin toEF(this Skin skin, SQLiteContext? context = null) + public static EFSkin toEF(this Skin skin, SQLiteContext context) { - return new() + var EfSkin = context.Skins.Find(skin.Name); + if (EfSkin == null) { - Name = skin.Name, - Description = skin.Description, - Icon = skin.Icon, - Price = skin.Price, - Image = new() { Id = Guid.NewGuid(), Base64 = skin.Image.Base64 }, - NameChampion = skin.Champion.Name, - Champion = context?.Champions.Find(skin.Champion.Name) ?? skin.Champion.toEF(context), - }; + return new() + { + Name = skin.Name, + Description = skin.Description, + Icon = skin.Icon, + Price = skin.Price, + Image = new() { Id = Guid.NewGuid(), Base64 = skin.Image.Base64 }, + NameChampion = skin.Champion.Name, + Champion = context?.Champions.Find(skin.Champion.Name) ?? skin.Champion.toEF(context) + }; + } + return EfSkin; } - public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, null, Skin.Description); + public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, Skin.Icon, Skin.Image.Base64, Skin.Description); } } diff --git a/Sources/EFlib/EFSkill.cs b/Sources/EFlib/EFSkill.cs index b090479..16825bc 100644 --- a/Sources/EFlib/EFSkill.cs +++ b/Sources/EFlib/EFSkill.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs b/Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs similarity index 97% rename from Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs rename to Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs index 3a85b19..8d749e0 100644 --- a/Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs +++ b/Sources/EFlib/Migrations/20230322115837_myMigration.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFlib.Migrations { [DbContext(typeof(SQLiteContext))] - [Migration("20230321114141_myMigration")] + [Migration("20230322115837_myMigration")] partial class myMigration { /// @@ -65,7 +65,7 @@ namespace EFlib.Migrations b.HasIndex("NameChampion"); - b.ToTable("EFCharacteristics"); + b.ToTable("Characteristics"); }); modelBuilder.Entity("EFlib.EFLargeImage", b => @@ -80,7 +80,7 @@ namespace EFlib.Migrations b.HasKey("Id"); - b.ToTable("EFLargeImage"); + b.ToTable("LargeImages"); }); modelBuilder.Entity("EFlib.EFSkill", b => diff --git a/Sources/EFlib/Migrations/20230321114141_myMigration.cs b/Sources/EFlib/Migrations/20230322115837_myMigration.cs similarity index 88% rename from Sources/EFlib/Migrations/20230321114141_myMigration.cs rename to Sources/EFlib/Migrations/20230322115837_myMigration.cs index 1536631..bbc31f9 100644 --- a/Sources/EFlib/Migrations/20230321114141_myMigration.cs +++ b/Sources/EFlib/Migrations/20230322115837_myMigration.cs @@ -12,7 +12,7 @@ namespace EFlib.Migrations protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "EFLargeImage", + name: "LargeImages", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), @@ -20,7 +20,7 @@ namespace EFlib.Migrations }, constraints: table => { - table.PrimaryKey("PK_EFLargeImage", x => x.Id); + table.PrimaryKey("PK_LargeImages", x => x.Id); }); migrationBuilder.CreateTable( @@ -37,15 +37,15 @@ namespace EFlib.Migrations { table.PrimaryKey("PK_Champions", x => x.Name); table.ForeignKey( - name: "FK_Champions_EFLargeImage_ImageId", + name: "FK_Champions_LargeImages_ImageId", column: x => x.ImageId, - principalTable: "EFLargeImage", + principalTable: "LargeImages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "EFCharacteristics", + name: "Characteristics", columns: table => new { Name = table.Column(type: "TEXT", maxLength: 250, nullable: false), @@ -54,9 +54,9 @@ namespace EFlib.Migrations }, constraints: table => { - table.PrimaryKey("PK_EFCharacteristics", x => x.Name); + table.PrimaryKey("PK_Characteristics", x => x.Name); table.ForeignKey( - name: "FK_EFCharacteristics_Champions_NameChampion", + name: "FK_Characteristics_Champions_NameChampion", column: x => x.NameChampion, principalTable: "Champions", principalColumn: "Name", @@ -103,9 +103,9 @@ namespace EFlib.Migrations principalColumn: "Name", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Skins_EFLargeImage_ImageId", + name: "FK_Skins_LargeImages_ImageId", column: x => x.ImageId, - principalTable: "EFLargeImage", + principalTable: "LargeImages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -116,8 +116,8 @@ namespace EFlib.Migrations column: "ImageId"); migrationBuilder.CreateIndex( - name: "IX_EFCharacteristics_NameChampion", - table: "EFCharacteristics", + name: "IX_Characteristics_NameChampion", + table: "Characteristics", column: "NameChampion"); migrationBuilder.CreateIndex( @@ -140,7 +140,7 @@ namespace EFlib.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "EFCharacteristics"); + name: "Characteristics"); migrationBuilder.DropTable( name: "Skills"); @@ -152,7 +152,7 @@ namespace EFlib.Migrations name: "Champions"); migrationBuilder.DropTable( - name: "EFLargeImage"); + name: "LargeImages"); } } } diff --git a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs index 468f77d..1e48e5f 100644 --- a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs @@ -62,7 +62,7 @@ namespace EFlib.Migrations b.HasIndex("NameChampion"); - b.ToTable("EFCharacteristics"); + b.ToTable("Characteristics"); }); modelBuilder.Entity("EFlib.EFLargeImage", b => @@ -77,7 +77,7 @@ namespace EFlib.Migrations b.HasKey("Id"); - b.ToTable("EFLargeImage"); + b.ToTable("LargeImages"); }); modelBuilder.Entity("EFlib.EFSkill", b => diff --git a/Sources/EFlib/projet.dbloulou.db b/Sources/EFlib/projet.dbloulou.db index 17e385daba427f21a72ffc165a841541c912a6c3..743b2966fe010ba651d1754b72dbc11dc91652e4 100644 GIT binary patch delta 456 zcmZoTz|wGlWkQz99R|Kj{A+oC^3CQ6=RL-?nMZ=tmaC1Oms5ysF`FRkJXTkhJDUXs z{8%>cVKHOW<>zA;_ts`?G|kLQNv-gVh8YN%iRr1ulQVhskolYMbL?l7 zO=4#k*VblisV+%O$^jXPY|Z5TTym4|bJyeRY3_!X0j=tHWz|Fc`uLnc#0A-n3=K^! SjLkQ{m;c8P=X}xU`2YZq#*=UW delta 486 zcmZoTz|wGlWkQz99tOTk{A+nX^UdV(=RLqRmxqT_ovVQDE5{$UZq|>ib*!o^dp1tg zW7&L%#f(u{oR3}HU!SqjHZw0JwZbzZ-qme#0-FpIkg{h}1W^fWN+7C|FiHGV> zUdSh*kD)K#5JQNwDUX$1Twb2BReN(H4-3)moP3Pe#8H`