Some checks failed
Game Ideas build for PR / build_blazor_app (pull_request) Failing after 29s
66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
|
using GameIdeas.BlazorApp.Services;
|
|
using GameIdeas.BlazorApp.Shared.Constants;
|
|
using GameIdeas.BlazorApp.Shared.Exceptions;
|
|
using GameIdeas.Resources;
|
|
using GameIdeas.Shared.Dto;
|
|
|
|
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|
|
|
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
|
{
|
|
public async Task<int> CreateGame(GameDetailDto game)
|
|
{
|
|
try
|
|
{
|
|
return await httpClientService.PostAsync<int>(Endpoints.Game.Create, game);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new GameCreationException(ResourcesKey.ErrorCreateGame);
|
|
}
|
|
}
|
|
|
|
public async Task<CategoriesDto> FetchCategories()
|
|
{
|
|
try
|
|
{
|
|
var result = await httpClientService.FetchDataAsync<CategoriesDto>(Endpoints.Category.AllCategories);
|
|
|
|
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchCategories);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filterParams, int currentPage)
|
|
{
|
|
try
|
|
{
|
|
GameFilterDto filter = new()
|
|
{
|
|
CurrentPage = currentPage,
|
|
Title = filterParams.Title,
|
|
MaxInterest = filterParams.MaxInterest,
|
|
MinInterest = filterParams.MinInterest,
|
|
StorageSpaces = filterParams.StorageSpaceIds,
|
|
DeveloperIds = filterParams.Developers?.Select(d => d.Id ?? 0).ToList(),
|
|
PublisherIds = filterParams.Publishers?.Select(d => d.Id ?? 0).ToList(),
|
|
PlatformIds = filterParams.Platforms?.Select(d => d.Id ?? 0).ToList(),
|
|
PropertyIds = filterParams.Properties?.Select(d => d.Id ?? 0).ToList(),
|
|
ReleaseYears = filterParams.ReleaseYears,
|
|
TagIds = filterParams.Tags?.Select(d => d.Id ?? 0).ToList(),
|
|
};
|
|
|
|
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(filter));
|
|
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new GameNotFoundException(ResourcesKey.ErrorFetchGames);
|
|
}
|
|
}
|
|
}
|