Add 'backend/' from commit '040cfd7a75423d4e6136e58a67b40579af4ee966'
git-subtree-dir: backend git-subtree-mainline:ab911955edgit-subtree-split:040cfd7a75
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class GetCreatorByAliasRequest
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public record struct GetCreatorByAliasResponse(
|
||||
Guid Id,
|
||||
Guid CreatedBy,
|
||||
DateTimeOffset CreatedAt,
|
||||
bool Verified,
|
||||
bool AcceptDonation,
|
||||
string Name,
|
||||
string? Title,
|
||||
Socials Socials,
|
||||
Colors Colors,
|
||||
PresentationInfos PresentationInfos,
|
||||
Images Images);
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class GetCreatorByAliasRequestValidator
|
||||
: Validator<GetCreatorByAliasRequest>
|
||||
{
|
||||
public GetCreatorByAliasRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.Name)
|
||||
.NotNull().WithMessage("You should specify the Name")
|
||||
.NotEmpty().WithMessage("You should specify a valid/not empty Name");
|
||||
}
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public class GetCreatorByAliasHandler(
|
||||
ContentDbContext context)
|
||||
: Endpoint<GetCreatorByAliasRequest, GetCreatorByAliasResponse>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/creators/@{Name}");
|
||||
Options((o => o.WithTags("Creators")));
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
GetCreatorByAliasRequest req,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var creatorName = req.Name.ToLower();
|
||||
|
||||
var creator = await context
|
||||
.Creators
|
||||
.Where(c => EF.Functions.ILike(c.Name, creatorName))
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (creator is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
var model = new GetCreatorByAliasResponse(
|
||||
creator.Id,
|
||||
creator.CreatedBy,
|
||||
creator.CreatedAt,
|
||||
creator.Verified,
|
||||
creator.AcceptDonation,
|
||||
creator.Name,
|
||||
creator.Title,
|
||||
creator.Socials,
|
||||
creator.Colors,
|
||||
creator.PresentationInfos,
|
||||
creator.Images);
|
||||
|
||||
await SendAsync(model, cancellation: ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user