using GymLogAI.Application.Interfaces; using GymLogAI.Core.Entities; using Microsoft.EntityFrameworkCore; namespace GymLogAI.Persistence.Repositories; public sealed class WorkoutRepository(AppDbContext dbContext) : IWorkoutRepository { public async Task AddAsync(Workout workout, CancellationToken cancellationToken) { dbContext.Workouts.Add(workout); await dbContext.SaveChangesAsync(cancellationToken); return workout; } public async Task> GetHistoryAsync(Guid userId, CancellationToken cancellationToken) { return await dbContext.Workouts .AsNoTracking() .Include(x => x.WorkoutExercises) .ThenInclude(x => x.Exercise) .Include(x => x.WorkoutExercises) .ThenInclude(x => x.Sets) .Where(x => x.UserId == userId) .OrderByDescending(x => x.PerformedAtUtc) .ToListAsync(cancellationToken); } }