Add gateway and filter
Some checks failed
Game Ideas build for PR / build_blazor_app (pull_request) Failing after 29s
Some checks failed
Game Ideas build for PR / build_blazor_app (pull_request) Failing after 29s
This commit is contained in:
@@ -59,7 +59,7 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
|
throw new GameNotFoundException(ResourcesKey.ErrorFetchGames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Pages.Users.Gateways;
|
||||||
|
|
||||||
|
public interface IUserGateway
|
||||||
|
{
|
||||||
|
Task<UserListDto> GetUsers(UserFilterParams filterParams);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class UserNotFoundException(string message) : Exception(message);
|
||||||
8
src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs
Normal file
8
src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs
Normal 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; }
|
||||||
|
}
|
||||||
7
src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs
Normal file
7
src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace GameIdeas.Shared.Dto;
|
||||||
|
|
||||||
|
public class UserListDto
|
||||||
|
{
|
||||||
|
public IEnumerable<UserDto>? Users { get; set; }
|
||||||
|
public int UsersCount { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user