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