refinement phase 3

This commit is contained in:
hamid
2026-07-13 11:26:39 +03:30
parent 1ce36f9414
commit 314763f764
194 changed files with 24211 additions and 274 deletions
@@ -103,32 +103,48 @@ internal sealed class RefundRepository : BaseAsyncRepository<Refund>, IRefundRep
return new PagedResult<RefundListItemDto>(items, total, page, pageSize);
}
public async Task<RefundStatusProjection?> GetStatusAsync(long id, CancellationToken cancellationToken)
{
var row = await (from r in TableNoTracking
where r.Id == id
join b in DbContext.Set<Booking>() on r.BookingId equals b.Id
join c in DbContext.Set<CustomerProfile>() on b.CustomerId equals c.Id
select new
{
c.UserId,
r.Id,
r.BookingId,
r.Status,
r.RefundChannel,
r.Amount,
r.ExpectedCustomerRefundEta,
r.GatewayRefundReference,
r.ExternalRevertReference
})
.FirstOrDefaultAsync(cancellationToken);
public Task<RefundStatusProjection?> GetStatusAsync(long id, CancellationToken cancellationToken)
=> StatusProjection(r => r.Id == id, cancellationToken);
public Task<RefundStatusProjection?> GetStatusByBookingAsync(long bookingId, CancellationToken cancellationToken)
// Newest refund for the booking (a re-refund is rare, but keep it deterministic).
=> StatusProjection(r => r.BookingId == bookingId, cancellationToken, latestFirst: true);
private async Task<RefundStatusProjection?> StatusProjection(
System.Linq.Expressions.Expression<Func<Refund, bool>> predicate, CancellationToken cancellationToken, bool latestFirst = false)
{
var query = from r in TableNoTracking.Where(predicate)
join b in DbContext.Set<Booking>() on r.BookingId equals b.Id
join c in DbContext.Set<CustomerProfile>() on b.CustomerId equals c.Id
select new
{
c.UserId,
r.Id,
r.BookingId,
r.Status,
r.RefundChannel,
r.Amount,
r.ExpectedCustomerRefundEta,
r.GatewayRefundReference,
r.ExternalRevertReference,
r.PlatformFeeRefundedIrr,
r.NursePayoutRefundedIrr,
r.RefundPercentageApplied,
r.CancellationPolicyCode,
r.CreatedAt,
r.ProcessedAt
};
var row = await (latestFirst ? query.OrderByDescending(x => x.Id) : query).FirstOrDefaultAsync(cancellationToken);
if (row is null)
return null;
var reference = Mask(row.GatewayRefundReference ?? row.ExternalRevertReference);
var dto = new RefundStatusDto(row.Id, row.BookingId, row.Status, row.RefundChannel, row.Amount.ToString(),
row.ExpectedCustomerRefundEta, reference);
var dto = new RefundStatusDto(
row.Id, row.BookingId, row.Status, row.RefundChannel, row.Amount.ToString(),
row.ExpectedCustomerRefundEta, reference,
row.PlatformFeeRefundedIrr.ToString(), row.NursePayoutRefundedIrr.ToString(),
row.RefundPercentageApplied, row.CancellationPolicyCode, row.CreatedAt, row.ProcessedAt);
return new RefundStatusProjection(row.UserId, dto);
}