chore: import Musify.WebApi into monorepo (preserving history)

git-subtree-dir: Musify.WebApi
git-subtree-mainline: 9d433868cc
git-subtree-split: ca8750c3b4
This commit is contained in:
2026-07-05 03:20:47 +02:00
36 changed files with 1698 additions and 0 deletions
@@ -0,0 +1,20 @@
using FluentValidation;
namespace WebApi.Filters;
public sealed class ValidationFilter<T>(IValidator<T> validator) : IEndpointFilter where T : class
{
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
var argument = context.Arguments.OfType<T>().FirstOrDefault();
if (argument is null)
return await next(context);
var result = await validator.ValidateAsync(argument, context.HttpContext.RequestAborted);
return result.IsValid
? await next(context)
: Results.ValidationProblem(result.ToDictionary());
}
}