many fixes and improvements - rework for modules/ and common/
feat(emailer): add Postmark and Resend providers
This commit is contained in:
63
backend/Modules/Creators/Features/RemoveCreator.cs
Normal file
63
backend/Modules/Creators/Features/RemoveCreator.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Hutopy.Infrastructure.Security;
|
||||
using Hutopy.Modules.Creators.Data;
|
||||
|
||||
namespace Hutopy.Modules.Creators.Features;
|
||||
|
||||
[PublicAPI]
|
||||
public record RemoveCreatorRequest(
|
||||
string CreatorSlug);
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class RemoveCreatorRequestValidator : Validator<RemoveCreatorRequest>
|
||||
{
|
||||
public RemoveCreatorRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.CreatorSlug)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.WithMessage("You should specify a valid CreatorSlug");
|
||||
}
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class RemoveCreatorHandler(
|
||||
CreatorsDbContext context)
|
||||
: Endpoint<RemoveCreatorRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/creators/@{CreatorSlug}");
|
||||
Options(o => o.WithTags("Creators"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
RemoveCreatorRequest req,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var creatorSlug = req.CreatorSlug.ToLower();
|
||||
|
||||
var creator = await context
|
||||
.Creators
|
||||
.Where(c => EF.Functions.ILike(c.Slug, creatorSlug))
|
||||
.SingleOrDefaultAsync(cancellationToken: ct);
|
||||
|
||||
if (creator is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (creator.CreatedBy != User.GetUserId())
|
||||
{
|
||||
await SendUnauthorizedAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
creator.DeletedAt = DateTimeOffset.UtcNow;
|
||||
creator.DeletedBy = User.GetUserId();
|
||||
|
||||
await context.SaveChangesAsync(ct);
|
||||
|
||||
await SendOkAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user