Závady nahlášené přihlášeným uživatelem od nejnovějších: filtr podle stavu, stránkování, štítky stavů, kategorie a místo z číselníků a čas v českém pásmu. Položka v menu a site.js pro automatické odeslání filtru (bez inline skriptů kvůli CSP). Refs #22
62 lines
2.7 KiB
C#
62 lines
2.7 KiB
C#
using System.Globalization;
|
||
using System.Net.Http.Json;
|
||
using Microsoft.AspNetCore.WebUtilities;
|
||
|
||
namespace Helpdesk.Web.Api;
|
||
|
||
/// <summary>Endpointy API pro přihlášeného uživatele; access token přidává <see cref="BearerTokenHandler"/>.</summary>
|
||
public sealed class HelpdeskApiClient(HttpClient http)
|
||
{
|
||
public async Task<UserDto> GetMeAsync(CancellationToken ct)
|
||
{
|
||
using var response = await http.GetAsync("api/v1/users/me", ct);
|
||
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||
}
|
||
|
||
public async Task<UserDto> UpdateMeAsync(UpdateProfileRequest request, CancellationToken ct)
|
||
{
|
||
using var response = await http.PutAsJsonAsync("api/v1/users/me", request, ct);
|
||
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||
}
|
||
|
||
public async Task<PagedResult<IssueSummary>> GetIssuesAsync(IssueListQuery query, CancellationToken ct)
|
||
{
|
||
var parameters = new Dictionary<string, string?>
|
||
{
|
||
["status"] = query.Status,
|
||
["mine"] = query.Mine ? "true" : null,
|
||
["sort"] = query.Sort,
|
||
["page"] = query.Page.ToString(CultureInfo.InvariantCulture),
|
||
["pageSize"] = query.PageSize.ToString(CultureInfo.InvariantCulture),
|
||
};
|
||
using var response = await http.GetAsync(QueryHelpers.AddQueryString("api/v1/issues", parameters.Where(p => !string.IsNullOrEmpty(p.Value))), ct);
|
||
return await ApiResponse.ReadAsync<PagedResult<IssueSummary>>(response, ct);
|
||
}
|
||
|
||
public async Task<IReadOnlyList<CategoryDto>> GetIssueCategoriesAsync(CancellationToken ct)
|
||
{
|
||
using var response = await http.GetAsync("api/v1/issue-categories", ct);
|
||
return await ApiResponse.ReadAsync<List<CategoryDto>>(response, ct);
|
||
}
|
||
|
||
public async Task<IReadOnlyList<BuildingDto>> GetBuildingsAsync(CancellationToken ct)
|
||
{
|
||
using var response = await http.GetAsync("api/v1/buildings", ct);
|
||
return await ApiResponse.ReadAsync<List<BuildingDto>>(response, ct);
|
||
}
|
||
|
||
/// <summary>Odhlásí ze všech zařízení – API zneplatní všechny tokeny uživatele.</summary>
|
||
public async Task LogoutAllAsync(CancellationToken ct)
|
||
{
|
||
using var response = await http.PostAsync("api/v1/auth/logout-all", content: null, ct);
|
||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||
}
|
||
|
||
/// <summary>Odhlásí toto zařízení – API zneplatní aktuální access token i předaný refresh token.</summary>
|
||
public async Task LogoutAsync(string refreshToken, CancellationToken ct)
|
||
{
|
||
using var response = await http.PostAsJsonAsync("api/v1/auth/logout", new RefreshTokenRequest(refreshToken), ct);
|
||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||
}
|
||
}
|