Add services and controllers for games #12
@@ -1,7 +1,3 @@
|
|||||||
namespace GameIdeas.Shared.Exceptions;
|
namespace GameIdeas.Shared.Exceptions;
|
||||||
|
|
||||||
public class NotFoundException : Exception
|
public class NotFoundException(string msg, Exception? innerException = null) : Exception(msg, innerException);
|
||||||
{
|
|
||||||
public NotFoundException(string msg, Exception? innerException = null) : base(msg, innerException)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace GameIdeas.WebAPI.Controllers;
|
|||||||
public class GameController(GameService gameService) : Controller
|
public class GameController(GameService gameService) : Controller
|
||||||
{
|
{
|
||||||
[HttpGet("Search")]
|
[HttpGet("Search")]
|
||||||
public async Task<IEnumerable<GameDto>> FetchGames([FromQuery] GameFilterDto filter)
|
public async Task<IEnumerable<GameDto>> FetchGames([FromQuery] PaggingDto pagging)
|
||||||
{
|
{
|
||||||
return await gameService.GetGames(filter);
|
return await gameService.GetGames(pagging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,9 @@ public class GameService(GameIdeasContext context, IMapper mapper)
|
|||||||
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
|
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
|
||||||
.FirstOrDefaultAsync(g => g.Id == gameId);
|
.FirstOrDefaultAsync(g => g.Id == gameId);
|
||||||
|
|
||||||
if (game == null)
|
return game == null
|
||||||
{
|
? throw new NotFoundException($"[{typeof(Game).Name}] with ID {gameId} has not been found in context")
|
||||||
throw new NotFoundException($"[{typeof(Game).Name}] with ID {gameId} has not been found in context");
|
: mapper.Map<GameDto>(game);
|
||||||
}
|
|
||||||
|
|
||||||
return mapper.Map<GameDto>(game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GameDto> CreateGame(GameDto gameDto)
|
public async Task<GameDto> CreateGame(GameDto gameDto)
|
||||||
|
|||||||
Reference in New Issue
Block a user