Cleaned code
This commit is contained in:
@@ -17,7 +17,7 @@ public class DeleteAuthorEndpoint(AuthorRepository authorRepository) : Endpoint<
|
||||
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);
|
||||
@@ -30,11 +30,12 @@ public class DeleteAuthorEndpoint(AuthorRepository authorRepository) : Endpoint<
|
||||
|
||||
if (author.Books?.Count > 0)
|
||||
{
|
||||
await Send.StringAsync("L'auteur possède encore des livres",409, cancellation: ct);
|
||||
await Send.StringAsync("L'auteur possède encore des livres", 409, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await authorRepository.DeleteAsync(author, ct);
|
||||
await Send.NoContentAsync(ct);;
|
||||
await Send.NoContentAsync(ct);
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class GetAuthorsEndpoint(AuthorRepository authorRepository) : EndpointWit
|
||||
Get("/authors/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await authorRepository.ProjectToListAsync<GetAuthorDto>(ct), ct);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class UpdateAuthorEndpoint(AuthorRepository authorRepository, AutoMapper.
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mapper.Map(req, author);
|
||||
await authorRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
|
||||
@@ -22,9 +22,8 @@ public class CreateBookEndpoint(BookRepository bookRepository, AuthorRepository
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await bookRepository.AddAsync(mapper.Map<Book>(req), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class GetBooksEndpoint(BookRepository bookRepository) : EndpointWithoutRe
|
||||
Get("/books/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await bookRepository.ProjectToListAsync<GetBookDto>(ct), ct);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class UpdateBookEndpoit(BookRepository bookRepository, AutoMapper.IMapper
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mapper.Map(req, book);
|
||||
await bookRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
|
||||
@@ -8,7 +8,8 @@ using FastEndpoints;
|
||||
|
||||
namespace BookHive.Endpoints.Loans;
|
||||
|
||||
public class CreateLoanEndpoint(LoanRepository loanRepository, BookRepository bookRepository, MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint<CreateLoanDto>
|
||||
public class CreateLoanEndpoint(LoanRepository loanRepository, BookRepository bookRepository, MemberRepository memberRepository, AutoMapper.IMapper mapper)
|
||||
: Endpoint<CreateLoanDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -24,7 +25,7 @@ public class CreateLoanEndpoint(LoanRepository loanRepository, BookRepository bo
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Member? member = await memberRepository.SingleOrDefaultAsync(new GetMemberByIdSpec(req.MemberId), ct);
|
||||
if (member is null)
|
||||
{
|
||||
@@ -37,7 +38,7 @@ public class CreateLoanEndpoint(LoanRepository loanRepository, BookRepository bo
|
||||
await Send.StringAsync("Le membre est désactivé", 400, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loan? loan = await loanRepository.FirstOrDefaultAsync(new GetAvailableBookByIdSpec(req.BookId), ct);
|
||||
if (loan is not null)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PatchReturnLoanEndpoint(LoanRepository loanRepository) : Endpoint<P
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
loan?.ReturnDate = req.ReturnDate;
|
||||
await loanRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class GetMembersEndpoint(MemberRepository memberRepository) : EndpointWit
|
||||
Get("/members/");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await memberRepository.ProjectToListAsync<GetMemberDto>(ct), ct);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class UpdateMemberEndpoint(MemberRepository memberRepository, AutoMapper.
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mapper.Map(req, member);
|
||||
await memberRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
|
||||
@@ -9,9 +9,9 @@ using FastEndpoints;
|
||||
namespace BookHive.Endpoints.Reviews;
|
||||
|
||||
public class CreateReviewEndpoint(
|
||||
ReviewRepository reviewRepository,
|
||||
MemberRepository memberRepository,
|
||||
BookRepository bookRepository,
|
||||
ReviewRepository reviewRepository,
|
||||
MemberRepository memberRepository,
|
||||
BookRepository bookRepository,
|
||||
AutoMapper.IMapper mapper)
|
||||
: Endpoint<CreateReviewDto>
|
||||
{
|
||||
@@ -29,14 +29,14 @@ public class CreateReviewEndpoint(
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Member? member = await memberRepository.SingleOrDefaultAsync(new GetMemberByIdSpec(req.MemberId), ct);
|
||||
if (member is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!member.IsActive)
|
||||
{
|
||||
await Send.StringAsync("Le membre est désactivé", 400, cancellation: ct);
|
||||
@@ -49,7 +49,7 @@ public class CreateReviewEndpoint(
|
||||
await Send.StringAsync("Le membre a déjà posté un commentaire", 400, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await reviewRepository.AddAsync(mapper.Map<Review>(req), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DeleteReviewEndpoint(ReviewRepository reviewRepository) : Endpoint<
|
||||
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);
|
||||
@@ -27,7 +27,7 @@ public class DeleteReviewEndpoint(ReviewRepository reviewRepository) : Endpoint<
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await reviewRepository.DeleteAsync(review, ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user