many fixes and improvements - rework for modules/ and common/
feat(emailer): add Postmark and Resend providers
This commit is contained in:
54
backend/Modules/Memberships/Handlers/GetActiveMemberships.cs
Normal file
54
backend/Modules/Memberships/Handlers/GetActiveMemberships.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Hutopy.Infrastructure.Security;
|
||||
using Hutopy.Modules.Creators.Contracts;
|
||||
using Hutopy.Modules.Memberships.Data;
|
||||
|
||||
namespace Hutopy.Modules.Memberships.Handlers;
|
||||
|
||||
[PublicAPI]
|
||||
public record struct GetActiveMembershipsResponse(
|
||||
Guid Id,
|
||||
Guid CreatorId,
|
||||
string CreatorName,
|
||||
string CreatorPortraitUrl,
|
||||
DateTimeOffset? StartDate,
|
||||
DateTimeOffset? EndDate);
|
||||
|
||||
[PublicAPI]
|
||||
public class GetActiveMembershipsHandler(
|
||||
ICreatorLookup creatorLookup,
|
||||
MembershipsDbContext dbContext)
|
||||
: EndpointWithoutRequest<IEnumerable<GetActiveMembershipsResponse>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/memberships/active");
|
||||
Options(o => o.WithTags("Memberships"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var subscriptions = await dbContext
|
||||
.Memberships
|
||||
.Where(subscription => subscription.UserId == User.GetUserId())
|
||||
.Where(subscription => subscription.State == MembershipState.Active)
|
||||
.ToListAsync(ct);
|
||||
|
||||
var result = await Task.WhenAll(
|
||||
subscriptions.Select(async subscription =>
|
||||
{
|
||||
var creator = await creatorLookup.GetCreatorAsync(subscription.CreatorId, ct);
|
||||
|
||||
return new GetActiveMembershipsResponse(
|
||||
subscription.Id,
|
||||
subscription.CreatorId,
|
||||
creator?.Name ?? "Unknown Creator",
|
||||
creator?.PortraitUrl ?? string.Empty,
|
||||
subscription.StartDate,
|
||||
subscription.EndDate);
|
||||
}));
|
||||
|
||||
|
||||
await SendOkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user