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,31 @@
using AutoMapper;
using FastEndpoints;
using MetaCourse.Api.Data;
using MetaCourse.Api.DTOs.Resources;
using Microsoft.EntityFrameworkCore;
namespace MetaCourse.Api.Endpoints.Resources;
public class UpdateResourceEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<UpdateResourceDto, GetResourceDto>
{
public override void Configure()
{
Put("api/resources/{id}");
AllowAnonymous();
Summary(s => s.Summary = "Met à jour une ressource");
}
public override async Task HandleAsync(UpdateResourceDto req, CancellationToken ct)
{
var resource = await db.Resources.FirstOrDefaultAsync(r => r.Id == req.Id, ct);
if (resource is null)
{
await SendNotFoundAsync(ct);
return;
}
mapper.Map(req, resource);
await db.SaveChangesAsync(ct);
await SendOkAsync(mapper.Map<GetResourceDto>(resource), ct);
}
}