fixed errors and finish endpoints
This commit is contained in:
28
.idea/.idea.BookHive/.idea/workspace.xml
generated
28
.idea/.idea.BookHive/.idea/workspace.xml
generated
@@ -6,11 +6,14 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="4c0ad985-5b6e-4587-85a5-1b48273bdb1d" name="Changes" comment="">
|
<list default="true" id="4c0ad985-5b6e-4587-85a5-1b48273bdb1d" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/BookHive/Endpoints/Books/UpdateBookEndpoit.cs" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/BookHive/Specifications/Loans/GetAvailableBookByIdSpec.cs" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/BookHive/Endpoints/Loans/PatchReturnLoanEndpoint.cs" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/BookHive/Specifications/Reviews/GetReviewByCriteriaSpec.cs" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.BookHive/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.BookHive/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.BookHive/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.BookHive/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BookHive/Endpoints/Authors/DeleteAuthorEndpoint.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BookHive/Endpoints/Authors/DeleteAuthorEndpoint.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BookHive/Endpoints/Books/CreateBookEndpoint.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BookHive/Endpoints/Books/CreateBookEndpoint.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BookHive/Endpoints/Books/DeleteBookEndpoint.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BookHive/Endpoints/Books/DeleteBookEndpoint.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BookHive/Endpoints/Loans/CreateLoanEndpoint.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BookHive/Endpoints/Loans/CreateLoanEndpoint.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -33,6 +36,8 @@
|
|||||||
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Members/CreateMemberEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Members/CreateMemberEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
|
<setting file="file://$PROJECT_DIR$/BookHive/Specifications/Loans/GetAvailableBookByIdSpec.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
|
<setting file="file://$PROJECT_DIR$/BookHive/Specifications/Reviews/GetReviewByCriteriaSpec.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
</component>
|
</component>
|
||||||
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
||||||
<component name="ProjectColorInfo">{
|
<component name="ProjectColorInfo">{
|
||||||
@@ -98,7 +103,7 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1773087844958</updated>
|
<updated>1773087844958</updated>
|
||||||
<workItem from="1773087846465" duration="527000" />
|
<workItem from="1773087846465" duration="527000" />
|
||||||
<workItem from="1773088517368" duration="3370000" />
|
<workItem from="1773088517368" duration="6491000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="first commit">
|
<task id="LOCAL-00001" summary="first commit">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -116,7 +121,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1773090621044</updated>
|
<updated>1773090621044</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="3" />
|
<task id="LOCAL-00003" summary="created all endpoints">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1773091913623</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1773091913623</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="4" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -127,7 +140,8 @@
|
|||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
<MESSAGE value="first commit" />
|
<MESSAGE value="first commit" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="first commit" />
|
<MESSAGE value="created all endpoints" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="created all endpoints" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ public class DeleteAuthorEndpoint(AuthorRepository authorRepository) : Endpoint<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (author.Books?.Count > 0)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("L'auteur possède encore des livres",409, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await authorRepository.DeleteAsync(author, ct);
|
await authorRepository.DeleteAsync(author, ct);
|
||||||
await Send.OkAsync(cancellation: ct);
|
await Send.OkAsync(cancellation: ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using BookHive.DTO.Book;
|
using BookHive.DTO.Book;
|
||||||
using BookHive.Models;
|
using BookHive.Models;
|
||||||
using BookHive.Repositories;
|
using BookHive.Repositories;
|
||||||
|
using BookHive.Specifications.Authors;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
|
||||||
namespace BookHive.Endpoints.Books;
|
namespace BookHive.Endpoints.Books;
|
||||||
|
|
||||||
public class CreateBookEndpoint(BookRepository bookRepository, AutoMapper.IMapper mapper) : Endpoint<CreateBookDto>
|
public class CreateBookEndpoint(BookRepository bookRepository, AuthorRepository authorRepository, AutoMapper.IMapper mapper) : Endpoint<CreateBookDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,13 @@ public class CreateBookEndpoint(BookRepository bookRepository, AutoMapper.IMappe
|
|||||||
|
|
||||||
public override async Task HandleAsync(CreateBookDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateBookDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
Author? author = await authorRepository.SingleOrDefaultAsync(new GetAuthorByIdSpec(req.AuthorId), ct);
|
||||||
|
if (author is null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await bookRepository.AddAsync(mapper.Map<Book>(req), ct);
|
await bookRepository.AddAsync(mapper.Map<Book>(req), ct);
|
||||||
await Send.OkAsync(cancellation: ct);
|
await Send.OkAsync(cancellation: ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using BookHive.Models;
|
using BookHive.Models;
|
||||||
using BookHive.Repositories;
|
using BookHive.Repositories;
|
||||||
using BookHive.Specifications.Books;
|
using BookHive.Specifications.Books;
|
||||||
|
using BookHive.Specifications.Loans;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
|
||||||
namespace BookHive.Endpoints.Books;
|
namespace BookHive.Endpoints.Books;
|
||||||
@@ -10,7 +11,7 @@ public class DeleteBookRequest
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteBookEndpoint(BookRepository bookRepository) : Endpoint<DeleteBookRequest>
|
public class DeleteBookEndpoint(BookRepository bookRepository, LoanRepository loanRepository) : Endpoint<DeleteBookRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,13 @@ public class DeleteBookEndpoint(BookRepository bookRepository) : Endpoint<Delete
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loan? loan = await loanRepository.FirstOrDefaultAsync(new GetAvailableBookByIdSpec(req.Id), ct);
|
||||||
|
if (loan is not null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Le livre est encore emprunté", 409, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await bookRepository.DeleteAsync(book, ct);
|
await bookRepository.DeleteAsync(book, ct);
|
||||||
await Send.OkAsync(cancellation: ct);
|
await Send.OkAsync(cancellation: ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using BookHive.DTO.Loan;
|
using BookHive.DTO.Loan;
|
||||||
using BookHive.Models;
|
using BookHive.Models;
|
||||||
using BookHive.Repositories;
|
using BookHive.Repositories;
|
||||||
|
using BookHive.Specifications.Books;
|
||||||
|
using BookHive.Specifications.Loans;
|
||||||
|
using BookHive.Specifications.Members;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
|
||||||
namespace BookHive.Endpoints.Loans;
|
namespace BookHive.Endpoints.Loans;
|
||||||
|
|
||||||
public class CreateLoanEndpoint(LoanRepository loanRepository, AutoMapper.IMapper mapper) : Endpoint<CreateLoanDto>
|
public class CreateLoanEndpoint(LoanRepository loanRepository, BookRepository bookRepository, MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint<CreateLoanDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -15,6 +18,39 @@ public class CreateLoanEndpoint(LoanRepository loanRepository, AutoMapper.IMappe
|
|||||||
|
|
||||||
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
Book? book = await bookRepository.SingleOrDefaultAsync(new GetBookByIdSpec(req.BookId), ct);
|
||||||
|
if (book is null)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loan? loan = await loanRepository.FirstOrDefaultAsync(new GetAvailableBookByIdSpec(req.BookId), ct);
|
||||||
|
if (loan is not null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Ce livre est déjà emprunté", 400, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.DueDate < req.LoanDate || req.DueDate.DayNumber - req.LoanDate.DayNumber < 1 || req.DueDate.DayNumber - req.LoanDate.DayNumber > 30)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("La date de retour estimée est incorrecte", 400, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await loanRepository.AddAsync(mapper.Map<Loan>(req), ct);
|
await loanRepository.AddAsync(mapper.Map<Loan>(req), ct);
|
||||||
await Send.OkAsync(cancellation: ct);
|
await Send.OkAsync(cancellation: ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using BookHive.Models;
|
|||||||
using BookHive.Repositories;
|
using BookHive.Repositories;
|
||||||
using BookHive.Specifications.Books;
|
using BookHive.Specifications.Books;
|
||||||
using BookHive.Specifications.Members;
|
using BookHive.Specifications.Members;
|
||||||
|
using BookHive.Specifications.Reviews;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
|
||||||
namespace BookHive.Endpoints.Reviews;
|
namespace BookHive.Endpoints.Reviews;
|
||||||
@@ -36,6 +37,19 @@ public class CreateReviewEndpoint(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!member.IsActive)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Le membre est désactivé", 400, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Review? review = await reviewRepository.SingleOrDefaultAsync(new GetReviewByCriteriaSpec(req.BookId, req.MemberId), ct);
|
||||||
|
if (review is not null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Le membre a déjà posté un commentaire", 400, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await reviewRepository.AddAsync(mapper.Map<Review>(req), ct);
|
await reviewRepository.AddAsync(mapper.Map<Review>(req), ct);
|
||||||
await Send.OkAsync(cancellation: ct);
|
await Send.OkAsync(cancellation: ct);
|
||||||
}
|
}
|
||||||
|
|||||||
13
BookHive/Specifications/Loans/GetAvailableBookByIdSpec.cs
Normal file
13
BookHive/Specifications/Loans/GetAvailableBookByIdSpec.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Ardalis.Specification;
|
||||||
|
using BookHive.Models;
|
||||||
|
|
||||||
|
namespace BookHive.Specifications.Loans;
|
||||||
|
|
||||||
|
public class GetAvailableBookByIdSpec : Specification<Loan>
|
||||||
|
{
|
||||||
|
public GetAvailableBookByIdSpec(int bookId)
|
||||||
|
{
|
||||||
|
Query
|
||||||
|
.Where(x => x.BookId == bookId && x.ReturnDate == null);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
BookHive/Specifications/Reviews/GetReviewByCriteriaSpec.cs
Normal file
13
BookHive/Specifications/Reviews/GetReviewByCriteriaSpec.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Ardalis.Specification;
|
||||||
|
using BookHive.Models;
|
||||||
|
|
||||||
|
namespace BookHive.Specifications.Reviews;
|
||||||
|
|
||||||
|
public class GetReviewByCriteriaSpec : SingleResultSpecification<Review>
|
||||||
|
{
|
||||||
|
public GetReviewByCriteriaSpec(int bookId, int memberId)
|
||||||
|
{
|
||||||
|
Query
|
||||||
|
.Where(x => x.BookId == bookId && x.MemberId == memberId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user