30 lines
972 B
C#
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;
|
|
}
|
|
}
|