first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Fitness_core_BE.Interfaces;
|
||||
using Fitness_core_BE.Models;
|
||||
using Fitness_core_BE.Models.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Fitness_core_BE.Repos
|
||||
{
|
||||
public class PaymentsEnablementRepository : IPaymentsEnablementRepository
|
||||
{
|
||||
private readonly CentralDbContext _context;
|
||||
|
||||
public PaymentsEnablementRepository(CentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<ClientWallet?> GetWalletByClientIdAsync(Guid clientId, CancellationToken ct = default)
|
||||
{
|
||||
return await _context.ClientWallets
|
||||
.FirstOrDefaultAsync(w => w.FKClientId == clientId, ct);
|
||||
}
|
||||
|
||||
public async Task<List<WalletLedgerEntry>> GetLedgerAsync(Guid walletId, CancellationToken ct = default)
|
||||
{
|
||||
return await _context.WalletLedgerEntries
|
||||
.AsNoTracking()
|
||||
.Where(e => e.FKWalletId == walletId)
|
||||
.OrderByDescending(e => e.CreatedAt)
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<ClientPayoutKyc?> GetKycByClientIdAsync(Guid clientId, CancellationToken ct = default)
|
||||
{
|
||||
return await _context.ClientPayoutKycs
|
||||
.AsNoTracking()
|
||||
.Include(k => k.Client)
|
||||
.Where(k => k.FKClientId == clientId)
|
||||
.OrderByDescending(k => k.SubmittedAt)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<ClientPayoutKyc?> GetKycForUpdateAsync(
|
||||
Guid clientId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
return await _context.ClientPayoutKycs
|
||||
.Include(k => k.Client)
|
||||
.Where(k => k.FKClientId == clientId)
|
||||
.OrderByDescending(k => k.SubmittedAt)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
public async Task CreateKycAsync(ClientPayoutKyc kyc, CancellationToken ct = default)
|
||||
{
|
||||
await _context.ClientPayoutKycs.AddAsync(kyc, ct);
|
||||
}
|
||||
|
||||
public async Task<(List<ClientPayoutKyc> Items, int Total)> ListKycAsync(string? status, CancellationToken ct = default)
|
||||
{
|
||||
var query = _context.ClientPayoutKycs
|
||||
.AsNoTracking()
|
||||
.Include(k => k.Client)
|
||||
.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(status) && Enum.TryParse<KycStatus>(status, true, out var parsedStatus))
|
||||
query = query.Where(k => k.KycStatus == parsedStatus);
|
||||
|
||||
var total = await query.CountAsync(ct);
|
||||
var items = await query.OrderByDescending(k => k.SubmittedAt).ToListAsync(ct);
|
||||
|
||||
return (items, total);
|
||||
}
|
||||
|
||||
public async Task CreateWalletAsync(ClientWallet wallet, CancellationToken ct = default)
|
||||
{
|
||||
await _context.ClientWallets.AddAsync(wallet, ct);
|
||||
}
|
||||
|
||||
public async Task CreateClientCardAsync(ClientCard card, CancellationToken ct = default)
|
||||
{
|
||||
await _context.ClientCard.AddAsync(card, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user