Initial commit

This commit is contained in:
2026-05-05 10:39:43 +02:00
commit b590ecdc35
87 changed files with 3934 additions and 0 deletions
@@ -0,0 +1,36 @@
using AutoMapper;
using FastEndpoints;
using MetaCourse.Api.Data;
using MetaCourse.Api.DTOs.Topics;
using Microsoft.EntityFrameworkCore;
namespace MetaCourse.Api.Endpoints.Topics;
public class UpdateTopicEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<UpdateTopicDto, GetTopicDto>
{
public override void Configure()
{
Put("api/topics/{id}");
AllowAnonymous();
Summary(s => s.Summary = "Met à jour un sujet");
}
public override async Task HandleAsync(UpdateTopicDto req, CancellationToken ct)
{
var topic = await db.Topics
.Include(t => t.TopicResources)
.ThenInclude(tr => tr.Resource)
.FirstOrDefaultAsync(t => t.Id == req.Id, ct);
if (topic is null)
{
await SendNotFoundAsync(ct);
return;
}
mapper.Map(req, topic);
await db.SaveChangesAsync(ct);
await SendOkAsync(mapper.Map<GetTopicDto>(topic), ct);
}
}