chore: 提交现有修改

This commit is contained in:
2025-12-02 12:11:25 +08:00
parent 541b75ecd8
commit 5332c87d9d
37 changed files with 429 additions and 677 deletions

View File

@@ -10,22 +10,17 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories;
/// <summary>
/// 支付记录的 EF Core 仓储实现。
/// </summary>
public sealed class EfPaymentRepository : IPaymentRepository
/// <remarks>
/// 初始化仓储。
/// </remarks>
public sealed class EfPaymentRepository(TakeoutAppDbContext context) : IPaymentRepository
{
private readonly TakeoutAppDbContext _context;
/// <summary>
/// 初始化仓储。
/// </summary>
public EfPaymentRepository(TakeoutAppDbContext context)
{
_context = context;
}
/// <inheritdoc />
public Task<PaymentRecord?> FindByIdAsync(long paymentId, long tenantId, CancellationToken cancellationToken = default)
{
return _context.PaymentRecords
return context.PaymentRecords
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.Id == paymentId)
.FirstOrDefaultAsync(cancellationToken);
@@ -34,7 +29,7 @@ public sealed class EfPaymentRepository : IPaymentRepository
/// <inheritdoc />
public Task<PaymentRecord?> FindByOrderIdAsync(long orderId, long tenantId, CancellationToken cancellationToken = default)
{
return _context.PaymentRecords
return context.PaymentRecords
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.OrderId == orderId)
.FirstOrDefaultAsync(cancellationToken);
@@ -43,7 +38,7 @@ public sealed class EfPaymentRepository : IPaymentRepository
/// <inheritdoc />
public async Task<IReadOnlyList<PaymentRefundRecord>> GetRefundsAsync(long paymentId, long tenantId, CancellationToken cancellationToken = default)
{
var refunds = await _context.PaymentRefundRecords
var refunds = await context.PaymentRefundRecords
.AsNoTracking()
.Where(x => x.TenantId == tenantId && x.PaymentRecordId == paymentId)
.OrderByDescending(x => x.CreatedAt)
@@ -55,19 +50,19 @@ public sealed class EfPaymentRepository : IPaymentRepository
/// <inheritdoc />
public Task AddPaymentAsync(PaymentRecord payment, CancellationToken cancellationToken = default)
{
return _context.PaymentRecords.AddAsync(payment, cancellationToken).AsTask();
return context.PaymentRecords.AddAsync(payment, cancellationToken).AsTask();
}
/// <inheritdoc />
public Task AddRefundAsync(PaymentRefundRecord refund, CancellationToken cancellationToken = default)
{
return _context.PaymentRefundRecords.AddAsync(refund, cancellationToken).AsTask();
return context.PaymentRefundRecords.AddAsync(refund, cancellationToken).AsTask();
}
/// <inheritdoc />
public async Task<IReadOnlyList<PaymentRecord>> SearchAsync(long tenantId, PaymentStatus? status, CancellationToken cancellationToken = default)
{
var query = _context.PaymentRecords
var query = context.PaymentRecords
.AsNoTracking()
.Where(x => x.TenantId == tenantId);
@@ -84,28 +79,28 @@ public sealed class EfPaymentRepository : IPaymentRepository
/// <inheritdoc />
public Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
return _context.SaveChangesAsync(cancellationToken);
return context.SaveChangesAsync(cancellationToken);
}
/// <inheritdoc />
public Task UpdatePaymentAsync(PaymentRecord payment, CancellationToken cancellationToken = default)
{
_context.PaymentRecords.Update(payment);
context.PaymentRecords.Update(payment);
return Task.CompletedTask;
}
/// <inheritdoc />
public async Task DeletePaymentAsync(long paymentId, long tenantId, CancellationToken cancellationToken = default)
{
var refunds = await _context.PaymentRefundRecords
var refunds = await context.PaymentRefundRecords
.Where(x => x.TenantId == tenantId && x.PaymentRecordId == paymentId)
.ToListAsync(cancellationToken);
if (refunds.Count > 0)
{
_context.PaymentRefundRecords.RemoveRange(refunds);
context.PaymentRefundRecords.RemoveRange(refunds);
}
var existing = await _context.PaymentRecords
var existing = await context.PaymentRecords
.Where(x => x.TenantId == tenantId && x.Id == paymentId)
.FirstOrDefaultAsync(cancellationToken);
if (existing == null)
@@ -113,6 +108,6 @@ public sealed class EfPaymentRepository : IPaymentRepository
return;
}
_context.PaymentRecords.Remove(existing);
context.PaymentRecords.Remove(existing);
}
}