Add gateway and filter
Some checks failed
Game Ideas build for PR / build_blazor_app (pull_request) Failing after 29s

This commit is contained in:
2025-04-22 21:29:50 +02:00
parent ea9fc001f3
commit 6d109d00e6
7 changed files with 64 additions and 4 deletions

View File

@@ -59,7 +59,7 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
} }
catch (Exception) catch (Exception)
{ {
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames); throw new GameNotFoundException(ResourcesKey.ErrorFetchGames);
} }
} }
} }

View File

@@ -0,0 +1,8 @@
using GameIdeas.Shared.Dto;
namespace GameIdeas.BlazorApp.Pages.Users.Gateways;
public interface IUserGateway
{
Task<UserListDto> GetUsers(UserFilterParams filterParams);
}

View File

@@ -0,0 +1,29 @@
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.Users.Gateways;
public class UserGateway(IHttpClientService httpClient) : IUserGateway
{
public async Task<UserListDto> GetUsers(UserFilterParams filterParams)
{
try
{
UserFilterDto filter = new()
{
};
var url = Endpoints.User.Fetch(filter);
return await httpClient.FetchDataAsync<UserListDto>(url)
?? throw new InvalidOperationException(ResourcesKey.ErrorFetchUsers);
}
catch (Exception)
{
throw new UserNotFoundException(ResourcesKey.ErrorFetchUsers);
}
}
}

View File

@@ -7,17 +7,22 @@ public static class Endpoints
{ {
public static class Game public static class Game
{ {
public static readonly string Create = "api/Game/Create"; public const string Create = "api/Game/Create";
public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}"; public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}";
} }
public static class Category public static class Category
{ {
public static readonly string AllCategories = "api/Category/All"; public const string AllCategories = "api/Category/All";
} }
public static class Auth public static class Auth
{ {
public static readonly string Login = "api/User/Login"; public const string Login = "api/User/Login";
}
public static class User
{
public static string Fetch(UserFilterDto filter) => $"api/User?{UrlHelper.BuildUrlParams(filter)}";
} }
} }

View File

@@ -0,0 +1,3 @@
namespace GameIdeas.BlazorApp.Shared.Exceptions;
public class UserNotFoundException(string message) : Exception(message);

View File

@@ -0,0 +1,8 @@
namespace GameIdeas.Shared.Dto;
public class UserFilterDto
{
public int CurrentPage { get; set; }
public string? Name { get; set; }
public IEnumerable<string>? RoleIds { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace GameIdeas.Shared.Dto;
public class UserListDto
{
public IEnumerable<UserDto>? Users { get; set; }
public int UsersCount { get; set; }
}