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 AutoMapper;
using FastEndpoints;
using MetaCourse.Api.Data;
using MetaCourse.Api.DTOs.Courses;
using Microsoft.EntityFrameworkCore;
namespace MetaCourse.Api.Endpoints.Courses;
public class UpdateCourseEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<UpdateCourseDto, GetCourseDto>
{
public override void Configure()
{
Put("api/courses/{id}");
AllowAnonymous();
Summary(s => s.Summary = "Met à jour le titre et la description d'un cours");
}
public override async Task HandleAsync(UpdateCourseDto req, CancellationToken ct)
{
var course = await db.Courses
.Include(c => c.Creator)
.Include(c => c.Topics)
.FirstOrDefaultAsync(c => c.Id == req.Id, ct);
if (course is null)
{
await SendNotFoundAsync(ct);
return;
}
mapper.Map(req, course);
course.UpdatedAt = DateTime.UtcNow;
await db.SaveChangesAsync(ct);
await SendOkAsync(mapper.Map<GetCourseDto>(course), ct);
}
}