feature/apply-filter #18

Merged
Egamorf merged 11 commits from feature/apply-filter into main 2025-04-20 15:43:24 +02:00
2 changed files with 31 additions and 17 deletions
Showing only changes of commit 5889216dfa - Show all commits

View File

@@ -18,11 +18,11 @@ public partial class Game
private IEnumerable<GameDto> GamesDto = [];
private int CurrentPage;
protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnInitializedAsync()
{
CurrentPage = 1;
await HandleFetchDatas(firstRender);
await base.OnAfterRenderAsync(firstRender);
await HandleFetchDatas(true);
await base.OnInitializedAsync();
}
private void HandleAddClicked(AddType addType)

View File

@@ -13,9 +13,19 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
{
public async Task<IEnumerable<GameDto>> GetGames(GameFilterDto filter)
{
var games = await SelectGames()
.OrderBy(g => g.Title)
.Skip((filter.CurrentPage - 1) * GlobalConstants.NUMBER_PER_PAGE)
var query = context.Games
.Include(g => g.GamePlatforms).ThenInclude(gp => gp.Platform)
.Include(g => g.GameProperties)
.Include(g => g.GameTags).ThenInclude(gt => gt.Tag)
.Include(g => g.GamePublishers)
.Include(g => g.GameDevelopers)
.AsQueryable();
ApplyFilter(ref query, filter);
ApplyOrder(ref query, filter);
var games = await query.Skip((filter.CurrentPage - 1) * GlobalConstants.NUMBER_PER_PAGE)
.Take(GlobalConstants.NUMBER_PER_PAGE)
.ToListAsync();
@@ -24,7 +34,14 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
public async Task<GameDetailDto> GetGameById(int gameId)
{
var game = await SelectGames()
var game = await context.Games
.Include(g => g.CreationUser)
.Include(g => g.ModificationUser)
.Include(g => g.GamePlatforms).ThenInclude(p => p.Platform)
.Include(g => g.GameProperties).ThenInclude(p => p.Property)
.Include(g => g.GameTags).ThenInclude(p => p.Tag)
.Include(g => g.GamePublishers).ThenInclude(p => p.Publisher)
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
.FirstOrDefaultAsync(g => g.Id == gameId);
return game == null
@@ -81,17 +98,14 @@ public class GameService(GameIdeasContext context, IMapper mapper) : IGameServic
return await context.SaveChangesAsync() != 0;
}
private IQueryable<Game> SelectGames()
private void ApplyOrder(ref IQueryable<Game> query, GameFilterDto filter)
{
return context.Games
.Include(g => g.CreationUser)
.Include(g => g.ModificationUser)
.Include(g => g.GamePlatforms).ThenInclude(p => p.Platform)
.Include(g => g.GameProperties).ThenInclude(p => p.Property)
.Include(g => g.GameTags).ThenInclude(p => p.Tag)
.Include(g => g.GamePublishers).ThenInclude(p => p.Publisher)
.Include(g => g.GameDevelopers).ThenInclude(p => p.Developer)
.AsQueryable();
}
private void ApplyFilter(ref IQueryable<Game> query, GameFilterDto filter)
{
}
private async Task HandlePlatformsCreation(IEnumerable<PlatformDto>? categoriesToCreate, int gameId)