Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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<GetUserEnrollmentsRequest, List<GetEnrollmentDto>>
|
||||
{
|
||||
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<List<GetEnrollmentDto>>(enrollments), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user