Files
social-media/src/Application/Stripe/Queries/GetMyLastReceipt.cs
2024-05-12 16:40:24 -04:00

30 lines
972 B
C#

using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Stripe.Queries;
public record GetMyLastReceiptQuery : IRequest<MyLastReceiptDto>
{
public string Email { get; set; } = string.Empty;
public string CreatorId { get; set; } = string.Empty;
};
public class GetMyLastReceiptQueryHandler(
IApplicationDbContext dbContext
)
: IRequestHandler<GetMyLastReceiptQuery, MyLastReceiptDto>
{
public async Task<MyLastReceiptDto> Handle(GetMyLastReceiptQuery request, CancellationToken cancellationToken)
{
var lastTransaction = await dbContext.UserTransactions.OrderBy(x => x.Created)
.LastOrDefaultAsync(x => x.ApplicationUserId == request.CreatorId && x.StripeBillingDetailEmail == request.Email,
cancellationToken);
var receiptUrl = new MyLastReceiptDto
{
ReceiptUrl = lastTransaction?.StripeReceiptUrl ?? "",
};
return receiptUrl;
}
}