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 CreateGame(GameDto game) { try { var result = await httpClientService.PostAsync(Endpoints.Game.Create, game); return result ?? throw new InvalidOperationException(ResourcesKey.ErrorCreateGame); } catch (Exception) { throw new GameCreationException(ResourcesKey.ErrorCreateGame); } } public async Task FetchCategories() { try { var result = await httpClientService.FetchDataAsync(Endpoints.Category.AllCategories); return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchCategories); } catch (Exception) { throw new CategoryNotFoundException(ResourcesKey.ErrorFetchCategories); } } }