53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using Hutopy.Web.Common.Security;
|
|
using Hutopy.Web.Features.Memberships.Data;
|
|
using Hutopy.Web.Features.Memberships.Infrastructure;
|
|
|
|
namespace Hutopy.Web.Features.Memberships.Handlers;
|
|
|
|
[PublicAPI]
|
|
public record struct ChangeStripeIdRequest(
|
|
string StripeAccountId);
|
|
|
|
public class ChangeStripeIdHandler(
|
|
MembershipDbContext dbContext,
|
|
StripeService stripeService)
|
|
: Endpoint<ChangeStripeIdRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/creators/stripe-account");
|
|
Options(o => o.WithTags("Memberships"));
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
ChangeStripeIdRequest req,
|
|
CancellationToken ct)
|
|
{
|
|
var creatorId = HttpContext.User.GetUserId();
|
|
|
|
var creator = await dbContext
|
|
.Creators
|
|
.FindAsync(
|
|
[creatorId],
|
|
cancellationToken: ct);
|
|
|
|
if (creator is null)
|
|
{
|
|
creator = new Creator
|
|
{
|
|
Id = creatorId,
|
|
Name = HttpContext.User.GetAlias() ?? creatorId.ToString()
|
|
};
|
|
|
|
await dbContext.AddAsync(creator, ct);
|
|
}
|
|
|
|
creator.StripeAccountId = req.StripeAccountId;
|
|
creator.PortraitUrl = HttpContext.User.GetPortraitUrl();
|
|
|
|
await dbContext.SaveChangesAsync(ct);
|
|
|
|
await SendOkAsync(creator.Id, ct);
|
|
}
|
|
}
|