diff --git a/.drone.yml b/.drone.yml index d445b9b..02f2027 100644 --- a/.drone.yml +++ b/.drone.yml @@ -54,7 +54,7 @@ steps: dockerfile: Sources/Trek12_API/Dockerfile context: Sources/ registry: hub.codefirst.iut.uca.fr - repo: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API + repo: hub.codefirst.iut.uca.fr/trek_prod/trek12_api username: from_secret: SECRET_REGISTRY_USERNAME password: @@ -64,7 +64,7 @@ steps: - name: deploy-container image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest environment: - IMAGENAME: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API:latest + IMAGENAME: hub.codefirst.iut.uca.fr/trek_prod/trek12_api:latest CONTAINERNAME: trek12api COMMAND: create OVERWRITE: true diff --git a/Sources/Tests/DbConsole/DbConsole.csproj b/Sources/Tests/DbConsole/DbConsole.csproj index 92c43c9..ed572bd 100644 --- a/Sources/Tests/DbConsole/DbConsole.csproj +++ b/Sources/Tests/DbConsole/DbConsole.csproj @@ -9,12 +9,15 @@ + + + diff --git a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs deleted file mode 100644 index 629e956..0000000 --- a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.Designer.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DbConsole.Migrations -{ - [DbContext(typeof(SQLiteContext))] - [Migration("20230212153116_MyMigration")] - partial class MyMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => - { - b.Property("PlayerId") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("MaxPoints") - .HasColumnType("INTEGER"); - - b.Property("MaxZone") - .HasColumnType("INTEGER"); - - b.Property("NbPlayed") - .HasColumnType("INTEGER"); - - b.Property("NbPoints") - .HasColumnType("INTEGER"); - - b.Property("NbWin") - .HasColumnType("INTEGER"); - - b.Property("Pseudo") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("PlayerId"); - - b.ToTable("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs b/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs deleted file mode 100644 index 98d2699..0000000 --- a/Sources/Tests/DbConsole/Migrations/20230212153116_MyMigration.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DbConsole.Migrations -{ - /// - public partial class MyMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Players", - columns: table => new - { - PlayerId = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Pseudo = table.Column(type: "TEXT", nullable: false), - NbWin = table.Column(type: "INTEGER", nullable: false), - NbPlayed = table.Column(type: "INTEGER", nullable: false), - MaxZone = table.Column(type: "INTEGER", nullable: false), - MaxPoints = table.Column(type: "INTEGER", nullable: false), - NbPoints = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Players", x => x.PlayerId); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Players"); - } - } -} diff --git a/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.Designer.cs b/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.Designer.cs new file mode 100644 index 0000000..90b7534 --- /dev/null +++ b/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.Designer.cs @@ -0,0 +1,175 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbConsole.Migrations +{ + [DbContext(typeof(SQLiteContext))] + [Migration("20230320170448_AllMigrations")] + partial class AllMigrations + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => + { + b.Property("CaseId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("CaseId"); + + b.ToTable("Case"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b => + { + b.Property("GameId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.HasKey("GameId"); + + b.ToTable("Game"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b => + { + b.Property("GrilleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxChain") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbChains") + .HasColumnType("INTEGER"); + + b.Property("NbZones") + .HasColumnType("INTEGER"); + + b.HasKey("GrilleId"); + + b.ToTable("Grille"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameId") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("PlayerId") + .HasColumnType("INTEGER"); + + b.HasKey("ScoreId"); + + b.HasIndex("GameId"); + + b.HasIndex("PlayerId"); + + b.ToTable("Score"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => + { + b.Property("TurnId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiceValue1") + .HasColumnType("INTEGER"); + + b.Property("DiceValue2") + .HasColumnType("INTEGER"); + + b.HasKey("TurnId"); + + b.ToTable("Turn"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.HasOne("EntityFrameWorkLib.GameEntity", "Game") + .WithMany() + .HasForeignKey("GameId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("PlayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Game"); + + b.Navigation("Player"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.cs b/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.cs new file mode 100644 index 0000000..96b4dd1 --- /dev/null +++ b/Sources/Tests/DbConsole/Migrations/20230320170448_AllMigrations.cs @@ -0,0 +1,151 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DbConsole.Migrations +{ + /// + public partial class AllMigrations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Case", + columns: table => new + { + CaseId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Value = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Case", x => x.CaseId); + }); + + migrationBuilder.CreateTable( + name: "Game", + columns: table => new + { + GameId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Duration = table.Column(type: "TEXT", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + NbPlayers = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Game", x => x.GameId); + }); + + migrationBuilder.CreateTable( + name: "Grille", + columns: table => new + { + GrilleId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + NbChains = table.Column(type: "INTEGER", nullable: false), + NbZones = table.Column(type: "INTEGER", nullable: false), + MaxChain = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Grille", x => x.GrilleId); + }); + + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + PlayerId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + NbWin = table.Column(type: "INTEGER", nullable: false), + NbPlayed = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false), + MaxPoints = table.Column(type: "INTEGER", nullable: false), + NbPoints = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.PlayerId); + }); + + migrationBuilder.CreateTable( + name: "Turn", + columns: table => new + { + TurnId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + DiceValue1 = table.Column(type: "INTEGER", nullable: false), + DiceValue2 = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Turn", x => x.TurnId); + }); + + migrationBuilder.CreateTable( + name: "Score", + columns: table => new + { + ScoreId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + NbPoints = table.Column(type: "INTEGER", nullable: false), + GameId = table.Column(type: "INTEGER", nullable: false), + PlayerId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Score", x => x.ScoreId); + table.ForeignKey( + name: "FK_Score_Game_GameId", + column: x => x.GameId, + principalTable: "Game", + principalColumn: "GameId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Score_Players_PlayerId", + column: x => x.PlayerId, + principalTable: "Players", + principalColumn: "PlayerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Score_GameId", + table: "Score", + column: "GameId"); + + migrationBuilder.CreateIndex( + name: "IX_Score_PlayerId", + table: "Score", + column: "PlayerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Case"); + + migrationBuilder.DropTable( + name: "Grille"); + + migrationBuilder.DropTable( + name: "Score"); + + migrationBuilder.DropTable( + name: "Turn"); + + migrationBuilder.DropTable( + name: "Game"); + + migrationBuilder.DropTable( + name: "Players"); + } + } +} diff --git a/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs b/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs index b5a68bd..2ee2875 100644 --- a/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/Tests/DbConsole/Migrations/SQLiteContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -15,6 +16,67 @@ namespace DbConsole.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => + { + b.Property("CaseId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("CaseId"); + + b.ToTable("Case"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b => + { + b.Property("GameId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.HasKey("GameId"); + + b.ToTable("Game"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b => + { + b.Property("GrilleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxChain") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbChains") + .HasColumnType("INTEGER"); + + b.Property("NbZones") + .HasColumnType("INTEGER"); + + b.HasKey("GrilleId"); + + b.ToTable("Grille"); + }); + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => { b.Property("PlayerId") @@ -44,6 +106,66 @@ namespace DbConsole.Migrations b.ToTable("Players"); }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameId") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("PlayerId") + .HasColumnType("INTEGER"); + + b.HasKey("ScoreId"); + + b.HasIndex("GameId"); + + b.HasIndex("PlayerId"); + + b.ToTable("Score"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => + { + b.Property("TurnId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiceValue1") + .HasColumnType("INTEGER"); + + b.Property("DiceValue2") + .HasColumnType("INTEGER"); + + b.HasKey("TurnId"); + + b.ToTable("Turn"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.HasOne("EntityFrameWorkLib.GameEntity", "Game") + .WithMany() + .HasForeignKey("GameId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("PlayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Game"); + + b.Navigation("Player"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/Tests/DbConsole/Program.cs b/Sources/Tests/DbConsole/Program.cs index c406084..cd00908 100644 --- a/Sources/Tests/DbConsole/Program.cs +++ b/Sources/Tests/DbConsole/Program.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; PlayerEntity p1 = new PlayerEntity { + PlayerId = 0, Pseudo = "Jax", NbWin = 0, NbPlayed = 0, @@ -11,8 +12,14 @@ PlayerEntity p1 = new PlayerEntity NbPoints = 0 }; +GameEntity g1 = new GameEntity +{ + GameId = 1, +}; + PlayerEntity p2 = new PlayerEntity { + PlayerId = 0, Pseudo = "Theo", NbWin = 0, NbPlayed = 0, @@ -21,12 +28,25 @@ PlayerEntity p2 = new PlayerEntity NbPoints = 0 }; -using (var context = new SQLiteContext()) +/*using (var context = new SQLiteContext()) { - Console.WriteLine("Create and Insert new Champion"); + Console.WriteLine("Create and Insert new Player"); context.Add(p1); context.Add(p2); context.SaveChanges(); +}*/ + +using (var context = new SQLiteContext()) +{ + var newScore = new ScoreEntity + { + GameId = 1, + PlayerId = 2, + NbPoints = 5 + }; + + context.Add(newScore); + context.SaveChanges(); } public class SQLiteContext : TrekContext @@ -35,7 +55,7 @@ public class SQLiteContext : TrekContext { if (!options.IsConfigured) { - options.UseSqlite($"Data Source=projet.Champions.db"); + options.UseSqlite($"Data Source=projet.ToutesTables.db"); } } } diff --git a/Sources/Tests/DbConsole/projet.Champions.db b/Sources/Tests/DbConsole/projet.Champions.db index bcf7203..67a5f99 100644 Binary files a/Sources/Tests/DbConsole/projet.Champions.db and b/Sources/Tests/DbConsole/projet.Champions.db differ diff --git a/Sources/Tests/DbConsole/projet.ToutesTables.db b/Sources/Tests/DbConsole/projet.ToutesTables.db new file mode 100644 index 0000000..4c892c4 Binary files /dev/null and b/Sources/Tests/DbConsole/projet.ToutesTables.db differ diff --git a/Sources/Tests/DbConsole/projet.ToutesTables.db-wal b/Sources/Tests/DbConsole/projet.ToutesTables.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/Sources/Trek12_API/Controllers/PlayerController.cs b/Sources/Trek12_API/Controllers/PlayerController.cs index 4b429ac..8b144e2 100644 --- a/Sources/Trek12_API/Controllers/PlayerController.cs +++ b/Sources/Trek12_API/Controllers/PlayerController.cs @@ -66,12 +66,12 @@ namespace Trek12_API.Controllers public async Task Delete(int idPlayer) { var playerToDelete = await playersManager.GetItemsById(idPlayer); - if (playerToDelete == null) + if(playerToDelete == null) { return NotFound("Joueur non trouvé"); } - if (!await playersManager.DeleteItem(playerToDelete.SingleOrDefault(p => p.Id == idPlayer))) + if(!await playersManager.DeleteItem(playerToDelete.SingleOrDefault(p => p.Id == idPlayer))) { return BadRequest("Erreur lors de la suppression du joueur"); } diff --git a/Sources/Trek12_Lib/CaseEntity.cs b/Sources/Trek12_Lib/CaseEntity.cs new file mode 100644 index 0000000..8a42c6c --- /dev/null +++ b/Sources/Trek12_Lib/CaseEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameWorkLib +{ + public class CaseEntity + { + public int CaseId { get; set; } + public int Value { get; set; } + } +} diff --git a/Sources/Trek12_Lib/GameEntity.cs b/Sources/Trek12_Lib/GameEntity.cs new file mode 100644 index 0000000..3648488 --- /dev/null +++ b/Sources/Trek12_Lib/GameEntity.cs @@ -0,0 +1,22 @@ +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; + +namespace EntityFrameWorkLib +{ + public class GameEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int GameId { get; set; } + public TimeSpan Duration { get; set; } + public DateOnly Date { get; set; } + public int NbPlayers { get; set; } + public string Name { get; set; } + //public ICollection NbPoints { get; set; } + } +} diff --git a/Sources/Trek12_Lib/GrilleEntity.cs b/Sources/Trek12_Lib/GrilleEntity.cs new file mode 100644 index 0000000..535437d --- /dev/null +++ b/Sources/Trek12_Lib/GrilleEntity.cs @@ -0,0 +1,21 @@ +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; + +namespace EntityFrameWorkLib +{ + public class GrilleEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int GrilleId { get; set; } + public int NbChains { get; set; } + public int NbZones { get; set; } + public int MaxChain { get; set; } + public int MaxZone { get; set; } + } +} diff --git a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs deleted file mode 100644 index 1eae5ae..0000000 --- a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.Designer.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -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(TrekContext))] - [Migration("20230212152210_MyMigration")] - partial class MyMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => - { - b.Property("PlayerId") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("MaxPoints") - .HasColumnType("INTEGER"); - - b.Property("MaxZone") - .HasColumnType("INTEGER"); - - b.Property("NbPlayed") - .HasColumnType("INTEGER"); - - b.Property("NbPoints") - .HasColumnType("INTEGER"); - - b.Property("NbWin") - .HasColumnType("INTEGER"); - - b.Property("Pseudo") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("PlayerId"); - - b.ToTable("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs b/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs deleted file mode 100644 index 704ad5f..0000000 --- a/Sources/Trek12_Lib/Migrations/20230212152210_MyMigration.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameWorkLib.Migrations -{ - /// - public partial class MyMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Players", - columns: table => new - { - PlayerId = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Pseudo = table.Column(type: "TEXT", nullable: false), - NbWin = table.Column(type: "INTEGER", nullable: false), - NbPlayed = table.Column(type: "INTEGER", nullable: false), - MaxZone = table.Column(type: "INTEGER", nullable: false), - MaxPoints = table.Column(type: "INTEGER", nullable: false), - NbPoints = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Players", x => x.PlayerId); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Players"); - } - } -} diff --git a/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.Designer.cs b/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.Designer.cs new file mode 100644 index 0000000..b99d4b8 --- /dev/null +++ b/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.Designer.cs @@ -0,0 +1,176 @@ +// +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(TrekContext))] + [Migration("20230320170231_AllMigrations")] + partial class AllMigrations + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => + { + b.Property("CaseId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("CaseId"); + + b.ToTable("Case"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b => + { + b.Property("GameId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.HasKey("GameId"); + + b.ToTable("Game"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b => + { + b.Property("GrilleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxChain") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbChains") + .HasColumnType("INTEGER"); + + b.Property("NbZones") + .HasColumnType("INTEGER"); + + b.HasKey("GrilleId"); + + b.ToTable("Grille"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => + { + b.Property("PlayerId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxPoints") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbPlayed") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("NbWin") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("PlayerId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameId") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("PlayerId") + .HasColumnType("INTEGER"); + + b.HasKey("ScoreId"); + + b.HasIndex("GameId"); + + b.HasIndex("PlayerId"); + + b.ToTable("Score"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => + { + b.Property("TurnId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiceValue1") + .HasColumnType("INTEGER"); + + b.Property("DiceValue2") + .HasColumnType("INTEGER"); + + b.HasKey("TurnId"); + + b.ToTable("Turn"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.HasOne("EntityFrameWorkLib.GameEntity", "Game") + .WithMany() + .HasForeignKey("GameId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("PlayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Game"); + + b.Navigation("Player"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.cs b/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.cs new file mode 100644 index 0000000..5790c46 --- /dev/null +++ b/Sources/Trek12_Lib/Migrations/20230320170231_AllMigrations.cs @@ -0,0 +1,151 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameWorkLib.Migrations +{ + /// + public partial class AllMigrations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Case", + columns: table => new + { + CaseId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Value = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Case", x => x.CaseId); + }); + + migrationBuilder.CreateTable( + name: "Game", + columns: table => new + { + GameId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Duration = table.Column(type: "TEXT", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + NbPlayers = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Game", x => x.GameId); + }); + + migrationBuilder.CreateTable( + name: "Grille", + columns: table => new + { + GrilleId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + NbChains = table.Column(type: "INTEGER", nullable: false), + NbZones = table.Column(type: "INTEGER", nullable: false), + MaxChain = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Grille", x => x.GrilleId); + }); + + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + PlayerId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + NbWin = table.Column(type: "INTEGER", nullable: false), + NbPlayed = table.Column(type: "INTEGER", nullable: false), + MaxZone = table.Column(type: "INTEGER", nullable: false), + MaxPoints = table.Column(type: "INTEGER", nullable: false), + NbPoints = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.PlayerId); + }); + + migrationBuilder.CreateTable( + name: "Turn", + columns: table => new + { + TurnId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + DiceValue1 = table.Column(type: "INTEGER", nullable: false), + DiceValue2 = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Turn", x => x.TurnId); + }); + + migrationBuilder.CreateTable( + name: "Score", + columns: table => new + { + ScoreId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + NbPoints = table.Column(type: "INTEGER", nullable: false), + GameId = table.Column(type: "INTEGER", nullable: false), + PlayerId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Score", x => x.ScoreId); + table.ForeignKey( + name: "FK_Score_Game_GameId", + column: x => x.GameId, + principalTable: "Game", + principalColumn: "GameId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Score_Players_PlayerId", + column: x => x.PlayerId, + principalTable: "Players", + principalColumn: "PlayerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Score_GameId", + table: "Score", + column: "GameId"); + + migrationBuilder.CreateIndex( + name: "IX_Score_PlayerId", + table: "Score", + column: "PlayerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Case"); + + migrationBuilder.DropTable( + name: "Grille"); + + migrationBuilder.DropTable( + name: "Score"); + + migrationBuilder.DropTable( + name: "Turn"); + + migrationBuilder.DropTable( + name: "Game"); + + migrationBuilder.DropTable( + name: "Players"); + } + } +} diff --git a/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs b/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs index a66ff04..c577c75 100644 --- a/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs +++ b/Sources/Trek12_Lib/Migrations/TrekContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using EntityFrameWorkLib; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -16,6 +17,67 @@ namespace EntityFrameWorkLib.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => + { + b.Property("CaseId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("CaseId"); + + b.ToTable("Case"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b => + { + b.Property("GameId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.HasKey("GameId"); + + b.ToTable("Game"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b => + { + b.Property("GrilleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MaxChain") + .HasColumnType("INTEGER"); + + b.Property("MaxZone") + .HasColumnType("INTEGER"); + + b.Property("NbChains") + .HasColumnType("INTEGER"); + + b.Property("NbZones") + .HasColumnType("INTEGER"); + + b.HasKey("GrilleId"); + + b.ToTable("Grille"); + }); + modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b => { b.Property("PlayerId") @@ -45,6 +107,66 @@ namespace EntityFrameWorkLib.Migrations b.ToTable("Players"); }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("GameId") + .HasColumnType("INTEGER"); + + b.Property("NbPoints") + .HasColumnType("INTEGER"); + + b.Property("PlayerId") + .HasColumnType("INTEGER"); + + b.HasKey("ScoreId"); + + b.HasIndex("GameId"); + + b.HasIndex("PlayerId"); + + b.ToTable("Score"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => + { + b.Property("TurnId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiceValue1") + .HasColumnType("INTEGER"); + + b.Property("DiceValue2") + .HasColumnType("INTEGER"); + + b.HasKey("TurnId"); + + b.ToTable("Turn"); + }); + + modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => + { + b.HasOne("EntityFrameWorkLib.GameEntity", "Game") + .WithMany() + .HasForeignKey("GameId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("PlayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Game"); + + b.Navigation("Player"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/Trek12_Lib/PlayerEntity.cs b/Sources/Trek12_Lib/PlayerEntity.cs index 174b399..516ca91 100644 --- a/Sources/Trek12_Lib/PlayerEntity.cs +++ b/Sources/Trek12_Lib/PlayerEntity.cs @@ -2,17 +2,19 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace EntityFrameWorkLib; -public class PlayerEntity +namespace EntityFrameWorkLib { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int PlayerId {get; set;} - public string Pseudo { get; set; } - public int NbWin { get; set; } - public int NbPlayed { get; set; } - public int MaxZone { get; set; } - public int MaxPoints { get; set; } - public int NbPoints { get; set; } + public class PlayerEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int PlayerId { get; set; } + public string Pseudo { get; set; } + public int NbWin { get; set; } + public int NbPlayed { get; set; } + public int MaxZone { get; set; } + public int MaxPoints { get; set; } + public int NbPoints { get; set; } + } } diff --git a/Sources/Trek12_Lib/ScoreEntity.cs b/Sources/Trek12_Lib/ScoreEntity.cs new file mode 100644 index 0000000..6e81feb --- /dev/null +++ b/Sources/Trek12_Lib/ScoreEntity.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameWorkLib +{ + public class ScoreEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ScoreId { get; set; } + public int NbPoints { get; set; } + + public int GameId { get; set; } + [ForeignKey("GameId")] + public GameEntity Game { get; set; } + + public int PlayerId { get; set; } + [ForeignKey("PlayerId")] + public PlayerEntity Player { get; set; } + } +} diff --git a/Sources/Trek12_Lib/TrekContext.cs b/Sources/Trek12_Lib/TrekContext.cs index d1d3a57..87d1a91 100644 --- a/Sources/Trek12_Lib/TrekContext.cs +++ b/Sources/Trek12_Lib/TrekContext.cs @@ -10,6 +10,16 @@ namespace EntityFrameWorkLib { public DbSet Players { get; set; } + public DbSet Game { get; set; } + + public DbSet Grille { get; set; } + + public DbSet Case { get; set; } + + public DbSet Turn { get; set; } + + public DbSet Score { get; set; } + public TrekContext() { } public TrekContext(DbContextOptions options) : base(options) @@ -18,21 +28,35 @@ namespace EntityFrameWorkLib { if (!options.IsConfigured) { - base.OnConfiguring(options.UseSqlite($"DataSource=projet.Players.db")); + base.OnConfiguring(options.UseSqlite($"DataSource=projet.AllTables.db")); } } + protected override void OnModelCreating(ModelBuilder modelBuilder) { //Définition de la clé primaire de PlayerEntity modelBuilder.Entity().HasKey(n => n.PlayerId); + //Définition de la clé primaire de GameEntity + modelBuilder.Entity().HasKey(n => n.GameId); + //Définition de la clé primaire de GrilleEntity + modelBuilder.Entity().HasKey(n => n.GrilleId); + //Définition de la clé primaire de CaseEntity + modelBuilder.Entity().HasKey(n => n.CaseId); + //Définition de la clé primaire de TurnEntity + modelBuilder.Entity().HasKey(n => n.TurnId); + //Définition de la clé primaire de ScoreEntity + modelBuilder.Entity().HasKey(n => n.ScoreId); //Définition du mode de generation de la clé : génération à l'insertion modelBuilder.Entity().Property(n => n.PlayerId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(n => n.GameId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(n => n.GrilleId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(n => n.CaseId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(n => n.TurnId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(n => n.ScoreId).ValueGeneratedOnAdd(); base.OnModelCreating(modelBuilder); - } - } } diff --git a/Sources/Trek12_Lib/TurnEntity.cs b/Sources/Trek12_Lib/TurnEntity.cs new file mode 100644 index 0000000..b82d23e --- /dev/null +++ b/Sources/Trek12_Lib/TurnEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFrameWorkLib +{ + public class TurnEntity + { + public int TurnId { get; set; } + public int DiceValue1 { get; set; } + public int DiceValue2 { get; set; } + } +} diff --git a/Sources/Trek12_Lib/projet.AllTables.db b/Sources/Trek12_Lib/projet.AllTables.db new file mode 100644 index 0000000..1dcbc42 Binary files /dev/null and b/Sources/Trek12_Lib/projet.AllTables.db differ diff --git a/Sources/Trek12_Lib/projet.Players.db b/Sources/Trek12_Lib/projet.Players.db deleted file mode 100644 index 3928b18..0000000 Binary files a/Sources/Trek12_Lib/projet.Players.db and /dev/null differ