création des interfaces des managers
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent aac8bf623b
commit bb234e77ac

@ -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!;
}

@ -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!;
}
}

@ -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; }
}

@ -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!;
}
}

@ -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; }

@ -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!;
}
}

@ -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; }
}
}

@ -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; }

@ -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
{
/// <summary>
/// All methods to handle administrators
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO, Entity or Model administrator</typeparam>
public interface IAdministratorManager<T>
{
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
public int getNbElements();
/// <summary>
/// add a T element
/// </summary>
/// <param name="admin">the administrator to add</param>
/// <returns>
/// the T element that corresponde to
/// the administrator added or the administrator equal to this
/// administrator if this administrator was already added
/// </returns>
public Task<T> addAdmin(T admin);
/// <summary>
/// remove a T element
/// </summary>
/// <param name="admin">the administrator to remove</param>
/// <returns>the administrator removed or null if there isn't any</returns>
public Task<T?> removeAdmin(T admin);
/// <summary>
/// remove a T element
/// </summary>
/// <param name="id">the id of the administrator to remove</param>
/// <returns>the administrator removed or null if there isn't any</returns>
public Task<T?> removeAdmin(int id);
/// <summary>
/// get a part of all administrators
/// </summary>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
public Task<(int nbPages, ReadOnlyCollection<T>? administrators)> getAdministrators(int nb, int count, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById);
/// <summary>
/// get an administrator by his username
/// </summary>
/// <param name="username">the username of the administrator</param>
/// <returns>the administrator that corresponde or null if there isn't any</returns>
public Task<T?> getAdministratorByUsername(string username);
/// <summary>
/// set the password of an administrator
/// </summary>
/// <param name="username">the username of the administrator</param>
/// <param name="newHashedPassword">the hash of the new password</param>
/// <returns>
/// true if the password was sucessful change
/// false otherwise (no administrator with this username
/// </returns>
public Task<bool> setPassword(string username, string newHashedPassword);
}
}

@ -5,15 +5,16 @@ namespace ManagerInterfaces
{
/// <summary>
/// All methods to handle answers
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO or Entity type answer</typeparam>
/// <typeparam name="T">a DTO, Entity or Model answer</typeparam>
public interface IAnswerManager<T>
{
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
abstract int getNbElement();
public int getNbElements();
/// <summary>
/// get a part of all answers
/// </summary>
@ -21,19 +22,21 @@ namespace ManagerInterfaces
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
public Task<(int nbAnswers, ReadOnlyCollection<T>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById);
public Task<(int nbPages, ReadOnlyCollection<T>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById);
/// <summary>
/// get a T element with an id
/// get some answers that answer to a question
/// </summary>
/// <param name="id">the id of the T element question</param>
/// <param name="id">the id of the question</param>
/// <returns>
/// a set of all T element that correspond to this question
/// a set of all T answers that answer to this question
/// </returns>
public Task<ReadOnlyCollection<T>?> getAnswersByIdQuestion(long id);
public Task<ReadOnlyCollection<T>?> getAnswersByIdQuestion(uint id);
/// <summary>
/// modified a T element with an id
/// </summary>
@ -43,7 +46,7 @@ namespace ManagerInterfaces
/// the T element (modified) that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> modifierAnswer(long id, T answer);
public Task<T?> updateAnswer(uint id, T answer);
/// <summary>
/// delete a T element with an id
/// </summary>
@ -52,21 +55,23 @@ namespace ManagerInterfaces
/// the T element deleted that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> supprimerAnswer(long id);
public Task<T?> removeAnswer(uint id);
/// <summary>
/// delete a T element
/// </summary>
/// <param name="answer">the T element to delete</param>
public Task supprimerAnswer(T answer);
/// <returns>the answer removed or null if there wasn't any</returns>
public Task<T?> removeAnswer(T answer);
/// <summary>
/// add a T element
/// </summary>
/// <param name="answer">the answer to add</param>
/// <returns>
/// 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
/// </returns>
public Task<T> ajouterAnswer(T answer);
public Task<T> addAnswer(T answer);
/// <summary>
/// get a T element with an id
/// </summary>
@ -75,6 +80,6 @@ namespace ManagerInterfaces
/// the T element that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> getAnswer(long id);
public Task<T?> getAnswer(uint id);
}
}
}

@ -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
{
/// <summary>
/// All methods to handle chapters
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO, Entity or Model chapter</typeparam>
public interface IChapterManager<T>
{
Task ajouterChapitre(T chapter);
Task supprimerChapitre(T chapter);
Task<(int nbChapter, ReadOnlyCollection<T>)> getChapters();
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
public int getNbElements();
/// <summary>
/// add a chapter
/// </summary>
/// <param name="chapter">chapter to add</param>
/// <returns>
/// the chapter added or the chapter that correspond
/// to it and that is already in the database
/// </returns>
Task<T> addChapter(T chapter);
/// <summary>
/// remove a chapter
/// </summary>
/// <param name="chapter">the chapter to remove</param>
/// <returns>
/// the chapter removed or null if
/// the chapter does not exist
/// </returns>
Task<T?> removeChapter(T chapter);
/// <summary>
/// remove a chapter
/// </summary>
/// <param name="id">the identifier of the chapter to remove</param>
/// <returns>
/// the chapter removed or null if
/// the chapter does not exist
/// </returns>
Task<T?> removeChapter(uint id);
/// <summary>
/// get a chapter
/// </summary>
/// <param name="id">the identifier of the chapter to remove</param>
/// <returns>
/// the chapter that correspond
/// to the id or null if the
/// chapter does not exist
/// </returns>
Task<T?> getChapter(uint id);
/// <summary>
/// get a part of all chapters
/// </summary>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
Task<(int nbPages, ReadOnlyCollection<T>? chapters)> getChapters(int nb, int count, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById);
}
}

@ -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
{
/// <summary>
/// All methods to handle lobbies
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO, Entity or Model lobby</typeparam>
public interface ILobbyManager<T>
{
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
public int getNbElements();
/// <summary>
/// add a lobby
/// </summary>
/// <param name="lobby">the lobby to add</param>
/// <returns>the lobby added</returns>
public Task<T> addLobby(T lobby);
/// <summary>
/// delete a T element
/// </summary>
/// <param name="lobby">the lobby to remove</param>
/// <returns>
/// the T element deleted or
/// null if there isn't any
/// </returns>
public Task<T?> removeLobby(T lobby);
/// <summary>
/// delete a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <returns>
/// the T element deleted that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> removeLobby(uint id);
/// <summary>
/// get a part of all lobbies
/// </summary>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
public Task<(int nbPages, ReadOnlyCollection<T>? lobbies)> getLobbies(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById);
/// <summary>
/// get a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <returns>
/// the T element that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> getLobby(uint id);
}
}

@ -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
{
/// <summary>
/// All methods to handle players
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO, Entity or Model player</typeparam>
public interface IPlayerManager<T>
{
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
public int getNbElements();
/// <summary>
/// add a player
/// </summary>
/// <param name="player">the player to add</param>
/// <returns>
/// the T element that corresponde to
/// the player added or the player equal to this
/// player if this player was already added
/// </returns>
public Task<T> addPlayer(T player);
/// <summary>
/// remove a player
/// </summary>
/// <param name="player">the player to remove</param>
/// <returns>
/// the player removed or null if
/// the player does not exist
/// </returns>
public Task<T?> removePlayer(T player);
/// <summary>
/// remove a player
/// </summary>
/// <param name="id">the identifier of the player to remove</param>
/// <returns>
/// the player removed or null if
/// the player does not exist
/// </returns>
Task<T?> removePlayer(uint id);
/// <summary>
/// get a part of all players
/// </summary>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
public Task<(int nbPage, ReadOnlyCollection<T>? players)> getPlayers(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById);
/// <summary>
/// get a player
/// </summary>
/// <param name="id">identifier of the player</param>
/// <returns>
/// the player with this id
/// or null if no player match
/// with this id
/// </returns>
public Task<T?> getPlayer(int id);
/// <summary>
/// get a player
/// </summary>
/// <param name="nickname">nickname of the player</param>
/// <returns>
/// the player with this nickname
/// or null if no player match
/// with this nickname
/// </returns>
public Task<T?> getPlayer(string nickname);
/// <summary>
/// get players in a lobby
/// </summary>
/// <param name="idLobby">the id of the lobby they are inside</param>
/// <returns>
/// 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
/// </returns>
public Task<ReadOnlyCollection<T>?> getPlayersInALobby(int idLobby);
/// <summary>
/// get the max score of a player in a chapter
/// </summary>
/// <param name="id">identifier of the player</param>
/// <param name="idChapter">identifier of the chapter</param>
/// <returns>
/// the max score of the player
/// or null if the player or
/// the chapter does not exist
/// </returns>
public Task<int?> getMaxScorePlayer(int id, int idChapter);
/// <summary>
/// get the global max score of a player
/// </summary>
/// <param name="id">identifier of the player</param>
/// <returns>
/// the max score of the player
/// or null if the player does not exist
/// </returns>
public Task<int?> getMaxScorePlayer(int id);
}
}

@ -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
{
/// <summary>
/// All methods to handle questions
/// /!\ all methods returns a task
/// </summary>
/// <typeparam name="T">a DTO, Entity or Model question</typeparam>
public interface IQuestionManager<T>
{
/// <summary>
/// get the number of T element
/// </summary>
/// <returns>the number of T element</returns>
public int getNbElements();
/// <summary>
/// add a question
/// </summary>
/// <param name="question">the question to add</param>
/// <returns>the question added</returns>
public Task<T> addQuestion(T question);
/// <summary>
/// delete a T element
/// </summary>
/// <param name="question">the question to remove</param>
/// <returns>
/// the T element deleted or
/// null if there isn't any
/// </returns>
public Task<T?> removeQuestion(T question);
/// <summary>
/// delete a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <returns>
/// the T element deleted that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> removeQuestion(uint id);
/// <summary>
/// get a part of all questions
/// </summary>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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)))
/// </returns>
public Task<(int nbPages, ReadOnlyCollection<T>? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById);
/// <summary>
/// get a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <returns>
/// the T element that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> getQuestion(uint id);
/// <summary>
/// modified a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <param name="question">an question that contains all modified properties</param>
/// <returns>
/// the T element (modified) that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> updateQuestion(uint id, T question);
/// <summary>
/// increase nbFalls of a question by 1
/// (and change the difficulty of the question)
/// </summary>
/// <param name="id">the id of the question</param>
/// <returns>
/// the T element (modified) that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> updateQuestionNbFalls(uint id);
/// <summary>
/// add some questions
/// </summary>
/// <param name="questions">a set of questions to add</param>
/// <returns>questions added</returns>
public Task<T> addQuestions(IEnumerable<T> questions);
/// <summary>
/// get a part of all questions for a given chapter and a given difficulty
/// </summary>
/// <param name="idChapter">the id of the chapter</param>
/// <param name="difficulty">the difficulty</param>
/// <param name="nb">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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
/// </returns>
public Task<(int nbPages, ReadOnlyCollection<T>? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById);
}
}
Loading…
Cancel
Save