error ; ne compile pas. vérification par le prof
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent 665f017e83
commit 672ef9db67

@ -0,0 +1,263 @@
// <auto-generated />
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("20240307151226_m1")]
partial class m1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AdministratorEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint?>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("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");
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
}
}
}

@ -0,0 +1,236 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConnectionLibrairie.Migrations
{
/// <inheritdoc />
public partial class m1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Administrators",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Administrators", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Chapters",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Chapters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Nickname = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Lobbies",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Password = table.Column<string>(type: "TEXT", nullable: false),
NbPlayers = table.Column<uint>(type: "INTEGER", nullable: false),
IdCreator = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(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<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
IdQuestion = table.Column<uint>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Answers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Questions",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
Difficulty = table.Column<byte>(type: "INTEGER", nullable: false),
NbFalls = table.Column<uint>(type: "INTEGER", nullable: false),
IdChapter = table.Column<uint>(type: "INTEGER", nullable: true),
IdAnswerGood = table.Column<uint>(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");
}
/// <inheritdoc />
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");
}
}
}

@ -0,0 +1,260 @@
// <auto-generated />
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<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint?>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("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");
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
}
}
}

@ -20,7 +20,6 @@ namespace Entities
[Required]
public string Content { get; set; } = null!;
[Required]
[ForeignKey(nameof(Question))]
public uint? IdQuestion { get; set; }

@ -12,20 +12,25 @@ using System.Threading.Tasks;
namespace EntityManagers
{
public class AnswerEntityManager(MyDbContext dbContext) : IAnswerManager<AnswerEntity>
public class AnswerEntityManager : IAnswerManager<AnswerEntity>
{
private MyDbContext dbContext = dbContext;
private MyDbContext dbContext;
public AnswerEntityManager(MyDbContext dbContext)
{
this.dbContext = dbContext;
}
public async Task<AnswerEntity> addAnswer(AnswerEntity answer)
{
var tmp = await dbContext.Answers.Where(a => a.Equals(answer)).FirstOrDefaultAsync();
var tmp = await dbContext.Answers.Where(a => a.Content == answer.Content.ToLower() && a.IdQuestion == answer.IdQuestion).FirstOrDefaultAsync();
if (tmp != null) // <=> he already exist
{
return tmp!;
}
await dbContext.Answers.AddAsync(answer);
await dbContext.Answers.AddAsync(new AnswerEntity { Content = answer.Content.ToLower(), IdQuestion = answer.IdQuestion });
await dbContext.SaveChangesAsync();
return await dbContext.Answers.Where(a => a.Equals(answer)).FirstAsync();
return await dbContext.Answers.Where(a => a.Content == answer.Content && a.IdQuestion == answer.IdQuestion).FirstAsync();
}
public async Task<AnswerEntity?> getAnswer(uint id)

@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie
=> a.ToModel().ToDto();
public static AdministratorEntity ToEntity(this AdministratorDto a)
=> a.ToModel().ToEntity();
// equality protocols
public static bool Equals(Administrator a1, Administrator a2)
=> a1.Username == a2.Username;
// reuse other methods
public static bool Equals(Administrator a1, AdministratorDto a2)
=> Equals(a1, a2.ToModel());
public static bool Equals(Administrator a1, AdministratorEntity a2)
=> Equals(a1, a2.ToModel());
public static bool Equals(AdministratorDto a1, Administrator a2)
=> Equals(a1.ToModel(), a2);
public static bool Equals(AdministratorDto a1, AdministratorDto a2)
=> Equals(a1.ToModel(), a2.ToModel());
public static bool Equals(AdministratorDto a1, AdministratorEntity a2)
=> Equals(a1.ToModel(), a2.ToModel());
public static bool Equals(AdministratorEntity a1, Administrator a2)
=> Equals(a1.ToModel(), a2);
public static bool Equals(AdministratorEntity a1, AdministratorDto a2)
=> Equals(a1.ToModel(), a2.ToModel());
public static bool Equals(AdministratorEntity a1, AdministratorEntity a2)
=> Equals(a1.ToModel(), a2.ToModel());
/// <summary>
/// equality protocol for an administrator
/// </summary>
/// <param name="a">the administrator</param>
/// <param name="o">an object</param>
/// <returns>true if the administrator and the object are sames, false otherwise</returns>
public static bool Equals(this Administrator a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o);
else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o));
else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o);
return false;
}
/// <summary>
/// equality protocol for an administrator entity
/// </summary>
/// <param name="a">the administrator entity</param>
/// <param name="o">an object</param>
/// <returns>true if the administrator entity and the object are sames, false otherwise</returns>
public static bool Equals(this AdministratorEntity a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o);
else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o));
else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o);
return false;
}
/// <summary>
/// equality protocol for an administrator dto
/// </summary>
/// <param name="a">the administrator dto</param>
/// <param name="o">an object</param>
/// <returns>true if the administrator dto and the object are sames, false otherwise</returns>
public static bool Equals(this AdministratorDto a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Administrator)) return Equals(a, (Administrator)o);
else if (o.GetType() == typeof(AdministratorEntity)) return Equals(a, ((AdministratorEntity)o));
else if (o.GetType() == typeof(AdministratorDto)) return Equals(a, (AdministratorDto)o);
return false;
}
}
}

@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie
=> a.ToModel().ToDto();
public static AnswerEntity ToEntity(this AnswerDto a)
=> a.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Answer a1, Answer a2)
=> a1.Content == a2.Content && a1.IdQuestion == a2.IdQuestion;
// reuse other methods
public static bool Equals(this Answer a1, AnswerDto a2)
=> a1.Equals(a2.ToModel());
public static bool Equals(this Answer a1, AnswerEntity a2)
=> a1.Equals(a2.ToModel());
public static bool Equals(this AnswerDto a1, Answer a2)
=> a1.ToModel().Equals(a2);
public static bool Equals(this AnswerDto a1, AnswerDto a2)
=> a1.ToModel().Equals(a2.ToModel());
public static bool Equals(this AnswerDto a1, AnswerEntity a2)
=> a1.ToModel().Equals(a2.ToModel());
public static bool Equals(this AnswerEntity a1, Answer a2)
=> a1.ToModel().Equals(a2);
public static bool Equals(this AnswerEntity a1, AnswerDto a2)
=> a1.ToModel().Equals(a2.ToModel());
public static bool Equals(this AnswerEntity a1, AnswerEntity a2)
=> a1.ToModel().Equals(a2.ToModel());
/// <summary>
/// equality protocol for an answer
/// </summary>
/// <param name="a">the answer</param>
/// <param name="o">an object</param>
/// <returns>true if the answer and the object are sames, false otherwise</returns>
public static bool Equals(this Answer a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o);
else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o));
else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o);
return false;
}
/// <summary>
/// equality protocol for an answer entity
/// </summary>
/// <param name="a">the answer entity</param>
/// <param name="o">an object</param>
/// <returns>true if the answer entity and the object are sames, false otherwise</returns>
public static bool Equals(this AnswerEntity a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o);
else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o));
else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o);
return false;
}
/// <summary>
/// equality protocol for an answer dto
/// </summary>
/// <param name="a">the answer dto</param>
/// <param name="o">an object</param>
/// <returns>true if the answer dto and the object are sames, false otherwise</returns>
public static bool Equals(this AnswerDto a, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Answer)) return Equals(a, (Answer)o);
else if (o.GetType() == typeof(AnswerEntity)) return Equals(a, ((AnswerEntity)o));
else if (o.GetType() == typeof(AnswerDto)) return Equals(a, (AnswerDto)o);
return false;
}
}
}

@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie
=> c.ToModel().ToDto();
public static ChapterEntity ToEntity(this ChapterDto c)
=> c.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Chapter c1, Chapter c2)
=> c1.Name == c2.Name;
// reuse other methods
public static bool Equals(this Chapter c1, ChapterDto c2)
=> c1.Equals(c2.ToModel());
public static bool Equals(this Chapter c1, ChapterEntity c2)
=> c1.Equals(c2.ToModel());
public static bool Equals(this ChapterDto c1, Chapter c2)
=> c1.ToModel().Equals(c2);
public static bool Equals(this ChapterDto c1, ChapterDto c2)
=> c1.ToModel().Equals(c2.ToModel());
public static bool Equals(this ChapterDto c1, ChapterEntity c2)
=> c1.ToModel().Equals(c2.ToModel());
public static bool Equals(this ChapterEntity c1, Chapter c2)
=> c1.ToModel().Equals(c2);
public static bool Equals(this ChapterEntity c1, ChapterDto c2)
=> c1.ToModel().Equals(c2.ToModel());
public static bool Equals(this ChapterEntity c1, ChapterEntity c2)
=> c1.ToModel().Equals(c2.ToModel());
/// <summary>
/// equality protocol for a chapter
/// </summary>
/// <param name="c">the chapter</param>
/// <param name="o">an object</param>
/// <returns>true if the chapter and the object are sames, false otherwise</returns>
public static bool Equals(this Chapter c, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o);
else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o));
else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o);
return false;
}
/// <summary>
/// equality protocol for a chapter entity
/// </summary>
/// <param name="c">the chapter entity</param>
/// <param name="o">an object</param>
/// <returns>true if the chapter entity and the object are sames, false otherwise</returns>
public static bool Equals(this ChapterEntity c, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o);
else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o));
else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o);
return false;
}
/// <summary>
/// equality protocol for a chapter dto
/// </summary>
/// <param name="c">the chapter dto</param>
/// <param name="o">an object</param>
/// <returns>true if the chapter dto and the object are sames, false otherwise</returns>
public static bool Equals(this ChapterDto c, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Chapter)) return Equals(c, (Chapter)o);
else if (o.GetType() == typeof(ChapterEntity)) return Equals(c, ((ChapterEntity)o));
else if (o.GetType() == typeof(ChapterDto)) return Equals(c, (ChapterDto)o);
return false;
}
}
}

@ -21,80 +21,30 @@ namespace ExtensionsClassLibrairie
public static Lobby ToModel(this LobbyDto l)
=> new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id);
public static LobbyDto ToDto(this Lobby l)
=> new LobbyDto { Id = l.Id, Creator = l.Creator.ToDto(), IdCreator = l.IdCreator,
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
=> new LobbyDto
{
Id = l.Id,
Creator = l.Creator.ToDto(),
IdCreator = l.IdCreator,
Name = l.Name,
Password = l.Password,
NbPlayers = l.NbPlayers
};
public static LobbyEntity ToEntity(this Lobby l)
=> new LobbyEntity { Id = l.Id, Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator,
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
=> new LobbyEntity
{
Id = l.Id,
Creator = l.Creator.ToEntity(),
IdCreator = l.IdCreator,
Name = l.Name,
Password = l.Password,
NbPlayers = l.NbPlayers
};
// reuse other methods
public static LobbyDto ToDto(this LobbyEntity l)
=> l.ToModel().ToDto();
public static LobbyEntity ToEntity(this LobbyDto l)
=> l.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Lobby l1, Lobby l2)
=> l1.Name == l2.Name && l1.IdCreator == l2.IdCreator;
// reuse other methods
public static bool Equals(this Lobby l1, LobbyDto l2)
=> l1.Equals(l2.ToModel());
public static bool Equals(this Lobby l1, LobbyEntity l2)
=> l1.Equals(l2.ToModel());
public static bool Equals(this LobbyDto l1, Lobby l2)
=> l1.ToModel().Equals(l2);
public static bool Equals(this LobbyDto l1, LobbyDto l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyDto l1, LobbyEntity l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyEntity l1, Lobby l2)
=> l1.ToModel().Equals(l2);
public static bool Equals(this LobbyEntity l1, LobbyDto l2)
=> l1.ToModel().Equals(l2.ToModel());
public static bool Equals(this LobbyEntity l1, LobbyEntity l2)
=> l1.ToModel().Equals(l2.ToModel());
/// <summary>
/// equality protocol for a lobby
/// </summary>
/// <param name="l">the lobby</param>
/// <param name="o">an object</param>
/// <returns>true if the lobby and the object are sames, false otherwise</returns>
public static bool Equals(this Lobby l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
/// <summary>
/// equality protocol for a lobby entity
/// </summary>
/// <param name="l">the lobby entity</param>
/// <param name="o">an object</param>
/// <returns>true if the lobby entity and the object are sames, false otherwise</returns>
public static bool Equals(this LobbyEntity l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
/// <summary>
/// equality protocol for a lobby dto
/// </summary>
/// <param name="l">the lobby dto</param>
/// <param name="o">an object</param>
/// <returns>true if the lobby dto and the object are sames, false otherwise</returns>
public static bool Equals(this LobbyDto l, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Lobby)) return Equals(l, (Lobby)o);
else if (o.GetType() == typeof(LobbyEntity)) return Equals(l, ((LobbyEntity)o));
else if (o.GetType() == typeof(LobbyDto)) return Equals(l, (LobbyDto)o);
return false;
}
}
}

@ -31,69 +31,5 @@ namespace ExtensionsClassLibrairie
=> p.ToModel().ToDto();
public static PlayerEntity ToEntity(this PlayerDto p)
=> p.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Player p1, Player p2)
=> p1.Nickname == p2.Nickname;
// reuse other methods
public static bool Equals(this Player p1, PlayerDto p2)
=> p1.Equals(p2.ToModel());
public static bool Equals(this Player p1, PlayerEntity p2)
=> p1.Equals(p2.ToModel());
public static bool Equals(this PlayerDto p1, Player p2)
=> p1.ToModel().Equals(p2);
public static bool Equals(this PlayerDto p1, PlayerDto p2)
=> p1.ToModel().Equals(p2.ToModel());
public static bool Equals(this PlayerDto p1, PlayerEntity p2)
=> p1.ToModel().Equals(p2.ToModel());
public static bool Equals(this PlayerEntity p1, Player p2)
=> p1.ToModel().Equals(p2);
public static bool Equals(this PlayerEntity p1, PlayerDto p2)
=> p1.ToModel().Equals(p2.ToModel());
public static bool Equals(this PlayerEntity p1, PlayerEntity p2)
=> p1.ToModel().Equals(p2.ToModel());
/// <summary>
/// equality protocol for a player
/// </summary>
/// <param name="p">the player</param>
/// <param name="o">an object</param>
/// <returns>true if the player and the object are sames, false otherwise</returns>
public static bool Equals(this Player p, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Player)) return Equals(p, (Player)o);
else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o));
else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o);
return false;
}
/// <summary>
/// equality protocol for a player entity
/// </summary>
/// <param name="p">the player entity</param>
/// <param name="o">an object</param>
/// <returns>true if the player entity and the object are sames, false otherwise</returns>
public static bool Equals(this PlayerEntity p, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Player)) return Equals(p, (Player)o);
else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o));
else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o);
return false;
}
/// <summary>
/// equality protocol for a player dto
/// </summary>
/// <param name="p">the player dto</param>
/// <param name="o">an object</param>
/// <returns>true if the player dto and the object are sames, false otherwise</returns>
public static bool Equals(this PlayerDto p, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Player)) return Equals(p, (Player)o);
else if (o.GetType() == typeof(PlayerEntity)) return Equals(p, ((PlayerEntity)o));
else if (o.GetType() == typeof(PlayerDto)) return Equals(p, (PlayerDto)o);
return false;
}
}
}

@ -43,69 +43,5 @@ namespace ExtensionsClassLibrairie
=> q.ToModel().ToDto();
public static QuestionEntity ToEntity(this QuestionDto q)
=> q.ToModel().ToEntity();
// equality protocols
public static bool Equals(this Question q1, Question q2)
=> q1.Content == q2.Content;
// reuse other methods
public static bool Equals(this Question q1, QuestionDto q2)
=> q1.Equals(q2.ToModel());
public static bool Equals(this Question q1, QuestionEntity q2)
=> q1.Equals(q2.ToModel());
public static bool Equals(this QuestionDto q1, Question q2)
=> q1.ToModel().Equals(q2);
public static bool Equals(this QuestionDto q1, QuestionDto q2)
=> q1.ToModel().Equals(q2.ToModel());
public static bool Equals(this QuestionDto q1, QuestionEntity q2)
=> q1.ToModel().Equals(q2.ToModel());
public static bool Equals(this QuestionEntity q1, Question q2)
=> q1.ToModel().Equals(q2);
public static bool Equals(this QuestionEntity q1, QuestionDto q2)
=> q1.ToModel().Equals(q2.ToModel());
public static bool Equals(this QuestionEntity q1, QuestionEntity q2)
=> q1.ToModel().Equals(q2.ToModel());
/// <summary>
/// equality protocol for a question
/// </summary>
/// <param name="q">the question</param>
/// <param name="o">an object</param>
/// <returns>true if the question and the object are sames, false otherwise</returns>
public static bool Equals(this Question q, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Question)) return Equals(q, (Question)o);
else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o));
else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o);
return false;
}
/// <summary>
/// equality protocol for a question entity
/// </summary>
/// <param name="q">the question entity</param>
/// <param name="o">an object</param>
/// <returns>true if the question entity and the object are sames, false otherwise</returns>
public static bool Equals(this QuestionEntity q, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Question)) return Equals(q, (Question)o);
else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o));
else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o);
return false;
}
/// <summary>
/// equality protocol for a question dto
/// </summary>
/// <param name="q">the question dto</param>
/// <param name="o">an object</param>
/// <returns>true if the question dto and the object are sames, false otherwise</returns>
public static bool Equals(this QuestionDto q, object? o)
{
if (o == null) return false;
if (o.GetType() == typeof(Question)) return Equals(q, (Question)o);
else if (o.GetType() == typeof(QuestionEntity)) return Equals(q, ((QuestionEntity)o));
else if (o.GetType() == typeof(QuestionDto)) return Equals(q, (QuestionDto)o);
return false;
}
}
}

@ -11,7 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using DTOs;
namespace ToModel
namespace ServiceManagers
{
public class AdministratorServiceManager(MyDbContext dbContext) : IAdministratorManager<AdministratorDto>
{

@ -1,4 +1,5 @@
using DbConnectionLibrairie;
using DataManagers;
using DbConnectionLibrairie;
using DTOs;
using Entities;
using EntityManagers;
@ -12,7 +13,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataManagers
namespace ServiceManagers
{
public class QuestionServiceManager(MyDbContext dbContext) : IQuestionManager<QuestionDto>
{

@ -1,50 +1,50 @@
using DbConnectionLibrairie;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTestsEntityManagers
{
/// <summary>
/// an abstract class to init the dbContext
/// (every unit tests need to implement it)
/// </summary>
public abstract class AbstractUnitTestEM
{
protected MyDbContext dbContext;
protected HttpClient httpClient;
/// <summary>
/// constructor of the class :
/// initialise the database context
/// </summary>
public AbstractUnitTestEM()
{
using DbConnectionLibrairie;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTestsEntityManagers
{
/// <summary>
/// an abstract class to init the dbContext
/// (every unit tests need to implement it)
/// </summary>
public abstract class AbstractUnitTestEM
{
public MyDbContext dbContext;
public HttpClient httpClient;
/// <summary>
/// constructor of the class :
/// initialise the database context
/// </summary>
public AbstractUnitTestEM()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var opt = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
dbContext = new MyDbContext(opt);
dbContext.Database.EnsureCreated();
httpClient = new HttpClient();
}
/// <summary>
/// destructor of the class :
/// dispose the database context
/// </summary>
~AbstractUnitTestEM()
{
dbContext.Dispose();
}
}
}
connection.Open();
var opt = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
dbContext = new MyDbContext(opt);
dbContext.Database.EnsureCreated();
httpClient = new HttpClient();
}
/// <summary>
/// destructor of the class :
/// dispose the database context
/// </summary>
~AbstractUnitTestEM()
{
dbContext.Dispose();
}
}
}

@ -7,7 +7,7 @@ namespace UnitTestsEntityManagers
public class UnitTestAnswerManager : AbstractUnitTestEM
{
AnswerEntityManager mgr;
private AnswerEntityManager mgr;
public UnitTestAnswerManager()
: base()
{
@ -20,39 +20,42 @@ namespace UnitTestsEntityManagers
[Fact]
public async void TestAddAnswer()
{
var answerToAdd = new AnswerEntity { Id = 0, Content = "damien" };
var answerToAdd = new AnswerEntity { Id = 1, Content = "chateîgne" };
var a = await mgr.addAnswer(answerToAdd);
// 1) normal insertion
// WF : it work perfectally
// and a is the same as answerToAdd
Assert.NotNull(a);
// WF : a is the same
// as answerToAdd
Assert.Equal(answerToAdd.Content, a.Content);
Assert.Equal(answerToAdd.Id, a.Id);
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
a = await mgr.addAnswer(answerToAdd);
// 2) with a random id greater than 0
// WF : it works so 'a' is not null,
// his content is equal to the
// WF : 'a' content is equal to the
// content of 'answerToAdd'
// and since it's the second answer
// that we add, his id equal 1
Assert.NotNull(a);
// that we add, his id equal 2
Assert.Equal(answerToAdd.Content, a.Content);
Assert.NotEqual((uint)1, a.Id);
Assert.Equal((uint)2, a.Id);
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
answerToAdd = new AnswerEntity { Id = 7, Content = "chateîgne" };
a = await mgr.addAnswer(answerToAdd);
// 3) with a content that we already have added
// WF : it don't works so 'a' is null
Assert.Null(a);
// WF : the function return the answer which already
// have the same content so the content of 'a' is "châteigne"
// and his id is 1
Assert.Equal("chateîgne", a.Content);
Assert.Equal((uint)1, a.Id);
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
answerToAdd = new AnswerEntity { Id = 7, Content = "CHATEÎGNE" };
a = await mgr.addAnswer(answerToAdd);
// 3) with a content that we already have added
// but in upperCase instead of lowerCase
// WF : it don't works so 'a' is null
Assert.Null(a);
// WF : the function return the answer which
// already have the same content so the content
// of 'a' is "chateîgne" and his id is 1
Assert.Equal("chateîgne", a.Content);
Assert.Equal((uint)1, a.Id);
}
/// <summary>
@ -62,38 +65,38 @@ namespace UnitTestsEntityManagers
public async Task TestRemoveAnswer()
{
// remember that we have only 2 answers in the database :
// 1) (0, "châteigne")
// 2) (1, "damien")
var a = await mgr.removeAnswer(2);
// 1) (1, "châteigne")
// 2) (2, "damien")
var a = await mgr.removeAnswer(3);
// 1) with an id greater or equal
// to the number of element
// WF : it don't works so 'a' is null,
Assert.Null(a);
a = await mgr.removeAnswer(0);
a = await mgr.removeAnswer(1);
// 1) with an id that belongs to an answer
// WF : it works so 'a' is not null,
// and since we've delete the answer with
// the id 0, the content is "châteigne"
// the id 1, the content is "châteigne"
Assert.NotNull(a);
Assert.Equal((uint)0, a.Id);
Assert.Equal((uint)1, a.Id);
Assert.Equal("châteigne", a.Content);
a = await mgr.removeAnswer(1);
a = await mgr.removeAnswer(2);
// 1) same thing with the id 1 just
// to clean the database
// WF : it works so 'a' is not null,
// and since we've delete the answer with
// the id 1, the content is "damien"
// the id 2, the content is "damien"
Assert.NotNull(a);
Assert.Equal((uint)0, a.Id);
Assert.Equal((uint)2, a.Id);
Assert.Equal("damien", a.Content);
// now, the database should be clean
}
// /!\ WARNING : since there was 2 answers added to the base,
// id index while now start at 2 (even though we've delete those)
// id index while now start at 3 (even though we've delete those)
/// <summary>
/// test of the 'getNbElement' method of an AnswerManager
@ -116,8 +119,9 @@ namespace UnitTestsEntityManagers
public static IEnumerable<Object?[]> TestGetAnswer_Datas()
{
var datas = fakeAnswers.datas;
uint max = 0;
foreach (var item in fakeAnswers.datas)
foreach (var item in datas)
{
yield return new Object[] { item.Id, item };
if(max < item.Id) max = item.Id;
@ -128,7 +132,8 @@ namespace UnitTestsEntityManagers
[MemberData(nameof(TestGetAnswer_Datas))]
public async Task TestGetAnswer(uint id, AnswerEntity? waiting)
{
Assert.Equal(waiting, await mgr.getAnswer(id));
var tmp = await mgr.getAnswer(id + 2);
Assert.Equal(waiting?.Content, tmp?.Content);
}
// modifierAnswer

@ -0,0 +1,64 @@
using DataManagers;
using DbConnectionLibrairie;
using DTOs;
using ManagerInterfaces;
using Microsoft.AspNetCore.Mvc;
using ServiceManagers;
using Microsoft.Extensions.Logging;
using OrderCriterias;
using Microsoft.AspNetCore.Http.HttpResults;
namespace WebApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class AdministratorController
{
private IAdministratorManager<AdministratorDto> mgr;
private readonly Logger<AdministratorController> logger;
public AdministratorController(MyDbContext dbContext, Logger<AdministratorController> logger)
{
mgr = new AdministratorServiceManager(dbContext);
this.logger = logger;
}
[HttpPost("add/administrator/")]
public async Task<IActionResult> PostAdministrator([FromBody] AdministratorDto administrator)
{
int count = mgr.getNbElements();
var tmp = await mgr.addAdmin(administrator);
if (mgr.getNbElements() == count) // <=> not added
{
return StatusCode(208) ;
}
logger.LogInformation(message: $"administrator added : {administrator.ToString()}");
return StatusCode(202);
}
[HttpGet("administrators")]
public async Task<IActionResult> GetSomeAdministrators(int page, int count = 10, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById)
{
var tmp = await mgr.getAdministrators(page, count, orderCriteria);
if (tmp.administrators == null)
{
return BadRequest(tmp);
}
else return Ok(tmp);
}
[HttpDelete()]
public async Task<IActionResult> DeleteAdministrator(int id)
{
if (id < 0)
{
return BadRequest();
}
var tmp = await mgr.removeAdmin(id);
if (tmp == null) return StatusCode(403);
logger.LogInformation(message: $"administrator removed : ${tmp}");
return Ok(tmp);
}
}
}

@ -0,0 +1,6 @@
namespace WebApi.Controllers
{
public class AnswerController
{
}
}

@ -0,0 +1,6 @@
namespace WebApi.Controllers
{
public class ChapterController
{
}
}

@ -0,0 +1,6 @@
namespace WebApi.Controllers
{
public class LobbyController
{
}
}

@ -0,0 +1,6 @@
namespace WebApi.Controllers
{
public class PlayerController
{
}
}

@ -0,0 +1,6 @@
namespace WebApi.Controllers
{
public class QuestionController
{
}
}

@ -1,33 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace WebApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -1,13 +0,0 @@
namespace WebApi
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -10,4 +10,12 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DbConnectionLibrairie\DbConnectionLibrairie.csproj" />
<ProjectReference Include="..\DTOs\DTOs.csproj" />
<ProjectReference Include="..\ManagerInterfaces\ManagerInterfaces.csproj" />
<ProjectReference Include="..\OrderCriterias\OrderCriterias.csproj" />
<ProjectReference Include="..\ServiceManagers\ServiceManagers.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save