This commit is contained in:
2024-10-22 16:41:11 -04:00
parent 114a10416a
commit 0c11d0aa5e
25 changed files with 1146 additions and 508 deletions

View File

@@ -1,18 +1,20 @@
using Hutopy.Web.Features.Memberships.Data;
using Hutopy.Web.Features.Memberships.Infrastructure;
namespace Hutopy.Web.Features.Memberships.Handlers;
[PublicAPI]
public class CreateMembershipTierRequest
{
public Guid CreatorId { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
public record struct CreateMembershipTierRequest(
Guid CreatorId,
string Name,
string Description,
decimal Price,
string Currency = "CAD");
[PublicAPI]
public class CreateMembershipTierEndpoint(
MembershipDbContext dbDbContext)
MembershipDbContext dbContext,
StripeService stripe)
: Endpoint<CreateMembershipTierRequest>
{
public override void Configure()
@@ -25,11 +27,29 @@ public class CreateMembershipTierEndpoint(
CreateMembershipTierRequest req,
CancellationToken ct)
{
var tier = dbDbContext
.Tiers
.Add(new Tier { CreatorId = req.CreatorId, Price = req.Price, Name = req.Name });
var tierId = Guid.NewGuid();
await dbDbContext.SaveChangesAsync(ct);
var productId = await stripe.CreateProductAsync(
req.CreatorId,
tierId,
req.Name,
req.Currency,
req.Price);
// Record the new Tier
var tier = new Tier
{
Id = tierId,
CreatorId = req.CreatorId,
Price = req.Price,
Name = req.Name,
Description = req.Description,
StripeProductId = productId,
};
dbContext.Tiers.Add(tier);
await dbContext.SaveChangesAsync(ct);
await SendOkAsync(tier, ct);
}