first commit
This commit is contained in:
21
BookHive/Endpoints/Authors/CreateAuthorEndpoint.cs
Normal file
21
BookHive/Endpoints/Authors/CreateAuthorEndpoint.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using BookHive.DTO.Author;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Authors;
|
||||
|
||||
public class CreateAuthorEndpoint(AuthorRepository authorRepository, AutoMapper.IMapper mapper) : Endpoint<CreateAuthorDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/authors/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateAuthorDto req, CancellationToken ct)
|
||||
{
|
||||
await authorRepository.AddAsync(mapper.Map<Author>(req), ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user