From 6d109d00e609c3af755d86b613127fb2c1c047c1 Mon Sep 17 00:00:00 2001 From: Egamorf Date: Tue, 22 Apr 2025 21:29:50 +0200 Subject: [PATCH] Add gateway and filter --- .../Pages/Games/Gateways/GameGateway.cs | 2 +- .../Pages/Users/Gateways/IUserGateway.cs | 8 +++++ .../Pages/Users/Gateways/UserGateway.cs | 29 +++++++++++++++++++ .../Shared/Constants/Endpoints.cs | 11 +++++-- .../Exceptions/UserNotFoundException.cs | 3 ++ .../GameIdeas.Shared/Dto/UserFilterDto.cs | 8 +++++ .../GameIdeas.Shared/Dto/UserListDto.cs | 7 +++++ 7 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/IUserGateway.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/UserGateway.cs create mode 100644 src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Exceptions/UserNotFoundException.cs create mode 100644 src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs create mode 100644 src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs index 21148a3..6494a4f 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Gateways/GameGateway.cs @@ -59,7 +59,7 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway } catch (Exception) { - throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames); + throw new GameNotFoundException(ResourcesKey.ErrorFetchGames); } } } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/IUserGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/IUserGateway.cs new file mode 100644 index 0000000..0b9be82 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/IUserGateway.cs @@ -0,0 +1,8 @@ +using GameIdeas.Shared.Dto; + +namespace GameIdeas.BlazorApp.Pages.Users.Gateways; + +public interface IUserGateway +{ + Task GetUsers(UserFilterParams filterParams); +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/UserGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/UserGateway.cs new file mode 100644 index 0000000..c9120e7 --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Users/Gateways/UserGateway.cs @@ -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 GetUsers(UserFilterParams filterParams) + { + try + { + UserFilterDto filter = new() + { + + }; + + var url = Endpoints.User.Fetch(filter); + return await httpClient.FetchDataAsync(url) + ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchUsers); + } + catch (Exception) + { + throw new UserNotFoundException(ResourcesKey.ErrorFetchUsers); + } + } +} diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Endpoints.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Endpoints.cs index 0c45383..65bc47c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Endpoints.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Constants/Endpoints.cs @@ -7,17 +7,22 @@ public static class Endpoints { 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 class Category { - public static readonly string AllCategories = "api/Category/All"; + public const string AllCategories = "api/Category/All"; } 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)}"; } } diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Exceptions/UserNotFoundException.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Exceptions/UserNotFoundException.cs new file mode 100644 index 0000000..11ef9aa --- /dev/null +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Exceptions/UserNotFoundException.cs @@ -0,0 +1,3 @@ +namespace GameIdeas.BlazorApp.Shared.Exceptions; + +public class UserNotFoundException(string message) : Exception(message); diff --git a/src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs b/src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs new file mode 100644 index 0000000..2d8eed3 --- /dev/null +++ b/src/GameIdeas/GameIdeas.Shared/Dto/UserFilterDto.cs @@ -0,0 +1,8 @@ +namespace GameIdeas.Shared.Dto; + +public class UserFilterDto +{ + public int CurrentPage { get; set; } + public string? Name { get; set; } + public IEnumerable? RoleIds { get; set; } +} diff --git a/src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs b/src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs new file mode 100644 index 0000000..40c80bc --- /dev/null +++ b/src/GameIdeas/GameIdeas.Shared/Dto/UserListDto.cs @@ -0,0 +1,7 @@ +namespace GameIdeas.Shared.Dto; + +public class UserListDto +{ + public IEnumerable? Users { get; set; } + public int UsersCount { get; set; } +}