Initial commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using AutoMapper;
|
||||
using FastEndpoints;
|
||||
using MetaCourse.Api.Data;
|
||||
using MetaCourse.Api.DTOs.Resources;
|
||||
using MetaCourse.Api.Entities;
|
||||
|
||||
namespace MetaCourse.Api.Endpoints.Resources;
|
||||
|
||||
public class CreateResourceEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<CreateResourceDto, GetResourceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("api/resources");
|
||||
AllowAnonymous();
|
||||
Summary(s => s.Summary = "Crée une nouvelle ressource dans le catalogue");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateResourceDto req, CancellationToken ct)
|
||||
{
|
||||
var resource = mapper.Map<Resource>(req);
|
||||
db.Resources.Add(resource);
|
||||
await db.SaveChangesAsync(ct);
|
||||
await SendAsync(mapper.Map<GetResourceDto>(resource), 201, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user