feature/apply-filter (#18)
Co-authored-by: Maxime Adler <madler@sqli.com> Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.WebAPI.Services.Interfaces;
|
||||
using GameIdeas.WebAPI.Services.Games;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GameIdeas.WebAPI.Controllers;
|
||||
@@ -7,16 +7,19 @@ namespace GameIdeas.WebAPI.Controllers;
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
|
||||
public class GameController(IGameService gameService, ILoggerFactory loggerFactory) : Controller
|
||||
public class GameController(
|
||||
IGameReadService gameReadService,
|
||||
IGameWriteService gameWriteService,
|
||||
ILoggerFactory loggerFactory) : Controller
|
||||
{
|
||||
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<GameDto>>> GetGames([FromQuery] PaggingDto pagging)
|
||||
public async Task<ActionResult<IEnumerable<GameDto>>> SearchGames([FromQuery] GameFilterDto filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await gameService.GetGames(pagging));
|
||||
return Ok(await gameReadService.GetGames(filter));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -26,11 +29,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<ActionResult<GameDto>> GetGameById(int id)
|
||||
public async Task<ActionResult<GameDetailDto>> GetGameById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await gameService.GetGameById(id));
|
||||
return Ok(await gameReadService.GetGameById(id));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -40,11 +43,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
}
|
||||
|
||||
[HttpPost("Create")]
|
||||
public async Task<ActionResult<int>> CreateGame([FromBody] GameDto game)
|
||||
public async Task<ActionResult<int>> CreateGame([FromBody] GameDetailDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gameResult = await gameService.CreateGame(game);
|
||||
var gameResult = await gameWriteService.CreateGame(game);
|
||||
return Created("/Create", gameResult.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -55,11 +58,11 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
}
|
||||
|
||||
[HttpPut("Update")]
|
||||
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDto game)
|
||||
public async Task<ActionResult<int>> UpdateGame([FromBody] GameDetailDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gameResult = await gameService.UpdateGame(game);
|
||||
var gameResult = await gameWriteService.UpdateGame(game);
|
||||
return Created($"/Update", gameResult.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -74,7 +77,7 @@ public class GameController(IGameService gameService, ILoggerFactory loggerFacto
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await gameService.DeleteGame(id));
|
||||
return Ok(await gameWriteService.DeleteGame(id));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user