Project.Fengling.QoderVersion/Backend/src/Fengling.Backend.Infrastructure/Repositories/GiftRepository.cs
sam e24925e1ed chore(build): 添加基础构建配置和版本管理
- 新增 .dockerignore 文件,忽略多种临时及中间文件
- 新增 .gitattributes 文件,配置文本文件换行及合并行为
- 新增详细的 .gitignore 文件,排除多种开发及生成文件
- 新增 VS Code C# 代码片段,提升开发效率
- 添加 Directory.Build.props,统一 MSBuild 配置和代码分析规则
- 添加空的 Directory.Build.targets,预留构建任务扩展位置
- 添加 Directory.Packages.props,实现依赖包版本集中管理和声明
2026-02-11 12:58:54 +08:00

39 lines
1.5 KiB
C#

using Fengling.Backend.Domain.AggregatesModel.GiftAggregate;
namespace Fengling.Backend.Infrastructure.Repositories;
public interface IGiftRepository : IRepository<Gift, GiftId>
{
Task<Gift?> GetByIdAsync(GiftId giftId, CancellationToken cancellationToken = default);
Task<List<Gift>> GetOnShelfGiftsAsync(CancellationToken cancellationToken = default);
Task<List<Gift>> GetByTypeAsync(GiftType type, CancellationToken cancellationToken = default);
}
public class GiftRepository(ApplicationDbContext context)
: RepositoryBase<Gift, GiftId, ApplicationDbContext>(context), IGiftRepository
{
public async Task<Gift?> GetByIdAsync(GiftId giftId, CancellationToken cancellationToken = default)
{
return await DbContext.Gifts
.FirstOrDefaultAsync(x => x.Id == giftId, cancellationToken);
}
public async Task<List<Gift>> 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<List<Gift>> 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);
}
}