Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user