Add user service and controller
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 50s

This commit is contained in:
2025-04-27 17:09:15 +02:00
parent 9f0b43d10c
commit 63622bd299
12 changed files with 208 additions and 10 deletions

View File

@@ -9,6 +9,32 @@ namespace GameIdeas.BlazorApp.Pages.Users.Gateways;
public class UserGateway(IHttpClientService httpClient) : IUserGateway
{
public async Task<string> CreateUser(UserDto user)
{
try
{
return await httpClient.PostAsync<string>(Endpoints.User.Create, user)
?? throw new InvalidOperationException(ResourcesKey.ErrorCreateUser);
}
catch (Exception)
{
throw new UserCreationException(ResourcesKey.ErrorCreateUser);
}
}
public async Task<string> DeleteUser(string userId)
{
try
{
return await httpClient.DeleteAsync<string>(Endpoints.User.Delete(userId))
?? throw new InvalidOperationException(ResourcesKey.ErrorDeleteUser);
}
catch (Exception)
{
throw new UserCreationException(ResourcesKey.ErrorDeleteUser);
}
}
public async Task<IEnumerable<RoleDto>> GetRoles()
{
try
@@ -42,4 +68,17 @@ public class UserGateway(IHttpClientService httpClient) : IUserGateway
throw new UserNotFoundException(ResourcesKey.ErrorFetchUsers);
}
}
public async Task<string> UpdateUser(UserDto user)
{
try
{
return await httpClient.PutAsync<string>(Endpoints.User.Update(user.Id ?? string.Empty), user)
?? throw new InvalidOperationException(ResourcesKey.ErrorUpdateUser);
}
catch (Exception)
{
throw new UserCreationException(ResourcesKey.ErrorUpdateUser);
}
}
}