All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 1m14s
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
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<GameDto> CreateGame(GameDto game)
|
|
{
|
|
try
|
|
{
|
|
var result = await httpClientService.PostAsync<GameDto>(Endpoints.Game.Create, game);
|
|
|
|
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame);
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|