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 0000000..0d5ba66
Binary files /dev/null and b/WebApi/DbConnectionLibrairie/database.db differ
diff --git a/WebApi/Entities/AdministratorEntity.cs b/WebApi/Entities/AdministratorEntity.cs
index 81b3c9c..a4f0c89 100644
--- a/WebApi/Entities/AdministratorEntity.cs
+++ b/WebApi/Entities/AdministratorEntity.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("Administrators")]
public class AdministratorEntity
{
///
@@ -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;
}
}
}