Základní backend: migrace, autentizace JWT, role, Swagger

- Helpdesk.Migrator (DbUp) aplikuje db/migrations, evidence v schema_version
- Domain/Application/Infrastructure/Api podle Clean Architecture
- registrace, ověření e-mailu, login, refresh s rotací, logout, reset hesla
- JWT podle RFC 7519 evidované jen podle jti v auth_token
- správa uživatelů a rolí, číselníky, ProblemDetails, Swagger UI
- Docker Compose (db, migrator, api), oddělené DB účty
- notifikace mají cizí klíče na issue a proposal
- unit testy domény a zabezpečení

Closes #1, closes #2, closes #3, closes #4, closes #5, closes #9
This commit is contained in:
PatTheEvil committed 2026-10-28 21:43:17 +01:00
1 parent fc76be7d69
commit a51d386278
64 files changed
+4394 -1

No files matched your search

@@ -0,0 +1,41 @@
using FluentValidation;
using Helpdesk.Application.Common;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace Helpdesk.Api.Infrastructure;
/// <summary>Převod výjimek na ProblemDetails (RFC 9457): aplikační chyby → 4xx, validace → 400 se seznamem chyb.</summary>
internal sealed class AppExceptionHandler(IProblemDetailsService problemDetails) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
ProblemDetails? problem = exception switch
{
ValidationException validation => new ValidationProblemDetails(
validation.Errors
.GroupBy(e => JsonName(e.PropertyName))
.ToDictionary(g => g.Key, g => g.Select(e => e.ErrorMessage).ToArray()))
{
Status = StatusCodes.Status400BadRequest,
Title = "Neplatná vstupní data.",
},
AppException app => new ProblemDetails { Status = app.StatusCode, Title = app.Message },
_ => null,
};
if (problem is null)
return false; // neočekávaná chyba → výchozí 500 bez detailů
httpContext.Response.StatusCode = problem.Status!.Value;
return await problemDetails.TryWriteAsync(new ProblemDetailsContext
{
HttpContext = httpContext,
ProblemDetails = problem,
Exception = exception,
});
}
private static string JsonName(string propertyName) =>
string.IsNullOrEmpty(propertyName) ? propertyName : char.ToLowerInvariant(propertyName[0]) + propertyName[1..];
}