backend: Add concurrency checks to admin user edits
This commit is contained in:
1 parent
91d0c06c83
commit
bd8eb65e56
18 files changed
+216
-23
No files matched your search
@@ -8,11 +8,12 @@ namespace Helpdesk.Web.Api;
|
||||
/// Neúspěšná odpověď API ve formátu ProblemDetails (RFC 9457). Nese stav, titulek
|
||||
/// a u validačních chyb seznam chyb podle polí (klíče jsou názvy vlastností v camelCase).
|
||||
/// </summary>
|
||||
public sealed class ApiException(HttpStatusCode statusCode, string? title, IReadOnlyDictionary<string, string[]> errors)
|
||||
public sealed class ApiException(HttpStatusCode statusCode, string? title, IReadOnlyDictionary<string, string[]> errors, string? problemType = null)
|
||||
: Exception(title ?? $"API vrátilo stav {(int)statusCode}.")
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; } = statusCode;
|
||||
public string? Title { get; } = title;
|
||||
public string? ProblemType { get; } = problemType;
|
||||
public IReadOnlyDictionary<string, string[]> Errors { get; } = errors;
|
||||
|
||||
/// <summary>Text pro uživatele. API píše titulky chyb česky, kromě odpovědí bez těla (např. 429).</summary>
|
||||
@@ -33,6 +34,7 @@ public sealed class ApiException(HttpStatusCode statusCode, string? title, IRead
|
||||
public static async Task<ApiException> FromResponseAsync(HttpResponseMessage response, CancellationToken ct)
|
||||
{
|
||||
string? title = null;
|
||||
string? type = null;
|
||||
Dictionary<string, string[]> errors = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (response.Content.Headers.ContentType?.MediaType is { } mediaType && mediaType.Contains("json", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -41,6 +43,7 @@ public sealed class ApiException(HttpStatusCode statusCode, string? title, IRead
|
||||
{
|
||||
var problem = await response.Content.ReadFromJsonAsync<ProblemBody>(ct);
|
||||
title = problem?.Title;
|
||||
type = problem?.Type;
|
||||
if (problem?.Errors is { } fieldErrors)
|
||||
{
|
||||
foreach (var (field, messages) in fieldErrors)
|
||||
@@ -53,10 +56,10 @@ public sealed class ApiException(HttpStatusCode statusCode, string? title, IRead
|
||||
}
|
||||
}
|
||||
|
||||
return new ApiException(response.StatusCode, title, errors);
|
||||
return new ApiException(response.StatusCode, title, errors, type);
|
||||
}
|
||||
|
||||
private sealed record ProblemBody(string? Title, Dictionary<string, string[]>? Errors);
|
||||
private sealed record ProblemBody(string? Title, Dictionary<string, string[]>? Errors, string? Type);
|
||||
}
|
||||
|
||||
internal static class ApiResponse
|
||||
|
||||
@@ -53,10 +53,11 @@ public sealed record AdminUserDto(
|
||||
}
|
||||
|
||||
public sealed record AdminUserDetailsDto(int Id, string Email, string FirstName, string LastName, string? Phone,
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, bool? VerificationEmailSent = null);
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, int RowVersion,
|
||||
bool? VerificationEmailSent = null);
|
||||
|
||||
public sealed record SaveAdminUserRequest(string Email, string FirstName, string LastName, string? Phone,
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, string? Password);
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, string? Password, int? RowVersion);
|
||||
|
||||
/// <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)
|
||||
|
||||
Reference in new issue
Block a user