fengling-member-service/src/Fengling.Member.Infrastructure/Repositories/PointsHistoryRepository.cs
sam 92247346dd refactor: major project restructuring and cleanup
Changes:

- Remove deprecated Fengling.Activity and YarpGateway.Admin projects

- Add points processing services with distributed lock support

- Update Vben frontend with gateway management pages

- Add gateway config controller and database listener

- Update routing to use header-mixed-nav layout

- Add comprehensive test suites for Member services

- Add YarpGateway integration tests

- Update package versions in Directory.Packages.props

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-02-15 10:34:07 +08:00

55 lines
1.8 KiB
C#

using Fengling.Member.Domain.Aggregates.PointsModel;
using Microsoft.EntityFrameworkCore;
namespace Fengling.Member.Infrastructure.Repositories;
/// <summary>
/// 积分历史仓储实现
/// </summary>
public class PointsHistoryRepository : IPointsHistoryRepository
{
private readonly ApplicationDbContext _context;
public PointsHistoryRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<bool> ExistsBySourceIdAsync(string sourceId, CancellationToken cancellationToken = default)
{
return await _context.PointsTransactions
.AnyAsync(t => t.SourceId == sourceId, cancellationToken);
}
public async Task<IEnumerable<PointsTransaction>> GetByMemberIdAsync(
long memberId,
int page = 1,
int pageSize = 20,
CancellationToken cancellationToken = default)
{
return await _context.PointsTransactions
.Where(t => t.MemberId == memberId)
.OrderByDescending(t => t.CreatedAt)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToListAsync(cancellationToken);
}
public async Task<int> CountByMemberIdAsync(long memberId, CancellationToken cancellationToken = default)
{
return await _context.PointsTransactions
.CountAsync(t => t.MemberId == memberId, cancellationToken);
}
public async Task<PointsTransaction?> GetByIdAsync(long id, CancellationToken cancellationToken = default)
{
return await _context.PointsTransactions.FindAsync(new object[] { id }, cancellationToken);
}
public async Task AddAsync(PointsTransaction transaction, CancellationToken cancellationToken = default)
{
_context.PointsTransactions.Add(transaction);
await _context.SaveChangesAsync(cancellationToken);
}
}