Fix runtime

This commit is contained in:
2024-10-20 16:49:59 -04:00
parent 070babb17a
commit 114a10416a
29 changed files with 133 additions and 2677 deletions

View File

@@ -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);
}
}