web: Add admin user management
This commit is contained in:
1 parent
232d48c7fc
commit
fcf7cd0596
11 files changed
+410
-18
No files matched your search
@@ -46,6 +46,12 @@ public sealed record ResetPasswordRequest(string Token, string NewPassword);
|
||||
|
||||
public sealed record UpdateProfileRequest(string FirstName, string LastName, string? Phone, bool EmailNotificationsEnabled);
|
||||
|
||||
public sealed record AdminUserDto(
|
||||
int Id, string Email, string FirstName, string LastName, string Role, bool IsActive, bool EmailConfirmed, DateTimeOffset CreatedAt)
|
||||
{
|
||||
public string FullName => $"{FirstName} {LastName}";
|
||||
}
|
||||
|
||||
/// <summary>Stránkovaný seznam z API: <c>{ items, totalCount, page, pageSize }</c>.</summary>
|
||||
public sealed record PagedResult<T>(IReadOnlyList<T> Items, int TotalCount, int Page, int PageSize)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,30 @@ public sealed class HelpdeskApiClient(HttpClient http)
|
||||
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<AdminUserDto>> GetAdminUsersAsync(string? q, string? role, int page, CancellationToken ct)
|
||||
{
|
||||
var parameters = new Dictionary<string, string?>
|
||||
{
|
||||
["q"] = q,
|
||||
["role"] = role,
|
||||
["page"] = page.ToString(CultureInfo.InvariantCulture),
|
||||
};
|
||||
using var response = await http.GetAsync(QueryHelpers.AddQueryString("admin/users", parameters), ct);
|
||||
return await ApiResponse.ReadAsync<PagedResult<AdminUserDto>>(response, ct);
|
||||
}
|
||||
|
||||
public async Task ChangeUserRoleAsync(int id, string role, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PutAsJsonAsync($"admin/users/{id.ToString(CultureInfo.InvariantCulture)}/role", new { role }, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task SetUserActiveAsync(int id, bool isActive, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PutAsJsonAsync($"admin/users/{id.ToString(CultureInfo.InvariantCulture)}/active", new { isActive }, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IssueSummary>> GetIssuesAsync(IssueListQuery query, CancellationToken ct)
|
||||
{
|
||||
var parameters = new Dictionary<string, string?>
|
||||
|
||||
Reference in new issue
Block a user