@ -2,15 +2,22 @@
using DbConnectionLibrairie ;
using DTOs ;
using EntityManagers ;
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
{
[ApiVersion("1.0")]
[Route("api/v{version:apiversion}")]
public class FrontController
{
[Inject]
public MyDbContext dbContext { get ; set ; }
// all secondary controllers
private AdministratorController administratorController ;
private ChapterController chapterController ;
@ -19,7 +26,6 @@ namespace WebApi.Controllers
private QuestionController questionController ;
public FrontController (
MyDbContext dbContext ,
Logger < AdministratorController > logAdmin ,
Logger < ChapterController > logChapter ,
Logger < LobbyController > logLobby ,
@ -34,12 +40,12 @@ namespace WebApi.Controllers
new LobbyServiceManager ( new LobbyDataManager ( new LobbyEntityManager ( dbContext ) ) ) ,
new PlayerServiceManager ( new PlayerDataManager ( new PlayerEntityManager ( dbContext ) ) ) ,
new QuestionServiceManager ( new QuestionDataManager ( new QuestionEntityManager ( 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) ;
playerController = new PlayerController ( unity , logPlayer ) ;
questionController = new QuestionController ( unity , logQuestion ) ;
}
/// <summary>
@ -357,5 +363,234 @@ namespace WebApi.Controllers
public async Task < IActionResult > GetLobby ( int id )
= > await lobbyController . GetLobby ( id ) ;
/// <summary>
/// add a player
/// </summary>
/// <param name="player">the player to add</param>
/// <returns>
/// 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
/// </returns>
[HttpPost("add/player")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(StatusCodes.Status208AlreadyReported)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task < IActionResult > PostPlayer ( [ FromBody ] PlayerDto player )
= > await playerController . PostPlayer ( player ) ;
/// <summary>
/// get a part of all players
/// </summary>
/// <param name="page">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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
/// </returns>
[HttpGet("all/players")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task < IActionResult > GetSomePlayers ( [ FromQuery ] int page , int count = 10 , PlayerOrderCriteria orderCriteria = PlayerOrderCriteria . ById )
= > await playerController . GetSomePlayers ( page , count , orderCriteria ) ;
/// <summary>
/// delete a player
/// </summary>
/// <param name="id">the id of the player to delete</param>
/// <returns>
/// <returns>
/// 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
/// </returns>
[HttpDelete("delete/player")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task < IActionResult > DeletePlayer ( int id )
= > await playerController . DeletePlayer ( id ) ;
/// <summary>
/// get a player
/// </summary>
/// <param name="id">the id of the player</param>
/// <returns>
/// 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
/// </returns>
[HttpGet("player")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task < IActionResult > GetPlayer ( int id )
= > await playerController . GetPlayer ( id ) ;
/// <summary>
/// update a player
/// </summary>
/// <param name="id">the id of the player</param>
/// <returns>
/// 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
/// </returns>
[HttpPut("update/player")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status208AlreadyReported)]
public async Task < IActionResult > PutPlayer ( [ FromQuery ] int id , [ FromBody ] PlayerDto player )
= > await playerController . PutPlayer ( id , player ) ;
/// <summary>
/// add a question
/// </summary>
/// <param name="question">the question to add</param>
/// <returns>
/// 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
/// </returns>
[HttpPost("add/question")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(StatusCodes.Status208AlreadyReported)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task < IActionResult > PostQuestion ( [ FromBody ] QuestionDto question )
= > await questionController . PostQuestion ( question ) ;
/// <summary>
/// get a part of all questions
/// </summary>
/// <param name="page">the actual page</param>
/// <param name="count">number of T element in a page</param>
/// <param name="orderCriteria">the order criteria</param>
/// <returns>
/// 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
/// </returns>
[HttpGet("questions/all")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task < IActionResult > GetSomeQuestions ( [ FromQuery ] int page , int count = 10 , QuestionOrderCriteria orderCriteria = QuestionOrderCriteria . ById )
= > await questionController . GetSomeQuestions ( page , count , orderCriteria ) ;
/// <summary>
/// delete a question
/// </summary>
/// <param name="id">the id of the question to delete</param>
/// <returns>
/// 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
/// </returns>
[HttpDelete("delete/question")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task < IActionResult > DeleteQuestion ( [ FromQuery ] int id )
= > await questionController . DeleteQuestion ( id ) ;
/// <summary>
/// get a question
/// </summary>
/// <param name="id">the id of the question</param>
/// <returns>
/// 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
/// </returns>
[HttpGet("question")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task < IActionResult > GetQuestion ( [ FromQuery ] int id )
= > await questionController . GetQuestion ( id ) ;
/// <summary>
/// update a question
/// </summary>
/// <param name="id">the id of the question</param>
/// <returns>
/// 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
/// </returns>
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status208AlreadyReported)]
public async Task < IActionResult > PutQuestion ( int id , QuestionDto question )
= > await questionController . PutQuestion ( id , question ) ;
}
}