- 核心业务拆分为 Endpoint → Application Service → Repository 三层 - AI写入操作必须用户确认后才写库(确认卡片机制) - 报告/饮食/用药分析改为持久化任务队列(原子领取/重试/重启恢复) - 运动计划修复: 连续真实日期替代周模板 - 用药提醒去重 + 通知Outbox预留 - 认证收拢到AuthService, 管理员收拢到AdminService - AI会话加用户归属校验防串号 - 提示词调整为患者视角 - 开发假数据已关闭 - 21/21测试通过, 0警告0错误
45 lines
1.9 KiB
C#
45 lines
1.9 KiB
C#
using Health.Application.Exercises;
|
|
|
|
namespace Health.Infrastructure.Exercises;
|
|
|
|
public sealed class EfExerciseRepository(AppDbContext db) : IExerciseRepository
|
|
{
|
|
private readonly AppDbContext _db = db;
|
|
|
|
public async Task<IReadOnlyList<ExercisePlan>> ListActiveOnAsync(Guid userId, DateOnly date, CancellationToken ct) =>
|
|
await _db.ExercisePlans.Include(p => p.Items)
|
|
.Where(p => p.UserId == userId && p.StartDate <= date && p.EndDate >= date)
|
|
.OrderByDescending(p => p.StartDate)
|
|
.ToListAsync(ct);
|
|
|
|
public async Task<IReadOnlyList<ExercisePlan>> ListAsync(Guid userId, int limit, CancellationToken ct) =>
|
|
await _db.ExercisePlans.Include(p => p.Items)
|
|
.Where(p => p.UserId == userId)
|
|
.OrderByDescending(p => p.StartDate)
|
|
.Take(limit)
|
|
.ToListAsync(ct);
|
|
|
|
public Task<ExercisePlan?> GetOwnedPlanAsync(Guid userId, Guid planId, CancellationToken ct) =>
|
|
_db.ExercisePlans.Include(p => p.Items)
|
|
.FirstOrDefaultAsync(p => p.Id == planId && p.UserId == userId, ct);
|
|
|
|
public Task<ExercisePlan?> GetLatestAsync(Guid userId, CancellationToken ct) =>
|
|
_db.ExercisePlans.Include(p => p.Items)
|
|
.Where(p => p.UserId == userId)
|
|
.OrderByDescending(p => p.StartDate)
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
public Task<ExercisePlanItem?> GetOwnedItemAsync(Guid userId, Guid itemId, CancellationToken ct) =>
|
|
_db.ExercisePlanItems.Include(i => i.Plan)
|
|
.FirstOrDefaultAsync(i => i.Id == itemId && i.Plan != null && i.Plan.UserId == userId, ct);
|
|
|
|
public async Task AddAsync(ExercisePlan plan, CancellationToken ct) =>
|
|
await _db.ExercisePlans.AddAsync(plan, ct);
|
|
|
|
public void Delete(ExercisePlan plan) =>
|
|
_db.ExercisePlans.Remove(plan);
|
|
|
|
public Task SaveChangesAsync(CancellationToken ct) =>
|
|
_db.SaveChangesAsync(ct);
|
|
}
|