Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using AutoMapper;
|
||||
using FastEndpoints;
|
||||
using MetaCourse.Api.Data;
|
||||
using MetaCourse.Api.DTOs.Courses;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MetaCourse.Api.Endpoints.Courses;
|
||||
|
||||
public class GetUserCoursesRequest
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
|
||||
public class GetUserCoursesEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<GetUserCoursesRequest, List<GetCourseDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/users/{userId}/courses");
|
||||
AllowAnonymous();
|
||||
Summary(s => s.Summary = "Liste les cours créés par un utilisateur");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserCoursesRequest req, CancellationToken ct)
|
||||
{
|
||||
var courses = await db.Courses
|
||||
.AsNoTracking()
|
||||
.Include(c => c.Creator)
|
||||
.Include(c => c.Topics)
|
||||
.Where(c => c.CreatorId == req.UserId)
|
||||
.OrderByDescending(c => c.UpdatedAt)
|
||||
.ToListAsync(ct);
|
||||
|
||||
await SendOkAsync(mapper.Map<List<GetCourseDto>>(courses), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user