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);
|
||||
}
|
||||
}
|
||||
34
BookHive/Endpoints/Authors/DeleteAuthorEndpoint.cs
Normal file
34
BookHive/Endpoints/Authors/DeleteAuthorEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Authors;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Authors;
|
||||
|
||||
public class DeleteAuthorRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteAuthorEndpoint(AuthorRepository authorRepository) : Endpoint<DeleteAuthorRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/authors/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct)
|
||||
{
|
||||
Author? author = await authorRepository.SingleOrDefaultAsync(new GetAuthorByIdSpec(req.Id), ct);
|
||||
|
||||
if (author is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await authorRepository.DeleteAsync(author, ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
34
BookHive/Endpoints/Authors/GetAuthorEndpoint.cs
Normal file
34
BookHive/Endpoints/Authors/GetAuthorEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.DTO.Author;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Authors;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Authors;
|
||||
|
||||
public class AuthorRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetAuthorEndpoint(AuthorRepository authorRepository, AutoMapper.IMapper mapper) : Endpoint<AuthorRequest, GetAuthorDetailsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/authors/{@Id}/", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(AuthorRequest req, CancellationToken ct)
|
||||
{
|
||||
Author? author = await authorRepository.SingleOrDefaultAsync(new GetAuthorByIdSpec(req.Id), ct);
|
||||
|
||||
if (author is null)
|
||||
{
|
||||
await Send.NoContentAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetAuthorDetailsDto>(author), ct);
|
||||
}
|
||||
}
|
||||
19
BookHive/Endpoints/Authors/GetAuthorsEndpoint.cs
Normal file
19
BookHive/Endpoints/Authors/GetAuthorsEndpoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using BookHive.DTO.Author;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Authors;
|
||||
|
||||
public class GetAuthorsEndpoint(AuthorRepository authorRepository) : EndpointWithoutRequest<List<GetAuthorDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/authors/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await authorRepository.ProjectToListAsync<GetAuthorDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
30
BookHive/Endpoints/Authors/UpdateAuthorEndpoint.cs
Normal file
30
BookHive/Endpoints/Authors/UpdateAuthorEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using BookHive.DTO.Author;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Authors;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Authors;
|
||||
|
||||
public class UpdateAuthorEndpoint(AuthorRepository authorRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateAuthorDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/authors/{@Id}/", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct)
|
||||
{
|
||||
Author? author = await authorRepository.SingleOrDefaultAsync(new GetAuthorByIdSpec(req.Id), ct);
|
||||
if (author is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
mapper.Map(req, author);
|
||||
await authorRepository.SaveChangesAsync(ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
34
BookHive/Endpoints/Books/DeleteBookEndpoint.cs
Normal file
34
BookHive/Endpoints/Books/DeleteBookEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Books;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Books;
|
||||
|
||||
public class DeleteBookRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteBookEndpoint(BookRepository bookRepository) : Endpoint<DeleteBookRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/books/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct)
|
||||
{
|
||||
Book? book = await bookRepository.SingleOrDefaultAsync(new GetBookByIdSpec(req.Id), ct);
|
||||
|
||||
if (book is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await bookRepository.DeleteAsync(book, ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
34
BookHive/Endpoints/Books/GetBookEndpoint.cs
Normal file
34
BookHive/Endpoints/Books/GetBookEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.DTO.Book;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Books;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Books;
|
||||
|
||||
public class BookRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetBookEndpoint(BookRepository bookRepository, AutoMapper.IMapper mapper) : Endpoint<BookRequest, GetBookDetailsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/books/{@Id}/", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(BookRequest req, CancellationToken ct)
|
||||
{
|
||||
Book? book = await bookRepository.SingleOrDefaultAsync(new GetBookByIdSpec(req.Id), ct);
|
||||
|
||||
if (book is null)
|
||||
{
|
||||
await Send.NoContentAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetBookDetailsDto>(book), ct);
|
||||
}
|
||||
}
|
||||
19
BookHive/Endpoints/Books/GetBooksEndpoint.cs
Normal file
19
BookHive/Endpoints/Books/GetBooksEndpoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using BookHive.DTO.Book;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Books;
|
||||
|
||||
public class GetBooksEndpoint(BookRepository bookRepository) : EndpointWithoutRequest<List<GetBookDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/books/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await bookRepository.ProjectToListAsync<GetBookDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
21
BookHive/Endpoints/Loans/CreateLoanEndpoint.cs
Normal file
21
BookHive/Endpoints/Loans/CreateLoanEndpoint.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using BookHive.DTO.Loan;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Loans;
|
||||
|
||||
public class CreateLoanEndpoint(LoanRepository loanRepository, AutoMapper.IMapper mapper) : Endpoint<CreateLoanDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/loans/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)
|
||||
{
|
||||
await loanRepository.AddAsync(mapper.Map<Loan>(req), ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
19
BookHive/Endpoints/Loans/GetLoansEndpoint.cs
Normal file
19
BookHive/Endpoints/Loans/GetLoansEndpoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using BookHive.DTO.Loan;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Loans;
|
||||
|
||||
public class GetLoansEndpoint(LoanRepository loanRepository) : EndpointWithoutRequest<List<GetLoanDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/loans/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await loanRepository.ProjectToListAsync<GetLoanDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
21
BookHive/Endpoints/Members/CreateMemberEndpoint.cs
Normal file
21
BookHive/Endpoints/Members/CreateMemberEndpoint.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using BookHive.DTO.Member;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Members;
|
||||
|
||||
public class CreateMemberEndpoint(MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint<CreateMemberDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/members/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateMemberDto req, CancellationToken ct)
|
||||
{
|
||||
await memberRepository.AddAsync(mapper.Map<Member>(req), ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
34
BookHive/Endpoints/Members/GetMemberEndpoint.cs
Normal file
34
BookHive/Endpoints/Members/GetMemberEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.DTO.Member;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Members;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Members;
|
||||
|
||||
public class MemberRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetMemberEndpoint(MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint<MemberRequest, GetMemberDetailsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/members/{@Id}/", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(MemberRequest req, CancellationToken ct)
|
||||
{
|
||||
Member? member = await memberRepository.SingleOrDefaultAsync(new GetMemberByIdSpec(req.Id), ct);
|
||||
|
||||
if (member is null)
|
||||
{
|
||||
await Send.NoContentAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetMemberDetailsDto>(member), ct);
|
||||
}
|
||||
}
|
||||
19
BookHive/Endpoints/Members/GetMembersEndpoint.cs
Normal file
19
BookHive/Endpoints/Members/GetMembersEndpoint.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using BookHive.DTO.Member;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Members;
|
||||
|
||||
public class GetMembersEndpoint(MemberRepository memberRepository) : EndpointWithoutRequest<List<GetMemberDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/members/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await memberRepository.ProjectToListAsync<GetMemberDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
34
BookHive/Endpoints/Reviews/DeleteReviewEndpoint.cs
Normal file
34
BookHive/Endpoints/Reviews/DeleteReviewEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Reviews;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Reviews;
|
||||
|
||||
public class DeleteReviewsRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteReviewEndpoint(ReviewRepository reviewRepository) : Endpoint<DeleteReviewsRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/reviews/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteReviewsRequest req, CancellationToken ct)
|
||||
{
|
||||
Review? review = await reviewRepository.SingleOrDefaultAsync(new GetReviewByIdSpec(req.Id), ct);
|
||||
|
||||
if (review is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await reviewRepository.DeleteAsync(review, ct);
|
||||
await Send.OkAsync(cancellation: ct);
|
||||
}
|
||||
}
|
||||
35
BookHive/Endpoints/Reviews/GetReviewEndpoint.cs
Normal file
35
BookHive/Endpoints/Reviews/GetReviewEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using BookHive.DTO.Review;
|
||||
using BookHive.Models;
|
||||
using BookHive.Repositories;
|
||||
using BookHive.Specifications.Books;
|
||||
using BookHive.Specifications.Reviews;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Reviews;
|
||||
|
||||
public class ReviewRequest
|
||||
{
|
||||
public int BookId { get; set; }
|
||||
}
|
||||
|
||||
public class GetReviewEndpoint(BookRepository bookRepository, ReviewRepository reviewRepository) : Endpoint<ReviewRequest, List<GetReviewDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/books/{@BookId}/reviews", x => new { x.BookId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ReviewRequest req, CancellationToken ct)
|
||||
{
|
||||
Book? book = await bookRepository.SingleOrDefaultAsync(new GetBookByIdSpec(req.BookId), ct);
|
||||
|
||||
if (book is null)
|
||||
{
|
||||
await Send.NoContentAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(await reviewRepository.ProjectToListAsync<GetReviewDto>(new GetReviewByBookIdSpec(req.BookId), ct), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user