From 9ccf950f7c57c403d81f191c8fb6893c344873a0 Mon Sep 17 00:00:00 2001 From: Damien Nortier Date: Thu, 14 Mar 2024 22:38:40 +0100 Subject: [PATCH] =?UTF-8?q?feat=20+=20refactor=20:=20ajout=20du=20contr?= =?UTF-8?q?=C3=B4leur=20des=20chapitres=20+=20cr=C3=A9ation=20d'unit=C3=A9?= =?UTF-8?q?=20de=20centralisation=20des=20requ=C3=AAtes=20(~=20unit=C3=A9?= =?UTF-8?q?=20de=20travail)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AdministratorController.cs | 46 ++- WebApi/WebApi/Controllers/AnswerController.cs | 6 - .../WebApi/Controllers/ChapterController.cs | 302 +++++++++++++++++- WebApi/WebApi/Controllers/FrontController.cs | 138 +++++++- WebApi/WebApi/Unit.cs | 293 +++++++++++++++++ 5 files changed, 744 insertions(+), 41 deletions(-) delete mode 100644 WebApi/WebApi/Controllers/AnswerController.cs create mode 100644 WebApi/WebApi/Unit.cs diff --git a/WebApi/WebApi/Controllers/AdministratorController.cs b/WebApi/WebApi/Controllers/AdministratorController.cs index 90254fc..b6229a0 100644 --- a/WebApi/WebApi/Controllers/AdministratorController.cs +++ b/WebApi/WebApi/Controllers/AdministratorController.cs @@ -10,17 +10,15 @@ using Microsoft.AspNetCore.Http.HttpResults; namespace WebApi.Controllers { - [ApiController] - [Route("api/v[version]/")] public class AdministratorController : ControllerBase { - private IAdministratorManager mgr; + private Unit unity; private readonly Logger logger; - public AdministratorController(MyDbContext dbContext, Logger logger) + public AdministratorController(Unit unit, Logger logger) { - mgr = new AdministratorServiceManager(dbContext); + this.unity = unit; this.logger = logger; } @@ -42,9 +40,9 @@ namespace WebApi.Controllers /// public async Task PostAdministrator(AdministratorDto administrator) { - int count = mgr.getNbElements(); // count : number of elements before opperation - var tmp = await mgr.addAdmin(administrator); // tmp : administrator recieve by the addAdmin method - if (mgr.getNbElements() == count) // <=> not added + int count = unity.getNbAdmins(); // count : number of elements before opperation + var tmp = await unity.addAdmin(administrator); // tmp : administrator recieve by the addAdmin method + if (unity.getNbAdmins() == count) // <=> not added { if(tmp.Username == administrator.Username) { @@ -73,7 +71,7 @@ namespace WebApi.Controllers else { // the administrator may be added but we do not recieved him - if (mgr.getAdministratorByUsername(administrator.Username) != null) + if (unity.getAdministratorByUsername(administrator.Username) != null) { // he is added logger.LogError(message: $"administrator added but not recieved"); @@ -83,7 +81,7 @@ namespace WebApi.Controllers { // he is not added logger.LogCritical(message: "administrator that we wanted to add not added\nand we have added another one"); - if (mgr.getAdministratorByUsername(administrator.Username) == null) // <=> not added + if (unity.getAdministratorByUsername(administrator.Username) == null) // <=> not added return StatusCode(500); } } @@ -105,14 +103,14 @@ namespace WebApi.Controllers /// /// return content : /// a tuple of the number of page and - /// all T element in the database for + /// all administrators in the database for /// the page nb if status code = 200 /// the number of page for count element if status code = 204 /// nothing if status code = 400 /// public async Task GetSomeAdministrators(int page, int count = 10, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById) { - var tmp = await mgr.getAdministrators(page, count, orderCriteria); + var tmp = await unity.getAdministrators(page, count, orderCriteria); if (tmp.administrators == null) { logger.LogInformation(message: "get admin : bad request (page or/and count incorrect)"); @@ -120,7 +118,7 @@ namespace WebApi.Controllers } else if (tmp.administrators.Count() == 0) { - logger.LogWarning(message: $"get admin : no content. number of element : {mgr.getNbElements()}, page wanted : {page}, number of elements in a page : {count}"); + logger.LogWarning(message: $"get admin : no content. number of element : {unity.getNbAdmins()}, page wanted : {page}, number of elements in a page : {count}"); return NoContent(); } else @@ -159,13 +157,13 @@ namespace WebApi.Controllers logger.LogError("want to delete an administrator with an id less than 0"); return BadRequest(); } - int count = mgr.getNbElements(); // count : number of elements before opperation - var tmp = await mgr.removeAdmin(id); + int count = unity.getNbAdmins(); // count : number of elements before opperation + var tmp = await unity.removeAdmin(id); if (tmp == null) // we don't recieve the administrator { - if(mgr.getNbElements() == count) // he is not deleted + if(unity.getNbAdmins() == count) // he is not deleted { - if (mgr.getAdministrator(id) != null) + if (unity.getAdministrator(id) != null) { logger.LogCritical(message: "remove administrator fail : administrator not removed and not recieved"); return StatusCode(500); @@ -178,7 +176,7 @@ namespace WebApi.Controllers } else // he may be deleted { - if (mgr.getAdministrator(id) == null) // he must be deleted + if (unity.getAdministrator(id) == null) // he must be deleted { logger.LogError(message: "administrator removed but not returned"); return NoContent(); @@ -190,7 +188,7 @@ namespace WebApi.Controllers } } } - if(mgr.getNbElements() == count) + if(unity.getNbAdmins() == count) { // <=> we have recieved an administrator which should be deleted // but since we have the same number of administrator than @@ -222,16 +220,16 @@ namespace WebApi.Controllers /// public async Task PutAdministrator(int id, AdministratorDto administrator) { - var tmp = await mgr.getAdministratorByUsername(administrator.Username); + var tmp = await unity.getAdministratorByUsername(administrator.Username); if (tmp != null) { logger.LogTrace(message: "Want to modify into an administrator who already exist"); return StatusCode(StatusCodes.Status208AlreadyReported, tmp); } - tmp = await mgr.updateAdministrator(id, administrator); + tmp = await unity.updateAdministrator(id, administrator); if(tmp == null) { - tmp = await mgr.getAdministrator(id); + tmp = await unity.getAdministrator(id); if (tmp == null) // Ok, it don't exist { logger.LogWarning(message: "Want to modify an administrator who don't exist"); @@ -261,7 +259,7 @@ namespace WebApi.Controllers } else // he haven't changed { - var tmp2 = (await mgr.getAdministratorByUsername(administrator.Username)); + var tmp2 = (await unity.getAdministratorByUsername(administrator.Username)); if(tmp2 != null) // it change another administrator logger.LogCritical(message: "administrator should have changed but he haven't. Instead, another one changed"); else // nothing have changed @@ -271,7 +269,7 @@ namespace WebApi.Controllers } else // we recieve another one { - var tmp2 = await mgr.getAdministrator(id); + var tmp2 = await unity.getAdministrator(id); if (tmp2 == null) { // ok, he d'ont exist. logger.LogError(message: "Want to modify an administrator who don't exist but recieved a random one"); diff --git a/WebApi/WebApi/Controllers/AnswerController.cs b/WebApi/WebApi/Controllers/AnswerController.cs deleted file mode 100644 index ea55e11..0000000 --- a/WebApi/WebApi/Controllers/AnswerController.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace WebApi.Controllers -{ - public class AnswerController - { - } -} diff --git a/WebApi/WebApi/Controllers/ChapterController.cs b/WebApi/WebApi/Controllers/ChapterController.cs index ed02709..9b87c19 100644 --- a/WebApi/WebApi/Controllers/ChapterController.cs +++ b/WebApi/WebApi/Controllers/ChapterController.cs @@ -1,6 +1,304 @@ -namespace WebApi.Controllers +using DTOs; +using Microsoft.AspNetCore.Mvc; +using OrderCriterias; + +namespace WebApi.Controllers { - public class ChapterController + public class ChapterController : ControllerBase { + private Unit unity; + + private readonly Logger logger; + + public ChapterController(Unit unit, Logger logger) + { + this.unity = unit; + this.logger = logger; + } + + /// + /// add a chapter + /// + /// the chapter to add + /// + /// status code : + /// 200 if the chapter is added + /// 202 if the chapter is added + /// 208 if the chapter was already in the database + /// 500 if there was an internal error that doesn't allow to continue + /// return content : + /// no content when status code = 200 + /// chapter added when status code = 202 + /// chapter already in the database that equals the one we wanted to add when status code = 208 + /// no content when status code = 500 + /// + public async Task PostChapter(ChapterDto chapter) + { + int count = unity.getNbChapters(); // count : number of elements before opperation + var tmp = await unity.addChapter(chapter); // tmp : chapter recieve by the addChapter method + if (unity.getNbChapters() == count) // <=> not added + { + if (tmp.Name == chapter.Name) + { + // it was already in the database + logger.LogInformation(message: $"want to add a chapter already in the database : {tmp.ToString()}"); + return StatusCode(208, tmp); + } + else + { + // we recieve a chapter already in the database + // that should be equal to the chapter that we + // wanted to add but it isn't + logger.LogCritical(message: "controller's add fail (already in the database) but\nchapter" + + $" recieve isn't the same as the one we wanted to add.\n" + + $"Chapter recieve : {tmp.ToString()}\nchapter to add : {chapter.ToString()}"); + return StatusCode(500); + } + } + // added + if (tmp.Name == chapter.Name) + { + logger.LogTrace(message: $"chapter added : {tmp.ToString()}"); + // the chapter has been added and we recieved him + return StatusCode(202, tmp); + } + else + { + // the chapter may be added but we do not recieved him + if (unity.getChapter(chapter.Name) != null) + { + // he is added + logger.LogError(message: $"chapter added but not recieved"); + return Ok(); // not 202 to make a difference between 2 cases + } + else + { + // he is not added + logger.LogCritical(message: "chapter that we wanted to add not added\nand we have added another one"); + if (unity.getChapter(chapter.Name) == null) // <=> not added + return StatusCode(500); + } + } + logger.LogError(message: "this case should not append"); + return StatusCode(500); + } + + /// + /// get a part of all chapters + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// status code : + /// 200 if we got a set + /// 204 if we got an empty set + /// 400 if we got nothing + /// + /// return content : + /// a tuple of the number of page and + /// all chapters in the database for + /// the page nb if status code = 200 + /// the number of page for count element if status code = 204 + /// nothing if status code = 400 + /// + public async Task GetSomeChapters(int page, int count = 10, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById) + { + var tmp = await unity.getChapters(page, count, orderCriteria); + if (tmp.chapters == null) + { + logger.LogInformation(message: "get chapter : bad request (page or/and count incorrect)"); + return BadRequest(tmp.nbPages); + } + else if (tmp.chapters.Count() == 0) + { + logger.LogWarning(message: $"get chapter : no content. number of element : {unity.getNbChapters()}, page wanted : {page}, number of elements in a page : {count}"); + return NoContent(); + } + else + { + logger.LogTrace(message: $"get chapters : page = {page}, count = {count}, order criteria = {orderCriteria switch + { + ChapterOrderCriteria.ById => "byId", + ChapterOrderCriteria.ByName => "byName", + _ => "none" + }}"); + return Ok(tmp); + } + } + + /// + /// delete a chapter + /// + /// the id of the chapter to delete + /// + /// + /// status code : + /// 200 if the chapter is removed + /// 204 if the chapter is removed + /// 400 if the id is incorrect + /// 500 if there was an internal error that doesn't allow to continue + /// return content : + /// aministrator deleted when status code = 200 + /// no content when status code = 204 + /// no content when status code = 400 + /// no content when status code = 500 + /// + public async Task DeleteChapter(int id) + { + if (id < 0) + { + logger.LogError("want to delete a chapter with an id less than 0"); + return BadRequest(); + } + int count = unity.getNbChapters(); // count : number of elements before opperation + var tmp = await unity.removeChapter(id); + if (tmp == null) // we don't recieve the chapter + { + if (unity.getNbChapters() == count) // he is not deleted + { + if (unity.getChapter(id) != null) + { + logger.LogCritical(message: "remove chapter fail : chapter not removed and not recieved"); + return StatusCode(500); + } + else + { + logger.LogInformation(message: "trying to remove a chapter with an id who don't exist"); + return BadRequest(); + } + } + else // he may be deleted + { + if (unity.getChapter(id) == null) // he must be deleted + { + logger.LogError(message: "chapter removed but not returned"); + return NoContent(); + } + else // he is not deleted + { + logger.LogCritical(message: "remove chapter fail : chapter to remove not remove\ninstead, anotherone is deleted and we recieved nothing"); + return StatusCode(500); + } + } + } + if (unity.getNbChapters() == count) + { + // <=> we have recieved a chapter which should be deleted + // but since we have the same number of chapter than + // before deletion, it isn't deleted + logger.LogCritical(message: $"chapter \"{tmp.ToString()}\"should be delete but it isn't"); + return StatusCode(500); + } + logger.LogTrace(message: $"chapter removed {tmp.ToString()}"); + return Ok(tmp); + } + + /// + /// update a chapter + /// + /// id of the chapter to update + /// a chapter who contains all properties to change + /// + /// status code : + /// 200 if the chapter is modified + /// 204 if we wanted to modify a chapter who don't exist + /// 208 if the new username of the chapter is already used + /// 500 if there was an internal error that doesn't allow to continue + /// + /// return content : + /// the chapter modified when status code = 200 + /// nothing when status code = 204 + /// the chapter that already have the username when status code = 208 + /// nothing when status code = 500 + /// + public async Task PutChapter(int id, ChapterDto chapter) + { + var tmp = await unity.getChapter(chapter.Name); + if (tmp != null) + { + logger.LogTrace(message: "Want to modify into a chapter who already exist"); + return StatusCode(StatusCodes.Status208AlreadyReported, tmp); + } + tmp = await unity.updateChapter(id, chapter.Name); + if (tmp == null) + { + tmp = await unity.getChapter(id); + if (tmp == null) // Ok, it don't exist + { + logger.LogWarning(message: "Want to modify a chapter who don't exist"); + return NoContent(); + } + else + { + if (tmp.Name == chapter.Name) + { + logger.LogError(message: "Chapter changed but not recieved"); + return Ok(tmp); + } + else + { + logger.LogCritical(message: "chapter haven't changed and we recieved nothing"); + return StatusCode(500); + } + } + } + else if (tmp.Id == id) // we recieve him + { + if (tmp.Name == chapter.Name) // he is changed + { + logger.LogTrace(message: $"chapter with id {id} modified in {chapter.ToString()}"); + return Ok(tmp); + } + else // he haven't changed + { + var tmp2 = (await unity.getChapter(chapter.Name)); + if (tmp2 != null) // it change another chapter + logger.LogCritical(message: "chapter should have changed but he haven't. Instead, another one changed"); + else // nothing have changed + logger.LogCritical(message: "chapter should have changed but he haven't and we recieved him"); + return StatusCode(500); + } + } + else // we recieve another one + { + var tmp2 = await unity.getChapter(id); + if (tmp2 == null) + { // ok, he d'ont exist. + logger.LogError(message: "Want to modify a chapter who don't exist but recieved a random one"); + return NoContent(); + } + else if (tmp2.Name == chapter.Name) + { + logger.LogError(message: $"chapter modified but recieved a random one"); + return Ok(tmp2); + } + else + { + logger.LogCritical(message: "chapter that we wanted to modify not modified"); + return StatusCode(500); + } + } + } + + /// + /// get a chapter + /// + /// the name of the chapter + /// + /// status code : + /// 200 when we got a chapter + /// 204 when we got null + /// + /// return content : + /// the chapter that correspond to the name when status code = 200 + /// nothing when status code 204 + /// + public async Task GetChapter(string name) + { + var tmp = await unity.getChapter(name); + if(tmp == null) return NoContent(); + return Ok(tmp); + } } } diff --git a/WebApi/WebApi/Controllers/FrontController.cs b/WebApi/WebApi/Controllers/FrontController.cs index 08ec160..3d0a7f6 100644 --- a/WebApi/WebApi/Controllers/FrontController.cs +++ b/WebApi/WebApi/Controllers/FrontController.cs @@ -1,6 +1,7 @@ using DbConnectionLibrairie; using DTOs; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using OrderCriterias; namespace WebApi.Controllers @@ -9,7 +10,6 @@ namespace WebApi.Controllers { // all secondary controllers private AdministratorController administratorController; - private AnswerController answerController; private ChapterController chapterController; private LobbyController lobbyController; private PlayerController playerController; @@ -18,19 +18,18 @@ namespace WebApi.Controllers public FrontController( MyDbContext dbContext, Logger logAdmin, - Logger logAnswer, Logger logChapter, Logger logLobby, Logger logPlayer, Logger logQuestion ) { - administratorController = new AdministratorController(dbContext, logAdmin); - answerController = new AnswerController(dbContext, logAnswer); - chapterController = new ChapterController(dbContext, logChapter); - lobbyController = new LobbyController(dbContext, logLobby); - playerController = new PlayerController(dbContext, logPlayer); - questionController = new QuestionController(dbContext, logQuestion); + var unity = new Unit(dbContext); + administratorController = new AdministratorController(unity, logAdmin); + chapterController = new ChapterController(unity, logChapter); + lobbyController = new LobbyController(unity, logLobby); + playerController = new PlayerController(unity, logPlayer); + questionController = new QuestionController(unity, logQuestion); } /// @@ -71,7 +70,7 @@ namespace WebApi.Controllers /// /// return content : /// a tuple of the number of page and - /// all T element in the database for + /// all administrators in the database for /// the page nb if status code = 200 /// the number of page for count element if status code = 204 /// nothing if status code = 400 @@ -136,5 +135,126 @@ namespace WebApi.Controllers => await administratorController.PutAdministrator(id, administrator); + + /// + /// add a chapter + /// + /// the chapter to add + /// + /// status code : + /// 200 if the chapter is added + /// 202 if the chapter is added + /// 208 if the chapter was already in the database + /// 500 if there was an internal error that doesn't allow to continue + /// return content : + /// no content when status code = 200 + /// chapter added when status code = 202 + /// chapter already in the database that equals the one we wanted to add when status code = 208 + /// no content when status code = 500 + /// + [HttpPost("add/chapter")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status202Accepted)] + [ProducesResponseType(StatusCodes.Status208AlreadyReported)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task PostChapter([FromBody] ChapterDto chapter) + => await chapterController.PostChapter(chapter); + + /// + /// get a part of all chapters + /// + /// the actual page + /// number of T element in a page + /// the order criteria + /// + /// status code : + /// 200 if we got a set + /// 204 if we got an empty set + /// 400 if we got nothing + /// + /// return content : + /// a tuple of the number of page and + /// all chapters in the database for + /// the page nb if status code = 200 + /// the number of page for count element if status code = 204 + /// nothing if status code = 400 + /// + [HttpGet("all/chapter")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task GetSomeChapters([FromQuery] int page, int count = 10, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById) + => await chapterController.GetSomeChapters(page, count, orderCriteria); + + /// + /// delete a chapter + /// + /// the id of the chapter to delete + /// + /// + /// status code : + /// 200 if the chapter is removed + /// 204 if the chapter is removed + /// 400 if the id is incorrect + /// 500 if there was an internal error that doesn't allow to continue + /// return content : + /// aministrator deleted when status code = 200 + /// no content when status code = 204 + /// no content when status code = 400 + /// no content when status code = 500 + /// + [HttpDelete("delete/chapter")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteChapter([FromQuery] int id) + => await chapterController.DeleteChapter(id); + + /// + /// update a chapter + /// + /// id of the chapter to update + /// a chapter who contains all properties to change + /// + /// status code : + /// 200 if the chapter is modified + /// 204 if we wanted to modify a chapter who don't exist + /// 208 if the new username of the chapter is already used + /// 500 if there was an internal error that doesn't allow to continue + /// + /// return content : + /// the chapter modified when status code = 200 + /// nothing when status code = 204 + /// the chapter that already have the username when status code = 208 + /// nothing when status code = 500 + /// + [HttpPut("update/chapter")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status208AlreadyReported)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task PutChapter([FromQuery] int id, [FromBody] ChapterDto chapter) + => await chapterController.PutChapter(id, chapter); + + /// + /// get a chapter + /// + /// the name of the chapter + /// + /// status code : + /// 200 when we got a chapter + /// 204 when we got null + /// + /// return content : + /// the chapter that correspond to the name when status code = 200 + /// nothing when status code 204 + /// + [HttpGet("chapters/name")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public async Task GetChapter(string name) + => await chapterController.GetChapter(name); + } } diff --git a/WebApi/WebApi/Unit.cs b/WebApi/WebApi/Unit.cs new file mode 100644 index 0000000..a60ffe1 --- /dev/null +++ b/WebApi/WebApi/Unit.cs @@ -0,0 +1,293 @@ +using DbConnectionLibrairie; +using DTOs; +using ManagerInterfaces; +using OrderCriterias; +using ServiceManagers; + +namespace WebApi +{ + /// + /// just an interface between service managers and controllers + /// which contains all service managers methods who just calls + /// methods of service managers (we don't care about awaiting) + /// + public class Unit : IAdministratorManager, IAnswerManager, IChapterManager, ILobbyManager, IPlayerManager, IQuestionManager + { + public IAdministratorManager AdministratorManager { get; set; } + public IAnswerManager AnswerManager { get; set; } + public IChapterManager ChapterManager { get; private set; } + public ILobbyManager LobbyManager { get; private set; } + public IPlayerManager PlayerManager { get; private set; } + public IQuestionManager QuestionManager { get; private set; } + + public Unit(MyDbContext dbContext) + { + AdministratorManager = new AdministratorServiceManager(dbContext); + AnswerManager = new AnswerServiceManager(dbContext); + ChapterManager = new ChapterServiceManager(dbContext); + LobbyManager = new LobbyServiceManager(dbContext); + PlayerManager = new PlayerServiceManager(dbContext); + QuestionManager = new QuestionServiceManager(dbContext); + } + + public int getNbAdmins() + { + return AdministratorManager.getNbAdmins(); + } + + public Task addAdmin(AdministratorDto admin) + { + return AdministratorManager.addAdmin(admin); + } + + public Task removeAdmin(AdministratorDto admin) + { + return AdministratorManager.removeAdmin(admin); + } + + public Task removeAdmin(int id) + { + return AdministratorManager.removeAdmin(id); + } + + public Task<(int nbPages, IEnumerable? administrators)> getAdministrators(int page, int count, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById) + { + return AdministratorManager.getAdministrators(page, count, orderCriteria); + } + + public Task getAdministrator(int id) + { + return AdministratorManager.getAdministrator(id); + } + + public Task getAdministratorByUsername(string username) + { + return AdministratorManager.getAdministratorByUsername(username); + } + + public Task setPassword(string username, string newHashedPassword) + { + return AdministratorManager.setPassword(username, newHashedPassword); + } + + public Task updateAdministrator(int id, AdministratorDto admin) + { + return AdministratorManager.updateAdministrator(id, admin); + } + + public int getNbAnswers() + { + return AnswerManager.getNbAnswers(); + } + + public Task<(int nbPages, IEnumerable? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById) + { + return AnswerManager.getAnswers(nb, count, orderCriteria); + } + + public Task?> getAnswers(string content) + { + return AnswerManager.getAnswers(content); + } + + public Task?> getAnswersByIdQuestion(int id) + { + return AnswerManager.getAnswersByIdQuestion(id); + } + + public Task updateAnswer(int id, AnswerDto answer) + { + return AnswerManager.updateAnswer(id, answer); + } + + public Task removeAnswer(int id) + { + return AnswerManager.removeAnswer(id); + } + + public Task removeAnswer(AnswerDto answer) + { + return AnswerManager.removeAnswer(answer); + } + + public Task addAnswer(AnswerDto answer) + { + return AnswerManager.addAnswer(answer); + } + + public Task getAnswer(int id) + { + return AnswerManager.getAnswer(id); + } + + public int getNbChapters() + { + return ChapterManager.getNbChapters(); + } + + public Task addChapter(ChapterDto chapter) + { + return ChapterManager.addChapter(chapter); + } + + public Task removeChapter(ChapterDto chapter) + { + return ChapterManager.removeChapter(chapter); + } + + public Task removeChapter(int id) + { + return ChapterManager.removeChapter(id); + } + + public Task getChapter(int id) + { + return ChapterManager.getChapter(id); + } + + public Task getChapter(string name) + { + return ChapterManager.getChapter(name); + } + + public Task<(int nbPages, IEnumerable? chapters)> getChapters(int nb, int count, ChapterOrderCriteria orderCriteria = ChapterOrderCriteria.ById) + { + return ChapterManager.getChapters(nb, count, orderCriteria); + } + + public Task updateChapter(int id, string newName) + { + return ChapterManager.updateChapter(id, newName); + } + + public int getNbLobbies() + { + return LobbyManager.getNbLobbies(); + } + + public Task addLobby(LobbyDto lobby) + { + return LobbyManager.addLobby(lobby); + } + + public Task removeLobby(LobbyDto lobby) + { + return LobbyManager.removeLobby(lobby); + } + + public Task removeLobby(int id) + { + return LobbyManager.removeLobby(id); + } + + public Task<(int nbPages, IEnumerable? lobbies)> getLobbies(int nb, int count, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById) + { + return LobbyManager.getLobbies(nb, count, orderCriteria); + } + + public Task getLobby(int id) + { + return LobbyManager.getLobby(id); + } + + public int getNbPlayers() + { + return PlayerManager.getNbPlayers(); + } + + public Task addPlayer(PlayerDto player) + { + return PlayerManager.addPlayer(player); + } + + public Task removePlayer(PlayerDto player) + { + return PlayerManager.removePlayer(player); + } + + public Task removePlayer(int id) + { + return PlayerManager.removePlayer(id); + } + + public Task<(int nbPages, IEnumerable? players)> getPlayers(int nb, int count, PlayerOrderCriteria orderCriteria = PlayerOrderCriteria.ById) + { + return PlayerManager.getPlayers(nb, count, orderCriteria); + } + + public Task getPlayer(int id) + { + return PlayerManager.getPlayer(id); + } + + public Task getPlayer(string nickname) + { + return PlayerManager.getPlayer(nickname); + } + + public Task?> getPlayersInALobby(int idLobby) + { + return PlayerManager.getPlayersInALobby(idLobby); + } + + public Task getMaxScorePlayer(int id, int idChapter) + { + return PlayerManager.getMaxScorePlayer(id, idChapter); + } + + public Task getMaxScorePlayer(int id) + { + return PlayerManager.getMaxScorePlayer(id); + } + + public int getNbQuestions() + { + return QuestionManager.getNbQuestions(); + } + + public Task addQuestion(QuestionDto question) + { + return QuestionManager.addQuestion(question); + } + + public Task removeQuestion(QuestionDto question) + { + return QuestionManager.removeQuestion(question); + } + + public Task removeQuestion(int id) + { + return QuestionManager.removeQuestion(id); + } + + public Task<(int nbPages, IEnumerable? questions)> getQuestions(int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById) + { + return QuestionManager.getQuestions(nb, count, orderCriteria); + } + + public Task getQuestion(int id) + { + return QuestionManager.getQuestion(id); + } + + public Task updateQuestion(int id, QuestionDto question) + { + return QuestionManager.updateQuestion(id, question); + } + + public Task updateQuestionNbFalls(int id) + { + return QuestionManager.updateQuestionNbFalls(id); + } + + public Task> addQuestions(IEnumerable questions) + { + return QuestionManager.addQuestions(questions); + } + + public Task<(int nbPages, IEnumerable? questions)?> getQuestionsByChapterAndDifficulty(int idChapter, int difficulty, int nb, int count, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById) + { + return QuestionManager.getQuestionsByChapterAndDifficulty(idChapter, difficulty, nb, count, orderCriteria); + } + } +}