* Managed API to handle User maintenance
* Managed Users view in application
This commit is contained in:
36
OrdersManagement/Services/UserService.cs
Normal file
36
OrdersManagement/Services/UserService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using OrdersManagementDataModel.Dtos;
|
||||
|
||||
namespace OrdersManagement.Services;
|
||||
|
||||
public class UserService(HttpClient httpClient)
|
||||
{
|
||||
public async Task<IEnumerable<UserDto>?> GetUsersAsync()
|
||||
{
|
||||
return await httpClient.GetFromJsonAsync<IEnumerable<UserDto>>("api/Users");
|
||||
}
|
||||
|
||||
public async Task<UserDto?> GetUserAsync(Guid userId)
|
||||
{
|
||||
return await httpClient.GetFromJsonAsync<UserDto>($"api/Users/by-id/?id={userId}");
|
||||
}
|
||||
|
||||
public async Task<UserDto?> GetUserByUsernameAsync(string username)
|
||||
{
|
||||
return await httpClient.GetFromJsonAsync<UserDto>($"api/Users/by-username/?username={username}");
|
||||
}
|
||||
|
||||
public async Task AddUserAsync(UserDto user)
|
||||
{
|
||||
await httpClient.PostAsJsonAsync("api/Users", user);
|
||||
}
|
||||
|
||||
public async Task UpdateUserAsync(UserDto user)
|
||||
{
|
||||
await httpClient.PutAsJsonAsync("api/Users", user);
|
||||
}
|
||||
|
||||
public async Task DeleteUserAsync(Guid userId)
|
||||
{
|
||||
await httpClient.DeleteAsync($"api/Users/?id={userId}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user