using Fengling.Backend.Domain.AggregatesModel.GiftAggregate; namespace Fengling.Backend.Infrastructure.Repositories; public interface IGiftRepository : IRepository { Task GetByIdAsync(GiftId giftId, CancellationToken cancellationToken = default); Task> GetOnShelfGiftsAsync(CancellationToken cancellationToken = default); Task> GetByTypeAsync(GiftType type, CancellationToken cancellationToken = default); } public class GiftRepository(ApplicationDbContext context) : RepositoryBase(context), IGiftRepository { public async Task GetByIdAsync(GiftId giftId, CancellationToken cancellationToken = default) { return await DbContext.Gifts .FirstOrDefaultAsync(x => x.Id == giftId, cancellationToken); } public async Task> GetOnShelfGiftsAsync(CancellationToken cancellationToken = default) { return await DbContext.Gifts .Where(x => x.IsOnShelf) .OrderBy(x => x.SortOrder) .ThenByDescending(x => x.CreatedAt) .ToListAsync(cancellationToken); } public async Task> GetByTypeAsync(GiftType type, CancellationToken cancellationToken = default) { return await DbContext.Gifts .Where(x => x.Type == type && x.IsOnShelf) .OrderBy(x => x.SortOrder) .ThenByDescending(x => x.CreatedAt) .ToListAsync(cancellationToken); } }