using DataManagers; using DbConnectionLibrairie; using DTOs; using EntityManagers; using ManagerInterfaces; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using OrderCriterias; using ServiceManagers; using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute; namespace WebApi.Controllers { /// /// a controller just to separate route definition with route "documentation" /// [ApiVersion("1.0")] [Route("api/v{version:apiversion}")] [ApiController] public class FrontController { private Unit unity; // all secondary controllers private AdministratorController administratorController; private ChapterController chapterController; private LobbyController lobbyController; private PlayerController playerController; private QuestionController questionController; public FrontController( AdministratorServiceManager administratorServiceManager, AnswerServiceManager answerServiceManager, ChapterServiceManager chapterServiceManager, LobbyServiceManager lobbyServiceManager, PlayerServiceManager playerServiceManager, QuestionServiceManager questionServiceManager ){ this.unity = new Unit( administratorServiceManager, answerServiceManager, chapterServiceManager, lobbyServiceManager, playerServiceManager, questionServiceManager ); administratorController = new AdministratorController(unity); chapterController = new ChapterController(unity); lobbyController = new LobbyController(unity); playerController = new PlayerController(unity); questionController = new QuestionController(unity); } /// /// add an administrator /// /// the administrator to add /// /// status code : /// 200 if the administrator is added /// 202 if the administrator is added /// 208 if the administrator 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 /// administrator added when status code = 202 /// administrator already in the database that equals the one we wanted to add when status code = 208 /// no content when status code = 500 /// [HttpPost("add/administrator/")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task PostAdministrator([FromBody] AdministratorDto administrator) { var tmp = await administratorController.PostAdministrator(administrator); return tmp; } /// /// get a part of all administrators /// /// 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 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 /// [HttpGet("administrators")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task GetSomeAdministrators([FromQuery] int page, int count = 10, AdministratorOrderCriteria orderCriteria = AdministratorOrderCriteria.ById) => await administratorController.GetSomeAdministrators(page, count, orderCriteria); /// /// delete an administrator /// /// the id of the administrator to delete /// /// /// status code : /// 200 if the administrator is removed /// 204 if the administrator 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/administrator")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeleteAdministrator([FromQuery] int id) => await administratorController.DeleteAdministrator(id); /// /// update an administrator /// /// id of the administrator to update /// an administrator who contains all properties to change /// /// status code : /// 200 if the administrator is modified /// 204 if we wanted to modify an administrator who don't exist /// 208 if the new username of the administrator is already used /// 500 if there was an internal error that doesn't allow to continue /// /// return content : /// the administrator modified when status code = 200 /// nothing when status code = 204 /// the administrator that already have the username when status code = 208 /// nothing when status code = 500 /// [HttpPut("update/administrator")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task PutAdministrator([FromQuery] int id, [FromBody] AdministratorDto administrator) => 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([FromQuery] string name) => await chapterController.GetChapter(name); /// /// add a lobby /// /// the lobby to add /// /// status code : /// 200 if the lobby is added /// 202 if the lobby is added /// 208 if the lobby 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 /// lobby added when status code = 202 /// lobby already in the database that equals the one we wanted to add when status code = 208 /// no content when status code = 500 /// [HttpPost("add/lobby")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task PostLobby([FromBody] LobbyDto lobby) => await lobbyController.PostLobby(lobby); /// /// get a part of all lobbies /// /// 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 lobbies 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("lobbies")] public async Task GetSomeLobbies([FromQuery] int page, int count = 10, LobbyOrderCriteria orderCriteria = LobbyOrderCriteria.ById) => await lobbyController.GetSomeLobbies(page, count, orderCriteria); /// /// delete a lobby /// /// the id of the lobby to delete /// /// /// status code : /// 200 if the lobby is removed /// 204 if the lobby 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/lobby")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeleteLobby([FromQuery] int id) => await lobbyController.DeleteLobby(id); /// /// get a lobby /// /// the id of the lobby /// /// status code : /// 200 when we got a lobby /// 204 when we got null /// /// return content : /// the lobby that correspond to the id when status code = 200 /// nothing when status code 204 /// [HttpGet("lobbies/name")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task GetLobby(int id) => await lobbyController.GetLobby(id); /// /// add a player /// /// the player to add /// /// status code : /// 200 if the player is added /// 202 if the player is added /// 208 if the player 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 /// player added when status code = 202 /// player already in the database that equals the one we wanted to add when status code = 208 /// no content when status code = 500 /// [HttpPost("add/player")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task PostPlayer([FromBody] PlayerDto player) => await playerController.PostPlayer(player); /// /// get a part of all players /// /// 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 players 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/players")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetSomePlayers([FromQuery] int page, int count = 10, PlayerOrderCriteria orderCriteria = PlayerOrderCriteria.ById) => await playerController.GetSomePlayers(page, count, orderCriteria); /// /// delete a player /// /// the id of the player to delete /// /// /// status code : /// 200 if the player is removed /// 204 if the player 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/player")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeletePlayer(int id) => await playerController.DeletePlayer(id); /// /// get a player /// /// the id of the player /// /// status code : /// 200 when we got a player /// 204 when we got null /// /// return content : /// the player that correspond to the id when status code = 200 /// nothing when status code = 204 /// [HttpGet("player")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task GetPlayer(int id) => await playerController.GetPlayer(id); /// /// update a player /// /// the id of the player /// /// status code : /// 200 when we got a player /// 204 when we got null /// 208 when the nickname is already used /// return content : /// the player that correspond to the id when status code = 200 /// nothing when status code = 204 /// the player which have this nickname when status code = 208 /// [HttpPut("update/player")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] public async Task PutPlayer([FromQuery] int id, [FromBody] PlayerDto player) => await playerController.PutPlayer(id, player); /// /// add a question /// /// the question to add /// /// status code : /// 200 if the question is added /// 202 if the question is added /// 208 if the question 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 /// question added when status code = 202 /// question already in the database that equals the one we wanted to add when status code = 208 /// no content when status code = 500 /// [HttpPost("add/question")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task PostQuestion([FromBody] QuestionDto question) => await questionController.PostQuestion(question); /// /// get a part of all questions /// /// 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 questions 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("questions/all")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task GetSomeQuestions([FromQuery] int page, int count = 10, QuestionOrderCriteria orderCriteria = QuestionOrderCriteria.ById) => await questionController.GetSomeQuestions(page, count, orderCriteria); /// /// delete a question /// /// the id of the question to delete /// /// status code : /// 200 if the question is removed /// 204 if the question 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/question")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeleteQuestion([FromQuery] int id) => await questionController.DeleteQuestion(id); /// /// get a question /// /// the id of the question /// /// status code : /// 200 when we got a question /// 204 when we got null /// /// return content : /// the question that correspond to the id when status code = 200 /// nothing when status code = 204 /// [HttpGet("question")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task GetQuestion([FromQuery] int id) => await questionController.GetQuestion(id); /// /// update a question /// /// the id of the question /// /// status code : /// 200 when we got a question /// 204 when we got null /// 208 when the nickname is already used /// return content : /// the question that correspond to the id when status code = 200 /// nothing when status code = 204 /// the question which have this nickname when status code = 208 /// [HttpPut] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status208AlreadyReported)] public async Task PutQuestion(int id, QuestionDto question) => await questionController.PutQuestion(id, question); } }