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