Initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using AutoMapper;
|
||||
using FastEndpoints;
|
||||
using MetaCourse.Api.Data;
|
||||
using MetaCourse.Api.DTOs.Courses;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MetaCourse.Api.Endpoints.Courses;
|
||||
|
||||
public class GetCourseRequest
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetCourseEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<GetCourseRequest, GetCourseDetailsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/courses/{id}");
|
||||
AllowAnonymous();
|
||||
Summary(s => s.Summary = "Récupère le détail d'un cours avec ses sujets et ressources");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetCourseRequest req, CancellationToken ct)
|
||||
{
|
||||
var course = await db.Courses
|
||||
.AsNoTracking()
|
||||
.Include(c => c.Creator)
|
||||
.Include(c => c.Topics.OrderBy(t => t.Position))
|
||||
.ThenInclude(t => t.TopicResources.OrderBy(tr => tr.Position))
|
||||
.ThenInclude(tr => tr.Resource)
|
||||
.FirstOrDefaultAsync(c => c.Id == req.Id, ct);
|
||||
|
||||
if (course is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await SendOkAsync(mapper.Map<GetCourseDetailsDto>(course), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user