many fixes and improvements - rework for modules/ and common/

feat(emailer): add Postmark and Resend providers
This commit is contained in:
2025-06-06 12:21:43 -04:00
parent 31ba18fa8d
commit 25b94d3e02
313 changed files with 6586 additions and 18260 deletions

View File

@@ -0,0 +1,49 @@
using Hutopy.Modules.Memberships.Contracts;
using Hutopy.Modules.Memberships.Data;
namespace Hutopy.Modules.Memberships.Handlers;
[PublicAPI]
public class CancelMembershipRequest
{
public Guid SubscriptionId { get; set; }
}
public class CancelMembershipHandler(
MembershipsDbContext dbContext,
IMembershipCancellationProcessor cancellationProcessor)
: Endpoint<CancelMembershipRequest>
{
public override void Configure()
{
Delete("/api/memberships");
Options(o => o.WithTags("Memberships"));
}
public override async Task HandleAsync(
CancelMembershipRequest req,
CancellationToken ct)
{
var subscription = await dbContext
.Memberships
.FindAsync(
[req.SubscriptionId],
cancellationToken: ct);
if (subscription is not { EndDate: null }
|| subscription.StripeSubscriptionId is null)
{
await SendNotFoundAsync(ct);
return;
}
// Cancel Stripe subscription
await cancellationProcessor.CancelAsync(subscription.StripeSubscriptionId, ct);
// Update subscription in the system
subscription.EndDate = DateTime.UtcNow;
await dbContext.SaveChangesAsync(ct);
await SendOkAsync(subscription.Id, ct);
}
}