From f972a3a9c9926d90a2245a35b2978805e9d64311 Mon Sep 17 00:00:00 2001 From: "damien.nortier" Date: Mon, 26 Feb 2024 10:52:48 +0100 Subject: [PATCH] =?UTF-8?q?finalisation=20du=20dbcontext=20et=20des=20enti?= =?UTF-8?q?t=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApi/DTOs/AnswerDto.cs | 3 + WebApi/DTOs/LobbyDto.cs | 2 + WebApi/DTOs/QuestionDto.cs | 4 + .../DbConnectionLibrairie.csproj | 1 + .../Migrations/20240226094705_m1.Designer.cs | 265 ++++++++++++++++++ .../Migrations/20240226094705_m1.cs | 237 ++++++++++++++++ .../Migrations/MyDbContextModelSnapshot.cs | 262 +++++++++++++++++ WebApi/DbConnectionLibrairie/MyDbContext.cs | 15 + WebApi/DbConnectionLibrairie/database.db | Bin 0 -> 81920 bytes WebApi/Entities/AdministratorEntity.cs | 11 +- WebApi/Entities/AnswerEntity.cs | 10 +- WebApi/Entities/ChapterEntity.cs | 11 +- WebApi/Entities/LobbyEntity.cs | 20 +- WebApi/Entities/LobbyEntityPlayerEntity.cs | 27 ++ WebApi/Entities/PlayerEntity.cs | 11 +- WebApi/Entities/PlayerEntityChapterEntity.cs | 33 +++ WebApi/Entities/QuestionEntity.cs | 22 +- WebApi/Model/Answer.cs | 14 +- WebApi/Model/Lobby.cs | 13 +- WebApi/Model/Player.cs | 6 +- WebApi/Model/Question.cs | 22 +- 21 files changed, 936 insertions(+), 53 deletions(-) create mode 100644 WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs create mode 100644 WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs create mode 100644 WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs create mode 100644 WebApi/DbConnectionLibrairie/database.db create mode 100644 WebApi/Entities/LobbyEntityPlayerEntity.cs create mode 100644 WebApi/Entities/PlayerEntityChapterEntity.cs diff --git a/WebApi/DTOs/AnswerDto.cs b/WebApi/DTOs/AnswerDto.cs index b26056c..967330c 100644 --- a/WebApi/DTOs/AnswerDto.cs +++ b/WebApi/DTOs/AnswerDto.cs @@ -11,9 +11,12 @@ namespace DTOs /// Id : identifier in the database /// Content : content of the answer /// IdQuestion : the id of the question which it answer to + /// Question : the question which it answer to /// public int? Id { get; set; } public string Content { get; set; } = null!; public int? IdQuestion { get; set; } + + public QuestionDto Question { get; set; } = null!; } } diff --git a/WebApi/DTOs/LobbyDto.cs b/WebApi/DTOs/LobbyDto.cs index d8b5e24..a82003a 100644 --- a/WebApi/DTOs/LobbyDto.cs +++ b/WebApi/DTOs/LobbyDto.cs @@ -17,11 +17,13 @@ namespace DTOs /// Name : name of the lobby /// Password : password require to access at the lobby /// IdCreator : identifier of the creator player + /// Creator : the creator player /// public int? Id { get; set; } public string Name { get; set; } = null!; public string Password { get; set; } = null!; public int NbPlayers { get; set; } public int? IdCreator { get; set; } + public PlayerDto Creator { get; set; } = null!; } } diff --git a/WebApi/DTOs/QuestionDto.cs b/WebApi/DTOs/QuestionDto.cs index cc2391f..e62efd1 100644 --- a/WebApi/DTOs/QuestionDto.cs +++ b/WebApi/DTOs/QuestionDto.cs @@ -19,6 +19,8 @@ namespace DTOs /// NbFails : number of time that people fail on this question /// IdChapter : identifier of the chapter of the question /// IdAnswerGood : identifier of the right answer to this question + /// Chapter : the chapter of the question + /// AnswerGood : the right answer to this question /// public int? Id { get; set; } public string Content { get; set; } = null!; @@ -26,5 +28,7 @@ namespace DTOs public int NbFalls { get; set; } public int? IdChapter { get; set; } public int? IdAnswerGood { get; set; } + public ChapterDto? Chapter { get; set; } + public AnswerDto? AnswerGood { get; set; } } } diff --git a/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj b/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj index ad7adea..f571f8a 100644 --- a/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj +++ b/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + $(MSBuildProjectDirectory) diff --git a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs new file mode 100644 index 0000000..2085c6b --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.Designer.cs @@ -0,0 +1,265 @@ +// +using System; +using DbConnectionLibrairie; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbConnectionLibrairie.Migrations +{ + [DbContext(typeof(MyDbContext))] + [Migration("20240226094705_m1")] + partial class m1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); + + modelBuilder.Entity("Entities.AdministratorEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Administrators"); + }); + + modelBuilder.Entity("Entities.AnswerEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IdQuestion") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("IdQuestion"); + + b.ToTable("Answers"); + }); + + modelBuilder.Entity("Entities.ChapterEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Chapters"); + }); + + modelBuilder.Entity("Entities.LobbyEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IdCreator") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IdCreator"); + + b.ToTable("Lobbies"); + }); + + modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b => + { + b.Property("IdLobby") + .HasColumnType("INTEGER"); + + b.Property("IdPlayer") + .HasColumnType("INTEGER"); + + b.Property("MaxScore") + .HasColumnType("INTEGER"); + + b.HasKey("IdLobby", "IdPlayer"); + + b.HasIndex("IdPlayer"); + + b.ToTable("Use"); + }); + + modelBuilder.Entity("Entities.PlayerEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Nickname") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b => + { + b.Property("IdPlayer") + .HasColumnType("INTEGER"); + + b.Property("IdChapter") + .HasColumnType("INTEGER"); + + b.Property("MaxScore") + .HasColumnType("INTEGER"); + + b.HasKey("IdPlayer", "IdChapter"); + + b.HasIndex("IdChapter"); + + b.ToTable("Play"); + }); + + modelBuilder.Entity("Entities.QuestionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("IdAnswerGood") + .HasColumnType("INTEGER"); + + b.Property("IdChapter") + .HasColumnType("INTEGER"); + + b.Property("NbFalls") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("IdAnswerGood"); + + b.HasIndex("IdChapter"); + + b.ToTable("Questions"); + }); + + modelBuilder.Entity("Entities.AnswerEntity", b => + { + b.HasOne("Entities.QuestionEntity", "Question") + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Question"); + }); + + modelBuilder.Entity("Entities.LobbyEntity", b => + { + b.HasOne("Entities.PlayerEntity", "Creator") + .WithMany() + .HasForeignKey("IdCreator"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b => + { + b.HasOne("Entities.LobbyEntity", "Lobby") + .WithMany() + .HasForeignKey("IdLobby") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("IdPlayer") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lobby"); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b => + { + b.HasOne("Entities.ChapterEntity", "Chapter") + .WithMany() + .HasForeignKey("IdChapter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("IdPlayer") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Chapter"); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("Entities.QuestionEntity", b => + { + b.HasOne("Entities.AnswerEntity", "AnswerGood") + .WithMany() + .HasForeignKey("IdAnswerGood"); + + b.HasOne("Entities.ChapterEntity", "Chapter") + .WithMany() + .HasForeignKey("IdChapter"); + + b.Navigation("AnswerGood"); + + b.Navigation("Chapter"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs new file mode 100644 index 0000000..e69c689 --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/20240226094705_m1.cs @@ -0,0 +1,237 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DbConnectionLibrairie.Migrations +{ + /// + public partial class m1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Administrators", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Username = table.Column(type: "TEXT", nullable: false), + HashedPassword = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Administrators", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Chapters", + 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_Chapters", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Nickname = table.Column(type: "TEXT", nullable: false), + HashedPassword = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Lobbies", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Password = table.Column(type: "TEXT", nullable: false), + NbPlayers = table.Column(type: "INTEGER", nullable: false), + IdCreator = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Lobbies", x => x.Id); + table.ForeignKey( + name: "FK_Lobbies_Players_IdCreator", + column: x => x.IdCreator, + principalTable: "Players", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Play", + columns: table => new + { + IdChapter = table.Column(type: "INTEGER", nullable: false), + IdPlayer = table.Column(type: "INTEGER", nullable: false), + MaxScore = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Play", x => new { x.IdPlayer, x.IdChapter }); + table.ForeignKey( + name: "FK_Play_Chapters_IdChapter", + column: x => x.IdChapter, + principalTable: "Chapters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Play_Players_IdPlayer", + column: x => x.IdPlayer, + principalTable: "Players", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Use", + columns: table => new + { + IdLobby = table.Column(type: "INTEGER", nullable: false), + IdPlayer = table.Column(type: "INTEGER", nullable: false), + MaxScore = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Use", x => new { x.IdLobby, x.IdPlayer }); + table.ForeignKey( + name: "FK_Use_Lobbies_IdLobby", + column: x => x.IdLobby, + principalTable: "Lobbies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Use_Players_IdPlayer", + column: x => x.IdPlayer, + principalTable: "Players", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Answers", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(type: "TEXT", nullable: false), + IdQuestion = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Answers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Questions", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(type: "TEXT", nullable: false), + Difficulty = table.Column(type: "INTEGER", nullable: false), + NbFalls = table.Column(type: "INTEGER", nullable: false), + IdChapter = table.Column(type: "INTEGER", nullable: true), + IdAnswerGood = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Questions", x => x.Id); + table.ForeignKey( + name: "FK_Questions_Answers_IdAnswerGood", + column: x => x.IdAnswerGood, + principalTable: "Answers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Questions_Chapters_IdChapter", + column: x => x.IdChapter, + principalTable: "Chapters", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Answers_IdQuestion", + table: "Answers", + column: "IdQuestion"); + + migrationBuilder.CreateIndex( + name: "IX_Lobbies_IdCreator", + table: "Lobbies", + column: "IdCreator"); + + migrationBuilder.CreateIndex( + name: "IX_Play_IdChapter", + table: "Play", + column: "IdChapter"); + + migrationBuilder.CreateIndex( + name: "IX_Questions_IdAnswerGood", + table: "Questions", + column: "IdAnswerGood"); + + migrationBuilder.CreateIndex( + name: "IX_Questions_IdChapter", + table: "Questions", + column: "IdChapter"); + + migrationBuilder.CreateIndex( + name: "IX_Use_IdPlayer", + table: "Use", + column: "IdPlayer"); + + migrationBuilder.AddForeignKey( + name: "FK_Answers_Questions_IdQuestion", + table: "Answers", + column: "IdQuestion", + principalTable: "Questions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Answers_Questions_IdQuestion", + table: "Answers"); + + migrationBuilder.DropTable( + name: "Administrators"); + + migrationBuilder.DropTable( + name: "Play"); + + migrationBuilder.DropTable( + name: "Use"); + + migrationBuilder.DropTable( + name: "Lobbies"); + + migrationBuilder.DropTable( + name: "Players"); + + migrationBuilder.DropTable( + name: "Questions"); + + migrationBuilder.DropTable( + name: "Answers"); + + migrationBuilder.DropTable( + name: "Chapters"); + } + } +} diff --git a/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs b/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs new file mode 100644 index 0000000..a361ff4 --- /dev/null +++ b/WebApi/DbConnectionLibrairie/Migrations/MyDbContextModelSnapshot.cs @@ -0,0 +1,262 @@ +// +using System; +using DbConnectionLibrairie; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DbConnectionLibrairie.Migrations +{ + [DbContext(typeof(MyDbContext))] + partial class MyDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); + + modelBuilder.Entity("Entities.AdministratorEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Administrators"); + }); + + modelBuilder.Entity("Entities.AnswerEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IdQuestion") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("IdQuestion"); + + b.ToTable("Answers"); + }); + + modelBuilder.Entity("Entities.ChapterEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Chapters"); + }); + + modelBuilder.Entity("Entities.LobbyEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IdCreator") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbPlayers") + .HasColumnType("INTEGER"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IdCreator"); + + b.ToTable("Lobbies"); + }); + + modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b => + { + b.Property("IdLobby") + .HasColumnType("INTEGER"); + + b.Property("IdPlayer") + .HasColumnType("INTEGER"); + + b.Property("MaxScore") + .HasColumnType("INTEGER"); + + b.HasKey("IdLobby", "IdPlayer"); + + b.HasIndex("IdPlayer"); + + b.ToTable("Use"); + }); + + modelBuilder.Entity("Entities.PlayerEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Nickname") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b => + { + b.Property("IdPlayer") + .HasColumnType("INTEGER"); + + b.Property("IdChapter") + .HasColumnType("INTEGER"); + + b.Property("MaxScore") + .HasColumnType("INTEGER"); + + b.HasKey("IdPlayer", "IdChapter"); + + b.HasIndex("IdChapter"); + + b.ToTable("Play"); + }); + + modelBuilder.Entity("Entities.QuestionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("IdAnswerGood") + .HasColumnType("INTEGER"); + + b.Property("IdChapter") + .HasColumnType("INTEGER"); + + b.Property("NbFalls") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("IdAnswerGood"); + + b.HasIndex("IdChapter"); + + b.ToTable("Questions"); + }); + + modelBuilder.Entity("Entities.AnswerEntity", b => + { + b.HasOne("Entities.QuestionEntity", "Question") + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Question"); + }); + + modelBuilder.Entity("Entities.LobbyEntity", b => + { + b.HasOne("Entities.PlayerEntity", "Creator") + .WithMany() + .HasForeignKey("IdCreator"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b => + { + b.HasOne("Entities.LobbyEntity", "Lobby") + .WithMany() + .HasForeignKey("IdLobby") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("IdPlayer") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lobby"); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b => + { + b.HasOne("Entities.ChapterEntity", "Chapter") + .WithMany() + .HasForeignKey("IdChapter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.PlayerEntity", "Player") + .WithMany() + .HasForeignKey("IdPlayer") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Chapter"); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("Entities.QuestionEntity", b => + { + b.HasOne("Entities.AnswerEntity", "AnswerGood") + .WithMany() + .HasForeignKey("IdAnswerGood"); + + b.HasOne("Entities.ChapterEntity", "Chapter") + .WithMany() + .HasForeignKey("IdChapter"); + + b.Navigation("AnswerGood"); + + b.Navigation("Chapter"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebApi/DbConnectionLibrairie/MyDbContext.cs b/WebApi/DbConnectionLibrairie/MyDbContext.cs index a5fdb4a..1afb573 100644 --- a/WebApi/DbConnectionLibrairie/MyDbContext.cs +++ b/WebApi/DbConnectionLibrairie/MyDbContext.cs @@ -11,6 +11,8 @@ namespace DbConnectionLibrairie public DbSet Lobbies { get; set; } public DbSet Players { get; set; } public DbSet Questions { get; set; } + public DbSet Use { get; set; } + public DbSet Play { get; set; } public MyDbContext() { } @@ -25,5 +27,18 @@ namespace DbConnectionLibrairie options.UseSqlite(@"Data source = database.db"); } } + + /// + /// function overrided OnModelCreating : + /// initialise composed primary keys + /// + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(u => new { u.IdLobby, u.IdPlayer }); + modelBuilder.Entity().HasKey(u => new { u.IdPlayer, u.IdChapter }); + + base.OnModelCreating(modelBuilder); + } } } diff --git a/WebApi/DbConnectionLibrairie/database.db b/WebApi/DbConnectionLibrairie/database.db new file mode 100644 index 0000000000000000000000000000000000000000..0d5ba66a99f1e0f01ab7b1c3c4260fad77e43d15 GIT binary patch literal 81920 zcmeI*O>YxN7{GC_194(v447zDA;fm2s#u_qq|g*qYU?`dU^Q`qW2)qUEGOO+tBGB_ zj(|fCNhtjee1{&|YmfZ~z4g*tFKw@tdhG1`n->(J9$5XY1lzMa^UVC_nOQH1VDtWJ zZ=@@GgW*AEq~o;}ItrI+HgxA4&{P0BY)(qXUP z)t}b4+7Ar9UGHw}cb@4(@%nPLsa0BfpiYiW1mFucoOD*>=<>b59 zq@#;&qxTPWW7He;4bgP#v*+&iC>mqeU`8^<1>8OQZS z@l)+cPPrY)ZAC3V&lPg=wQJJ%4@aGyece4^crVU75n7ecS2acT%0)wkydoYV$5fGu zEp0_>DvkA)(s;1Cs#Mn-o2_O=lq>4S7wtf`jb?qV(%e?Q(6*JzgVuVzAtJ14jn+-4 zz3QMp()%M-X=z)cHK#@Q=yGpwueW=+KN6D@jq0A$*r|2)_l@Keyo?W=B6{uCuXk-N zGeO6m5gc7DFuJy{A8etv-qh+V4Qt5enhYE(D^0DYHMK@n+f-Dix;;s1+38PWG-t5| zRV|fcQ6v(aVMk?gX$JLpfeC3Mt+|C52E6!6PoCSVAPmu#&r8mp~e-Q-cCY&V^ zF(7jtt}4bP2REYixHLvd8>v&-75CU)X#WwTmY)`a58Ts|k4O45s}wVuQ_ zEWXZ#_3XXblQZ{#S0uByg(s%_TIcEJ?qDc3{DcJ&M7ZGSg&Iv>qCyEqK!R7&O>pYCQnyGLf8JAI3#x!dPZmOIswBZ>)o@7$z(wF~^&MIxFvweI3eniwBD z@r=_>uHA*`?3$%wO0DU2JC(4#n5VYg{lUL*#@C70PRQJ?nT$Sunys*QH~*J;et&vW z{&+TNo~`H$=AZdvJ!kEM-@R+iw3D^Y(^PoA{gn2mJiZ8{*FvvSaFWJe2^*aQv8cyh z1~)o}@nkR*m#49Z8#@kVygU9yuIhZ=@N>_<1_rkbafNgG99W26<>=CP4}=%L*ByKB z6btWYWzup!*1Z*_4-MzMT-e#KeF|r<((9djyI=Q{t?zY=M|w9w+#HE|HYZ=bDjmz# zNZb|RK2L_n;uZ(@iTEr*cX!SLDG!fbfVW6$x2?zL%tnhq`LXeJ~y6mW1? z_{MP1J=`6ADVCM!Y@}I{67}q){BS90OB@@gy)d?TLfm9enK#-6@huhq$cQf<2q1s} z0tg_000IagfB*srAn-N|ydzEAk{9O}Z_h6-emH;k_R{>F_QAqObMteHc`+`j_*X`J z@jw6p1Q0*~0R#|0009ILKmdWaU*Ph@t?Afb0+>Jl7r*q+0|5jOKmY**5I_I{1Q0*~ z0R&Pk!2N%UCzqiifB*srAbfB*srAb @@ -17,7 +14,7 @@ namespace Entities /// HashedPassword : hash of the password of the administrator /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Username { get; set; } = null!; public string HashedPassword { get; set; } = null!; } diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs index 5178988..26e63d9 100644 --- a/WebApi/Entities/AnswerEntity.cs +++ b/WebApi/Entities/AnswerEntity.cs @@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Entities { + [Table("Answers")] public class AnswerEntity { /// @@ -11,12 +12,15 @@ namespace Entities /// Id : identifier in the database /// Content : content of the answer /// IdQuestion : the id of the question which it answer to + /// Question : the question which it answer to /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Content { get; set; } = null!; - [ForeignKey(nameof(QuestionEntity))] - public int? IdQuestion { get; set; } + [ForeignKey(nameof(Question))] + public uint IdQuestion { get; set; } + + public QuestionEntity Question { get; set; } = null!; } } diff --git a/WebApi/Entities/ChapterEntity.cs b/WebApi/Entities/ChapterEntity.cs index 794579f..786e9c1 100644 --- a/WebApi/Entities/ChapterEntity.cs +++ b/WebApi/Entities/ChapterEntity.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace Entities { + [Table("Chapters")] public class ChapterEntity { /// @@ -16,7 +13,7 @@ namespace Entities /// Name : name of the chapter /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Name { get; set; } = null!; } } diff --git a/WebApi/Entities/LobbyEntity.cs b/WebApi/Entities/LobbyEntity.cs index 15559c7..65781d1 100644 --- a/WebApi/Entities/LobbyEntity.cs +++ b/WebApi/Entities/LobbyEntity.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics.CodeAnalysis; namespace Entities { + [Table("Lobbies")] public class LobbyEntity { /// @@ -17,14 +14,17 @@ namespace Entities /// Name : name of the lobby /// Password : password require to access at the lobby /// IdCreator : identifier of the creator player + /// Creator : the creator player /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Name { get; set; } = null!; public string Password { get; set; } = null!; - public int NbPlayers { get; set; } + public uint NbPlayers { get; set; } - [ForeignKey(nameof(PlayerEntity))] - public int? IdCreator { get; set; } + [ForeignKey(nameof(Creator))] + public uint? IdCreator { get; set; } + + public PlayerEntity Creator { get; set; } = null!; } } diff --git a/WebApi/Entities/LobbyEntityPlayerEntity.cs b/WebApi/Entities/LobbyEntityPlayerEntity.cs new file mode 100644 index 0000000..c521d84 --- /dev/null +++ b/WebApi/Entities/LobbyEntityPlayerEntity.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entities +{ + [Table("Use")] + public class LobbyEntityPlayerEntity + { + /// + /// a class just to match with the model (this is the "utiliser" entity) + /// properties : + /// IdLobby : identifier of the lobby this is for + /// IdPlayer : identifier of the player this is for + /// Lobby : the lobby this is for + /// Player : the player this is for + /// + [ForeignKey(nameof(Lobby))] + public uint IdLobby { get; set; } + + [ForeignKey(nameof(Player))] + public uint IdPlayer { get; set; } + + public LobbyEntity Lobby { get; set; } = null!; + public PlayerEntity Player { get; set; } = null!; + + public uint MaxScore { get; set; } + } +} diff --git a/WebApi/Entities/PlayerEntity.cs b/WebApi/Entities/PlayerEntity.cs index dc3d839..873c4e0 100644 --- a/WebApi/Entities/PlayerEntity.cs +++ b/WebApi/Entities/PlayerEntity.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace Entities { + [Table("Players")] public class PlayerEntity { /// @@ -17,7 +14,7 @@ namespace Entities /// HashedPassword : hashed of the password of the player /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Nickname { get; set; } = null!; public string HashedPassword { get; set; } = null!; } diff --git a/WebApi/Entities/PlayerEntityChapterEntity.cs b/WebApi/Entities/PlayerEntityChapterEntity.cs new file mode 100644 index 0000000..16d1c28 --- /dev/null +++ b/WebApi/Entities/PlayerEntityChapterEntity.cs @@ -0,0 +1,33 @@ +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 Entities +{ + [Table("Play")] + public class PlayerEntityChapterEntity + { + /// + /// a class to storage the maximum score of a player for a chapter + /// properties : + /// IdChapter : identifier of the chapter this is for + /// IdPlayer : identifier of the player this is for + /// Chapter : the chapter this is for + /// Player : the player this is for + /// + [ForeignKey(nameof(Chapter))] + public uint IdChapter { get; set; } + + [ForeignKey(nameof(Player))] + public uint IdPlayer { get; set; } + + public ChapterEntity Chapter { get; set; } = null!; + public PlayerEntity Player { get; set; } = null!; + + public uint MaxScore { get; set; } + } +} diff --git a/WebApi/Entities/QuestionEntity.cs b/WebApi/Entities/QuestionEntity.cs index 1e08922..523afde 100644 --- a/WebApi/Entities/QuestionEntity.cs +++ b/WebApi/Entities/QuestionEntity.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; namespace Entities { + [Table("Questions")] public class QuestionEntity { /// @@ -19,17 +20,24 @@ namespace Entities /// NbFails : number of time that people fail on this question /// IdChapter : identifier of the chapter of the question /// IdAnswerGood : identifier of the right answer to this question + /// Chapter : the chapter of the question + /// AnswerGood : the right answer to this question /// [Key] - public int? Id { get; set; } + public uint? Id { get; set; } public string Content { get; set; } = null!; - public int Difficulty { get; set; } - public int NbFalls { get; set; } + [AllowedValues(1, 2, 3)] + public byte Difficulty { get; set; } + public uint NbFalls { get; set; } - [ForeignKey(nameof(ChapterEntity))] - public int? IdChapter { get; set; } + [ForeignKey(nameof(Chapter))] + public uint? IdChapter { get; set; } - [ForeignKey(nameof(AnswerEntity))] - public int? IdAnswerGood { get; set; } + [ForeignKey(nameof(AnswerGood))] + public uint? IdAnswerGood { get; set; } + + public ChapterEntity? Chapter { get; set; } + + public AnswerEntity? AnswerGood { get; set; } } } diff --git a/WebApi/Model/Answer.cs b/WebApi/Model/Answer.cs index 5525f91..24f87b6 100644 --- a/WebApi/Model/Answer.cs +++ b/WebApi/Model/Answer.cs @@ -11,10 +11,12 @@ namespace Model /// id : identifier in the database /// content : content of the answer /// idQuestion : the id of the question which it answer to + /// question : the question which it answer to /// private int id; private string? content; private int idQuestion; + public Question? question; /// /// getters and setters for attributes @@ -34,17 +36,23 @@ namespace Model get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion private set { idQuestion = value < -1 || value == null ? -1 : value.Value; } } + + public Question? Question + { + get => question; + private set { question = value; IdQuestion = value == null ? -1 : value.Id; } + } /// /// constructor of an answer /// /// the content of the answer /// the id in the database - /// the id of the question which it answer to - public Answer(string content, int? idQuestion = null, int? id = null) + /// the question which it answer to + public Answer(string content, Question? question = null, int? id = null) { Content = content; Id = id; - IdQuestion = idQuestion; + Question = question; } } diff --git a/WebApi/Model/Lobby.cs b/WebApi/Model/Lobby.cs index 8624941..f9dac85 100644 --- a/WebApi/Model/Lobby.cs +++ b/WebApi/Model/Lobby.cs @@ -17,12 +17,14 @@ namespace Model /// name : name of the lobby /// password : password require to access at the lobby /// idCreator : identifier of the creator player + /// creator : the creator player /// private int id; private string? name; private string? password; private int nbPlayers; private int idCreator; + private Player creator; /// /// getters and setters of attributes /// @@ -51,19 +53,24 @@ namespace Model get => idCreator == -1 ? null : id; private set { idCreator = value == null || value < -1 ? -1 : value.Value; } } + public Player Creator + { + get => creator; + set { creator = value; idCreator = value.Id; } + } /// /// constructor of a lobby /// /// the name of the lobby - /// the id of the creator + /// the creator /// the password require to access to the lobby /// the number of players in the lobby /// the id of the lobby - public Lobby(string name, int idCreator, string password = "", int nbPlayer = 0, int? id = null) + public Lobby(string name, Player creator, string password = "", int nbPlayer = 0, int? id = null) { Name = name; - IdCreator = idCreator; + Creator = creator; Password = password; NbPlayers = nbPlayer; Id = id; diff --git a/WebApi/Model/Player.cs b/WebApi/Model/Player.cs index 4c20a75..ee70ae7 100644 --- a/WebApi/Model/Player.cs +++ b/WebApi/Model/Player.cs @@ -23,10 +23,10 @@ namespace Model /// /// getters and setters for attributes /// - public int? Id + public int Id { - get => id == -1 ? null : id; - private set { id = value == null || value < -1 ? -1 : value.Value; } + get => id; + private set { id = value; } } public string Nickname { diff --git a/WebApi/Model/Question.cs b/WebApi/Model/Question.cs index d376dd7..ead4d2f 100644 --- a/WebApi/Model/Question.cs +++ b/WebApi/Model/Question.cs @@ -19,6 +19,8 @@ namespace Model /// nbFails : number of time that people fail on this question /// idChapter : identifier of the chapter of the question /// idAnswerGood : identifier of the right answer to this question + /// chapter : the chapter of the question + /// answerGood : the right answer to this question /// private int id; private string? content; @@ -26,6 +28,8 @@ namespace Model private int nbFalls; private int idChapter; private int idAnswerGood; + private Chapter? chapter; + private Answer? answerGood; public int? Id { @@ -58,14 +62,26 @@ namespace Model set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; } } - public Question(string content, int idChapter = -1, int id = -1, int idAnswerGood = -1) + public Chapter? Chapter + { + get => chapter; + set { chapter = value; IdChapter = value == null ? -1 : value.Id; } + } + + public Answer? AnswerGood + { + get => answerGood; + set { answerGood = value; IdAnswerGood = value == null ? -1 : value.Id; } + } + + public Question(string content, Chapter? chapter = null, int id = -1, Answer? answerGood = null) { Id = id; Content = content; Difficulty = 1; NbFalls = 0; - IdChapter = idChapter; - IdAnswerGood = idAnswerGood; + Chapter = chapter; + AnswerGood = answerGood; } } }