using AutoMapper; using FastEndpoints; using MetaCourse.Api.Data; using MetaCourse.Api.DTOs.UserCourses; using Microsoft.EntityFrameworkCore; namespace MetaCourse.Api.Endpoints.UserCourses; public class GetUserEnrollmentsRequest { public Guid UserId { get; set; } } public class GetUserEnrollmentsEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint> { public override void Configure() { Get("api/users/{userId}/enrollments"); AllowAnonymous(); Summary(s => s.Summary = "Liste les cours auxquels un utilisateur est inscrit"); } public override async Task HandleAsync(GetUserEnrollmentsRequest req, CancellationToken ct) { var enrollments = await db.UserCourses .AsNoTracking() .Include(uc => uc.Course) .Where(uc => uc.UserId == req.UserId) .OrderByDescending(uc => uc.EnrolledAt) .ToListAsync(ct); await SendOkAsync(mapper.Map>(enrollments), ct); } }