Files
MetaCourseApi/MetaCourse.Api/Endpoints/Resources/GetResourcesEndpoint.cs
T
2026-05-05 10:39:43 +02:00

28 lines
805 B
C#

using AutoMapper;
using FastEndpoints;
using MetaCourse.Api.Data;
using MetaCourse.Api.DTOs.Resources;
using Microsoft.EntityFrameworkCore;
namespace MetaCourse.Api.Endpoints.Resources;
public class GetResourcesEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : EndpointWithoutRequest<List<GetResourceDto>>
{
public override void Configure()
{
Get("api/resources");
AllowAnonymous();
Summary(s => s.Summary = "Liste toutes les ressources du catalogue");
}
public override async Task HandleAsync(CancellationToken ct)
{
var resources = await db.Resources
.AsNoTracking()
.OrderByDescending(r => r.CreatedAt)
.ToListAsync(ct);
await SendOkAsync(mapper.Map<List<GetResourceDto>>(resources), ct);
}
}