Add services and controllers for games #12

Merged
Egamorf merged 7 commits from release/add-services-controllers into main 2025-04-12 21:34:45 +02:00
3 changed files with 6 additions and 13 deletions
Showing only changes of commit b545da19b7 - Show all commits

View File

@@ -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)
{ }
}

View File

@@ -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);
} }
} }

View File

@@ -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)