feat : ajout des classes entity (⚠️ manque utiliser et jouer), des modèle et des DTOs
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent 62957eb56f
commit 8e229a61f7

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTOs
{
public class AdministratorDto
{
/// <summary>
/// define a DTO for an administrator
/// properties :
/// Id : identifier in the database
/// Username : username for a player
/// HashedPassword : hashed of the password of the player
/// </summary>
public int Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
}

@ -1,25 +1,19 @@
namespace DTOs using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DTOs
{ {
public class AnswerDto
{
/// <summary> /// <summary>
/// define a DTO of an answer for a Question with Mutiple Choice /// define a DTO for an answer for a Question with Mutiple Choice
/// properties : /// properties :
/// Id : identifier in the database /// Id : identifier in the database
/// Content : content of the answer /// Content : content of the answer
/// idQuestion : the id of the question which it answer to
/// </summary> /// </summary>
public class AnswerDto
{
public int Id { get; set; } public int Id { get; set; }
public string Content { get; set; } = null!; public string Content { get; set; } = null!;
public int? IdQuestion { get; set; }
/// <summary>
/// constructor of an answer
/// </summary>
/// <param name="content">the content of an answer</param>
/// <param name="id">the id of an answer</param>
public AnswerDto(string content, int id = -1)
{
Content = content;
Id = id;
}
} }
} }

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTOs
{
public class ChapterDto
{
/// <summary>
/// define a mathematical chapter or thematic
/// properties :
/// Id : identifier in the database
/// Name : name of the chapter
/// </summary>
public int Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -0,0 +1,27 @@
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 DTOs
{
public class LobbyDto
{
/// <summary>
/// define a lobby for QMC rapidity fight
/// properties :
/// Id : identifier of the lobby in the database
/// Name : name of the lobby
/// Password : password require to access at the lobby
/// IdCreator : identifier of the creator player
/// </summary>
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; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTOs
{
public class PlayerDto
{
/// <summary>
/// define a DTO for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// HashedPassword : hashed of the password of the player
/// </summary>
public int Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
}

@ -0,0 +1,30 @@
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 DTOs
{
public class QuestionDto
{
/// <summary>
/// represent a mathematical question
/// properties :
/// Id : identifier of the question in the database
/// Content : the content of the question
/// Difficulty : difficulty (between 1 and 3 included) of the question
/// 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
/// </summary>
public int Id { get; set; }
public string Content { get; set; } = null!;
public int Difficuty { get; set; }
public int NbFalls { get; set; }
public int IdChapter { get; set; }
public int IdAnswerGood { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class AdministratorEntity
{
/// <summary>
/// define an entity for an administrator
/// properties :
/// Id : identifier in the database
/// Username : username for a player
/// HashedPassword : hashed of the password of the player
/// </summary>
[Key]
public int Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
}

@ -1,19 +1,22 @@
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities namespace Entities
{ {
public class AnswerEntity public class AnswerEntity
{ {
/// <summary> /// <summary>
/// define an entity of an answer for a Question with Mutiple Choice /// define an entity for an answer for a Question with Mutiple Choice
/// properties : /// properties :
/// Id : identifier in the database /// Id : identifier in the database
/// Content : content of the answer /// Content : content of the answer
/// idQuestion : the id of the question which it answer to
/// </summary> /// </summary>
[Key]
public int Id { get; set; } public int Id { get; set; }
public string Content { get; set; } = null!; public string Content { get; set; } = null!;
[ForeignKey(nameof(QuestionEntity))] [ForeignKey(nameof(QuestionEntity))]
public int IdQuestion { get; set; } public int? IdQuestion { get; set; }
} }
} }

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class ChapterEntity
{
/// <summary>
/// define a mathematical chapter or thematic
/// properties :
/// Id : identifier in the database
/// Name : name of the chapter
/// </summary>
[Key]
public int Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -0,0 +1,30 @@
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
{
public class LobbyEntity
{
/// <summary>
/// define a lobby for QMC rapidity fight
/// properties :
/// Id : identifier of the lobby in the database
/// Name : name of the lobby
/// Password : password require to access at the lobby
/// IdCreator : identifier of the creator player
/// </summary>
[Key]
public int Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public int NbPlayers { get; set; }
[ForeignKey(nameof(PlayerEntity))]
public int IdCreator { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class PlayerEntity
{
/// <summary>
/// define an entity for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// HashedPassword : hashed of the password of the player
/// </summary>
[Key]
public int Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
}

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -9,10 +10,23 @@ namespace Entities
{ {
public class QuestionEntity public class QuestionEntity
{ {
/// <summary>
/// represent a mathematical question
/// properties :
/// Id : identifier of the question in the database
/// Content : the content of the question
/// Difficulty : difficulty (between 1 and 3 included) of the question
/// 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
/// </summary>
[Key]
public int Id { get; set; } public int Id { get; set; }
public string Content { get; set; } public string Content { get; set; } = null!;
public int difficuty { get; set; } public int Difficuty { get; set; }
public int NbFalls { get; set; } public int NbFalls { get; set; }
[ForeignKey(nameof(ChapterEntity))]
public int IdChapter { get; set; } public int IdChapter { get; set; }
[ForeignKey(nameof(AnswerEntity))] [ForeignKey(nameof(AnswerEntity))]

@ -25,7 +25,7 @@ namespace ManagerInterfaces
/// this page (or null if (nb-1)*count /// this page (or null if (nb-1)*count
/// is outside boundaries (0, getNbElement()-1) /// is outside boundaries (0, getNbElement()-1)
/// </returns> /// </returns>
public IEnumerable<T>? getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById); public Task<(int nbAnswer, IEnumerable<T>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById);
/// <summary> /// <summary>
/// get a T element with an id /// get a T element with an id
/// </summary> /// </summary>
@ -33,7 +33,7 @@ namespace ManagerInterfaces
/// <returns> /// <returns>
/// a set of all T element that correspond to this question /// a set of all T element that correspond to this question
/// </returns> /// </returns>
public ReadOnlyCollection<T>? getAnswersByIdQuestion(long id); public Task<ReadOnlyCollection<T>?> getAnswersByIdQuestion(long id);
/// <summary> /// <summary>
/// modified a T element with an id /// modified a T element with an id
/// </summary> /// </summary>
@ -43,7 +43,7 @@ namespace ManagerInterfaces
/// the T element (modified) that corresponde /// the T element (modified) that corresponde
/// to the id or null if there isn't any /// to the id or null if there isn't any
/// </returns> /// </returns>
public T? modifierAnswer(long id, T answer); public Task<T?> modifierAnswer(long id, T answer);
/// <summary> /// <summary>
/// delete a T element with an id /// delete a T element with an id
/// </summary> /// </summary>
@ -52,12 +52,12 @@ namespace ManagerInterfaces
/// the T element deleted that corresponde /// the T element deleted that corresponde
/// to the id or null if there isn't any /// to the id or null if there isn't any
/// </returns> /// </returns>
public T? supprimerAnswer(long id); public Task<T?> supprimerAnswer(long id);
/// <summary> /// <summary>
/// delete a T element /// delete a T element
/// </summary> /// </summary>
/// <param name="answer">the T element to delete</param> /// <param name="answer">the T element to delete</param>
public void supprimerAnswer(T answer); public Task supprimerAnswer(T answer);
/// <summary> /// <summary>
/// add a T element /// add a T element
/// </summary> /// </summary>
@ -66,6 +66,6 @@ namespace ManagerInterfaces
/// the T element (modified) that corresponde /// the T element (modified) that corresponde
/// to the id or null if there isn't any /// to the id or null if there isn't any
/// </returns> /// </returns>
public T ajouterAnswer(T answer); public Task<T> ajouterAnswer(T answer);
} }
} }

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ManagerInterfaces
{
public interface IChapterManager<T>
{
Task ajouterChapitre(T chapter);
Task supprimerChapitre(T chapter);
Task<(int nbChapter, ReadOnlyCollection<T>)> getChapters();
}
}

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
{
public class Administrator
{
/// <summary>
/// define a DTO for an administrator
/// attributes :
/// id : identifier in the database
/// username : username for a player
/// hashedPassword : hashed of the password of the player
/// </summary>
private int id;
private string? username;
private string hashedPassword;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int Id
{
get => id;
private set { id = value < 0 ? 0 : value; }
}
public string Username
{
get { return username == null ? "" : username; }
private set { username = value == "" ? null : value; }
}
public string HashedPassword
{
get => hashedPassword;
set { hashedPassword = value; }
}
public Administrator(string username, string hashedPassword, int id)
{
this.Username = username;
this.HashedPassword = hashedPassword;
this.Id = id;
}
}
}

@ -1,53 +1,19 @@
namespace Model using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace model
{ {
/// <summary>
/// define an answer for a Question with Mutiple Choice
/// variable :
/// id : identifier in the database
/// content : content of the answer
/// </summary>
public class Answer public class Answer
{ {
private int id;
private string? content;
/// <summary>
/// property for id manipulations
/// </summary>
public int Id
{
get
{
return id;
}
private set
{
id = value < -1 ? -1 : value;
}
}
/// <summary>
/// property for content manipulations
/// </summary>
public string Content
{
get
{
return content == null ? "" : content;
}
set
{
content = value == "" ? null : value;
}
}
/// <summary> /// <summary>
/// constructor of an answer /// define a DTO for an answer for a Question with Mutiple Choice
/// properties :
/// Id : identifier in the database
/// Content : content of the answer
/// idQuestion : the id of the question which it answer to
/// </summary> /// </summary>
/// <param name="content">the content of an answer</param> public int Id { get; set; }
/// <param name="id">the id of an answer</param> public string Content { get; set; } = null!;
public Answer(string content, int id = -1) public int? IdQuestion { get; set; }
{
Id = id;
Content = content;
}
} }
} }

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
{
public class Chapter
{
/// <summary>
/// define a mathematical chapter or thematic
/// properties :
/// Id : identifier in the database
/// Name : name of the chapter
/// </summary>
public int Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -0,0 +1,27 @@
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 model
{
public class Lobby
{
/// <summary>
/// define a lobby for QMC rapidity fight
/// properties :
/// Id : identifier of the lobby in the database
/// Name : name of the lobby
/// Password : password require to access at the lobby
/// idCreator : identifier of the creator player
/// </summary>
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; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
{
public class Player
{
/// <summary>
/// define a DTO for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// HashedPassword : hashed of the password of the player
/// </summary>
public int Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
}

@ -0,0 +1,30 @@
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 model
{
public class Question
{
/// <summary>
/// represent a mathematical question
/// properties :
/// Id : identifier of the question in the database
/// Content : the content of the question
/// Difficulty : difficulty (between 1 and 3 included) of the question
/// 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
/// </summary>
public int Id { get; set; }
public string Content { get; set; } = null!;
public int Difficuty { get; set; }
public int NbFalls { get; set; }
public int IdChapter { get; set; }
public int IdAnswerGood { get; set; }
}
}

@ -8,7 +8,7 @@ namespace UnitTestsEntityManagers
public class UnitTestAnswerManager : AbstractUnitTestEM public class UnitTestAnswerManager : AbstractUnitTestEM
{ {
IEnumerable<AnswerEntity> answers = JsonConvert IEnumerable<AnswerEntity> answers = JsonConvert
.DeserializeObject<IEnumerable<AnswerEntity>> .DeserializeObject<List<AnswerEntity>>
(File.ReadAllTextAsync("../fake-Answers.json").Result)!; // if this is null, we don't want to continue (File.ReadAllTextAsync("../fake-Answers.json").Result)!; // if this is null, we don't want to continue
AnswerEntityManager mgr; AnswerEntityManager mgr;

Loading…
Cancel
Save