From bb234e77ac6e2e6df3a9ae600d522ef31adedde9 Mon Sep 17 00:00:00 2001 From: "damien.nortier" Date: Sun, 3 Mar 2024 13:11:10 +0100 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20des=20interfaces=20des=20manage?= =?UTF-8?q?rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApi/DTOs/AnswerDto.cs | 2 +- WebApi/Entities/AdministratorEntity.cs | 3 + WebApi/Entities/AnswerEntity.cs | 5 +- WebApi/Entities/ChapterEntity.cs | 2 + WebApi/Entities/LobbyEntity.cs | 2 + WebApi/Entities/PlayerEntity.cs | 3 + WebApi/Entities/PlayerEntityChapterEntity.cs | 3 + WebApi/Entities/QuestionEntity.cs | 2 + .../IAdministratorManager.cs | 76 +++++++++++ WebApi/ManagerInterfaces/IAnswerManager.cs | 41 +++--- WebApi/ManagerInterfaces/IChapterManager.cs | 69 +++++++++- WebApi/ManagerInterfaces/ILobbyManager.cs | 71 +++++++++++ WebApi/ManagerInterfaces/IPlayerManager.cs | 119 ++++++++++++++++++ WebApi/ManagerInterfaces/IQuestionManager.cs | 116 +++++++++++++++++ 14 files changed, 488 insertions(+), 26 deletions(-) create mode 100644 WebApi/ManagerInterfaces/IAdministratorManager.cs create mode 100644 WebApi/ManagerInterfaces/ILobbyManager.cs create mode 100644 WebApi/ManagerInterfaces/IPlayerManager.cs create mode 100644 WebApi/ManagerInterfaces/IQuestionManager.cs diff --git a/WebApi/DTOs/AnswerDto.cs b/WebApi/DTOs/AnswerDto.cs index 3e68657..7b7b874 100644 --- a/WebApi/DTOs/AnswerDto.cs +++ b/WebApi/DTOs/AnswerDto.cs @@ -15,7 +15,7 @@ namespace DTOs { public uint Id { get; set; } public string Content { get; set; } = null!; - public uint? IdQuestion { get; set; } + public uint IdQuestion { get; set; } public QuestionDto? Question { get; set; } = null!; } diff --git a/WebApi/Entities/AdministratorEntity.cs b/WebApi/Entities/AdministratorEntity.cs index e7a95bc..1cd09d5 100644 --- a/WebApi/Entities/AdministratorEntity.cs +++ b/WebApi/Entities/AdministratorEntity.cs @@ -14,8 +14,11 @@ namespace Entities public class AdministratorEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Username { get; set; } = null!; + [Required] public string HashedPassword { get; set; } = null!; } } diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs index 9822e04..fefe6de 100644 --- a/WebApi/Entities/AnswerEntity.cs +++ b/WebApi/Entities/AnswerEntity.cs @@ -15,11 +15,14 @@ namespace Entities public class AnswerEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Content { get; set; } = null!; + [Required] [ForeignKey(nameof(Question))] - public uint? IdQuestion { get; set; } + public uint IdQuestion { get; set; } public QuestionEntity? Question { get; set; } } diff --git a/WebApi/Entities/ChapterEntity.cs b/WebApi/Entities/ChapterEntity.cs index 35f74cf..c6289d1 100644 --- a/WebApi/Entities/ChapterEntity.cs +++ b/WebApi/Entities/ChapterEntity.cs @@ -13,7 +13,9 @@ namespace Entities public class ChapterEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Name { get; set; } = null!; } } diff --git a/WebApi/Entities/LobbyEntity.cs b/WebApi/Entities/LobbyEntity.cs index 879eb0b..8badbd9 100644 --- a/WebApi/Entities/LobbyEntity.cs +++ b/WebApi/Entities/LobbyEntity.cs @@ -17,7 +17,9 @@ namespace Entities public class LobbyEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Name { get; set; } = null!; public string Password { get; set; } = null!; public uint NbPlayers { get; set; } diff --git a/WebApi/Entities/PlayerEntity.cs b/WebApi/Entities/PlayerEntity.cs index ed0f388..1cb3846 100644 --- a/WebApi/Entities/PlayerEntity.cs +++ b/WebApi/Entities/PlayerEntity.cs @@ -14,8 +14,11 @@ namespace Entities public class PlayerEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Nickname { get; set; } = null!; + [Required] public string HashedPassword { get; set; } = null!; } } diff --git a/WebApi/Entities/PlayerEntityChapterEntity.cs b/WebApi/Entities/PlayerEntityChapterEntity.cs index 74f7a2a..25a23ac 100644 --- a/WebApi/Entities/PlayerEntityChapterEntity.cs +++ b/WebApi/Entities/PlayerEntityChapterEntity.cs @@ -20,14 +20,17 @@ namespace Entities public class PlayerEntityChapterEntity { [ForeignKey(nameof(Chapter))] + [DatabaseGenerated(DatabaseGeneratedOption.None)] public uint IdChapter { get; set; } [ForeignKey(nameof(Player))] + [DatabaseGenerated(DatabaseGeneratedOption.None)] 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 0b2a573..5f0d440 100644 --- a/WebApi/Entities/QuestionEntity.cs +++ b/WebApi/Entities/QuestionEntity.cs @@ -24,7 +24,9 @@ namespace Entities public class QuestionEntity { [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public uint Id { get; set; } + [Required] public string Content { get; set; } = null!; [AllowedValues(1, 2, 3)] public byte Difficulty { get; set; } diff --git a/WebApi/ManagerInterfaces/IAdministratorManager.cs b/WebApi/ManagerInterfaces/IAdministratorManager.cs new file mode 100644 index 0000000..b765df5 --- /dev/null +++ b/WebApi/ManagerInterfaces/IAdministratorManager.cs @@ -0,0 +1,76 @@ +using OrderCriterias; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManagerInterfaces +{ + /// + /// All methods to handle administrators + /// /!\ all methods returns a task + /// + /// a DTO, Entity or Model administrator + public interface IAdministratorManager + { + /// + /// get the number of T element + /// + /// the number of T element + public int getNbElements(); + /// + /// add a T element + /// + /// the administrator to add + /// + /// the T element that corresponde to + /// the administrator added or the administrator equal to this + /// administrator if this administrator was already added + /// + public Task addAdmin(T admin); + /// + /// remove a T element + /// + /// the administrator to remove + /// the administrator removed or null if there isn't any + public Task removeAdmin(T admin); + /// + /// remove a T element + /// + /// the id of the administrator to remove + /// the administrator removed or null if there isn't any + public Task removeAdmin(int id); + /// + /// get a part of all administrators + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// + public Task<(int nbPages, ReadOnlyCollection? administrators)> getAdministrators(int nb, int count, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById); + /// + /// get an administrator by his username + /// + /// the username of the administrator + /// the administrator that corresponde or null if there isn't any + public Task getAdministratorByUsername(string username); + /// + /// set the password of an administrator + /// + /// the username of the administrator + /// the hash of the new password + /// + /// true if the password was sucessful change + /// false otherwise (no administrator with this username + /// + public Task setPassword(string username, string newHashedPassword); + } +} diff --git a/WebApi/ManagerInterfaces/IAnswerManager.cs b/WebApi/ManagerInterfaces/IAnswerManager.cs index 538c843..f1630fc 100644 --- a/WebApi/ManagerInterfaces/IAnswerManager.cs +++ b/WebApi/ManagerInterfaces/IAnswerManager.cs @@ -5,15 +5,16 @@ namespace ManagerInterfaces { /// /// All methods to handle answers + /// /!\ all methods returns a task /// - /// a DTO or Entity type answer + /// a DTO, Entity or Model answer public interface IAnswerManager { /// /// get the number of T element /// /// the number of T element - abstract int getNbElement(); + public int getNbElements(); /// /// get a part of all answers /// @@ -21,19 +22,21 @@ namespace ManagerInterfaces /// number of T element in a page /// the order criteria /// - /// all T element of the database for - /// this page (or null if (nb-1)*count - /// is outside boundaries (0, getNbElement()-1) + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) /// - public Task<(int nbAnswers, ReadOnlyCollection? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById); + public Task<(int nbPages, ReadOnlyCollection? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById); /// - /// get a T element with an id + /// get some answers that answer to a question /// - /// the id of the T element question + /// the id of the question /// - /// a set of all T element that correspond to this question + /// a set of all T answers that answer to this question /// - public Task?> getAnswersByIdQuestion(long id); + public Task?> getAnswersByIdQuestion(uint id); /// /// modified a T element with an id /// @@ -43,7 +46,7 @@ namespace ManagerInterfaces /// the T element (modified) that corresponde /// to the id or null if there isn't any /// - public Task modifierAnswer(long id, T answer); + public Task updateAnswer(uint id, T answer); /// /// delete a T element with an id /// @@ -52,21 +55,23 @@ namespace ManagerInterfaces /// the T element deleted that corresponde /// to the id or null if there isn't any /// - public Task supprimerAnswer(long id); + public Task removeAnswer(uint id); /// /// delete a T element /// /// the T element to delete - public Task supprimerAnswer(T answer); + /// the answer removed or null if there wasn't any + public Task removeAnswer(T answer); /// /// add a T element /// /// the answer to add /// - /// the T element (modified) that corresponde - /// to the id or null if there isn't any + /// the T element that corresponde to + /// the answer added or the answer equal to this + /// answer if this answer was already added /// - public Task ajouterAnswer(T answer); + public Task addAnswer(T answer); /// /// get a T element with an id /// @@ -75,6 +80,6 @@ namespace ManagerInterfaces /// the T element that corresponde /// to the id or null if there isn't any /// - public Task getAnswer(long id); + public Task getAnswer(uint id); } -} +} \ No newline at end of file diff --git a/WebApi/ManagerInterfaces/IChapterManager.cs b/WebApi/ManagerInterfaces/IChapterManager.cs index 132dc38..495dea1 100644 --- a/WebApi/ManagerInterfaces/IChapterManager.cs +++ b/WebApi/ManagerInterfaces/IChapterManager.cs @@ -1,4 +1,5 @@ -using System; +using OrderCriterias; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -7,12 +8,68 @@ using System.Threading.Tasks; namespace ManagerInterfaces { + /// + /// All methods to handle chapters + /// /!\ all methods returns a task + /// + /// a DTO, Entity or Model chapter public interface IChapterManager { - Task ajouterChapitre(T chapter); - - Task supprimerChapitre(T chapter); - - Task<(int nbChapter, ReadOnlyCollection)> getChapters(); + /// + /// get the number of T element + /// + /// the number of T element + public int getNbElements(); + /// + /// add a chapter + /// + /// chapter to add + /// + /// the chapter added or the chapter that correspond + /// to it and that is already in the database + /// + Task addChapter(T chapter); + /// + /// remove a chapter + /// + /// the chapter to remove + /// + /// the chapter removed or null if + /// the chapter does not exist + /// + Task removeChapter(T chapter); + /// + /// remove a chapter + /// + /// the identifier of the chapter to remove + /// + /// the chapter removed or null if + /// the chapter does not exist + /// + Task removeChapter(uint id); + /// + /// get a chapter + /// + /// the identifier of the chapter to remove + /// + /// the chapter that correspond + /// to the id or null if the + /// chapter does not exist + /// + Task getChapter(uint id); + /// + /// get a part of all chapters + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// + Task<(int nbPages, ReadOnlyCollection? chapters)> getChapters(int nb, int count, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById); } } diff --git a/WebApi/ManagerInterfaces/ILobbyManager.cs b/WebApi/ManagerInterfaces/ILobbyManager.cs new file mode 100644 index 0000000..ba30722 --- /dev/null +++ b/WebApi/ManagerInterfaces/ILobbyManager.cs @@ -0,0 +1,71 @@ +using OrderCriterias; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManagerInterfaces +{ + /// + /// All methods to handle lobbies + /// /!\ all methods returns a task + /// + /// a DTO, Entity or Model lobby + public interface ILobbyManager + { + /// + /// get the number of T element + /// + /// the number of T element + public int getNbElements(); + /// + /// add a lobby + /// + /// the lobby to add + /// the lobby added + public Task addLobby(T lobby); + /// + /// delete a T element + /// + /// the lobby to remove + /// + /// the T element deleted or + /// null if there isn't any + /// + public Task removeLobby(T lobby); + /// + /// delete a T element with an id + /// + /// the id of the T element + /// + /// the T element deleted that corresponde + /// to the id or null if there isn't any + /// + public Task removeLobby(uint id); + /// + /// get a part of all lobbies + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// + public Task<(int nbPages, ReadOnlyCollection? lobbies)> getLobbies(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById); + /// + /// get a T element with an id + /// + /// the id of the T element + /// + /// the T element that corresponde + /// to the id or null if there isn't any + /// + public Task getLobby(uint id); + } +} \ No newline at end of file diff --git a/WebApi/ManagerInterfaces/IPlayerManager.cs b/WebApi/ManagerInterfaces/IPlayerManager.cs new file mode 100644 index 0000000..e5393e0 --- /dev/null +++ b/WebApi/ManagerInterfaces/IPlayerManager.cs @@ -0,0 +1,119 @@ +using OrderCriterias; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManagerInterfaces +{ + + /// + /// All methods to handle players + /// /!\ all methods returns a task + /// + /// a DTO, Entity or Model player + public interface IPlayerManager + { + /// + /// get the number of T element + /// + /// the number of T element + public int getNbElements(); + /// + /// add a player + /// + /// the player to add + /// + /// the T element that corresponde to + /// the player added or the player equal to this + /// player if this player was already added + /// + public Task addPlayer(T player); + /// + /// remove a player + /// + /// the player to remove + /// + /// the player removed or null if + /// the player does not exist + /// + public Task removePlayer(T player); + /// + /// remove a player + /// + /// the identifier of the player to remove + /// + /// the player removed or null if + /// the player does not exist + /// + Task removePlayer(uint id); + /// + /// get a part of all players + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// + public Task<(int nbPage, ReadOnlyCollection? players)> getPlayers(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById); + /// + /// get a player + /// + /// identifier of the player + /// + /// the player with this id + /// or null if no player match + /// with this id + /// + public Task getPlayer(int id); + /// + /// get a player + /// + /// nickname of the player + /// + /// the player with this nickname + /// or null if no player match + /// with this nickname + /// + public Task getPlayer(string nickname); + /// + /// get players in a lobby + /// + /// the id of the lobby they are inside + /// + /// a set of all players in this lobby + /// (we know that the lobby is at less + /// used by the creator) or null (and + /// delete the lobby) if it is used by + /// no player + /// + public Task?> getPlayersInALobby(int idLobby); + /// + /// get the max score of a player in a chapter + /// + /// identifier of the player + /// identifier of the chapter + /// + /// the max score of the player + /// or null if the player or + /// the chapter does not exist + /// + public Task getMaxScorePlayer(int id, int idChapter); + /// + /// get the global max score of a player + /// + /// identifier of the player + /// + /// the max score of the player + /// or null if the player does not exist + /// + public Task getMaxScorePlayer(int id); + } +} diff --git a/WebApi/ManagerInterfaces/IQuestionManager.cs b/WebApi/ManagerInterfaces/IQuestionManager.cs new file mode 100644 index 0000000..a777522 --- /dev/null +++ b/WebApi/ManagerInterfaces/IQuestionManager.cs @@ -0,0 +1,116 @@ +using OrderCriterias; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManagerInterfaces +{ + /// + /// All methods to handle questions + /// /!\ all methods returns a task + /// + /// a DTO, Entity or Model question + public interface IQuestionManager + { + /// + /// get the number of T element + /// + /// the number of T element + public int getNbElements(); + /// + /// add a question + /// + /// the question to add + /// the question added + public Task addQuestion(T question); + /// + /// delete a T element + /// + /// the question to remove + /// + /// the T element deleted or + /// null if there isn't any + /// + public Task removeQuestion(T question); + /// + /// delete a T element with an id + /// + /// the id of the T element + /// + /// the T element deleted that corresponde + /// to the id or null if there isn't any + /// + public Task removeQuestion(uint id); + /// + /// get a part of all questions + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// + public Task<(int nbPages, ReadOnlyCollection? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById); + /// + /// get a T element with an id + /// + /// the id of the T element + /// + /// the T element that corresponde + /// to the id or null if there isn't any + /// + public Task getQuestion(uint id); + /// + /// modified a T element with an id + /// + /// the id of the T element + /// an question that contains all modified properties + /// + /// the T element (modified) that corresponde + /// to the id or null if there isn't any + /// + public Task updateQuestion(uint id, T question); + /// + /// increase nbFalls of a question by 1 + /// (and change the difficulty of the question) + /// + /// the id of the question + /// + /// the T element (modified) that corresponde + /// to the id or null if there isn't any + /// + public Task updateQuestionNbFalls(uint id); + /// + /// add some questions + /// + /// a set of questions to add + /// questions added + public Task addQuestions(IEnumerable questions); + /// + /// get a part of all questions for a given chapter and a given difficulty + /// + /// the id of the chapter + /// the difficulty + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// a set of the number of page and + /// all T element in the database for + /// the page nb (or null if the page + /// does not exist (<=> (nb-1)*count outside + /// boundaries (0, getNbElement()-1))) + /// or null if the chapter does not exist + /// or the difficulty is not between 1 and 3 + /// + public Task<(int nbPages, ReadOnlyCollection? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById); + + } +}