Fix runtime
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using Hutopy.Web.Common.Security;
|
||||
using Hutopy.Web.Features.Memberships.Data;
|
||||
using Hutopy.Web.Features.Memberships.Services;
|
||||
|
||||
namespace Hutopy.Web.Features.Memberships.Handlers;
|
||||
|
||||
[PublicAPI]
|
||||
public record struct ConfigureStripeAccountRequest(
|
||||
Guid SubscriptionId,
|
||||
string StripeAccountId);
|
||||
|
||||
public class ConfigureStripeAccountHandler(
|
||||
MembershipDbContext dbContext,
|
||||
StripeService stripeService)
|
||||
: Endpoint<ConfigureStripeAccountRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/membership/stripe-account");
|
||||
Options(o => o.WithTags("Memberships"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
ConfigureStripeAccountRequest 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;
|
||||
|
||||
await dbContext.SaveChangesAsync(ct);
|
||||
|
||||
await SendOkAsync(creator.Id, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user