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,37 @@
using FastEndpoints;
using MetaCourse.Api.Data;
using Microsoft.EntityFrameworkCore;
namespace MetaCourse.Api.Endpoints.Topics;
public class UnlinkResourceRequest
{
public Guid TopicId { get; set; }
public Guid ResourceId { get; set; }
}
public class UnlinkResourceFromTopicEndpoint(AppDbContext db) : Endpoint<UnlinkResourceRequest>
{
public override void Configure()
{
Delete("api/topics/{topicId}/resources/{resourceId}");
AllowAnonymous();
Summary(s => s.Summary = "Dissocie une ressource d'un sujet");
}
public override async Task HandleAsync(UnlinkResourceRequest req, CancellationToken ct)
{
var link = await db.TopicResources
.FirstOrDefaultAsync(tr => tr.TopicId == req.TopicId && tr.ResourceId == req.ResourceId, ct);
if (link is null)
{
await SendNotFoundAsync(ct);
return;
}
db.TopicResources.Remove(link);
await db.SaveChangesAsync(ct);
await SendNoContentAsync(ct);
}
}