diff --git a/.idea/.idea.BookHive/.idea/workspace.xml b/.idea/.idea.BookHive/.idea/workspace.xml
index e1fe9db..fb89e6d 100644
--- a/.idea/.idea.BookHive/.idea/workspace.xml
+++ b/.idea/.idea.BookHive/.idea/workspace.xml
@@ -5,7 +5,13 @@
BookHive/BookHive.csproj
-
+
+
+
+
+
+
+
@@ -14,17 +20,28 @@
+
+
+
+
+
+
+
+
{
"associatedIndex": 5
}
+
+
+
@@ -35,6 +52,7 @@
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
+ "git-widget-placeholder": "master",
"vue.rearranger.settings.migration": "true"
}
}]]>
@@ -80,16 +98,36 @@
1773087844958
-
+
+
+
+ 1773090602496
+
+
+
+ 1773090602496
+
+
+
+ 1773090621044
+
+
+
+ 1773090621044
+
+
+
+
+
diff --git a/BookHive/Endpoints/Books/UpdateBookEndpoit.cs b/BookHive/Endpoints/Books/UpdateBookEndpoit.cs
new file mode 100644
index 0000000..1ac5b20
--- /dev/null
+++ b/BookHive/Endpoints/Books/UpdateBookEndpoit.cs
@@ -0,0 +1,30 @@
+using BookHive.DTO.Book;
+using BookHive.Models;
+using BookHive.Repositories;
+using BookHive.Specifications.Books;
+using FastEndpoints;
+
+namespace BookHive.Endpoints.Books;
+
+public class UpdateBookEndpoit(BookRepository bookRepository, AutoMapper.IMapper mapper) : Endpoint
+{
+ public override void Configure()
+ {
+ Put("/books/{@Id}/", x => new { x.Id });
+ AllowAnonymous();
+ }
+
+ public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct)
+ {
+ Book? book = await bookRepository.SingleOrDefaultAsync(new GetBookByIdSpec(req.Id), ct);
+ if (book is null)
+ {
+ await Send.NotFoundAsync(ct);
+ return;
+ }
+
+ mapper.Map(req, book);
+ await bookRepository.SaveChangesAsync(ct);
+ await Send.OkAsync(cancellation: ct);
+ }
+}
\ No newline at end of file
diff --git a/BookHive/Endpoints/Loans/PatchReturnLoanEndpoint.cs b/BookHive/Endpoints/Loans/PatchReturnLoanEndpoint.cs
new file mode 100644
index 0000000..ca04695
--- /dev/null
+++ b/BookHive/Endpoints/Loans/PatchReturnLoanEndpoint.cs
@@ -0,0 +1,35 @@
+using BookHive.Models;
+using BookHive.Repositories;
+using BookHive.Specifications.Loans;
+using FastEndpoints;
+
+namespace BookHive.Endpoints.Loans;
+
+public class PatchReturnLoanRequest
+{
+ public int Id { get; set; }
+ public DateOnly ReturnDate { get; set; }
+}
+
+public class PatchReturnLoanEndpoint(LoanRepository loanRepository) : Endpoint
+{
+ public override void Configure()
+ {
+ Patch("/loans/{@Id}/return/", x => new { x.Id });
+ AllowAnonymous();
+ }
+
+ public override async Task HandleAsync(PatchReturnLoanRequest req, CancellationToken ct)
+ {
+ Loan? loan = await loanRepository.SingleOrDefaultAsync(new GetLoanByIdSpec(req.Id), ct);
+ if (loan is null)
+ {
+ await Send.NotFoundAsync(ct);
+ await Send.OkAsync(cancellation: ct);
+ }
+
+ loan?.ReturnDate = req.ReturnDate;
+ await loanRepository.SaveChangesAsync(ct);
+ await Send.OkAsync(cancellation: ct);
+ }
+}
\ No newline at end of file
diff --git a/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs b/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs
new file mode 100644
index 0000000..d795412
--- /dev/null
+++ b/BookHive/Endpoints/Members/UpdateMemberEndpoint.cs
@@ -0,0 +1,30 @@
+using BookHive.DTO.Member;
+using BookHive.Models;
+using BookHive.Repositories;
+using BookHive.Specifications.Members;
+using FastEndpoints;
+
+namespace BookHive.Endpoints.Members;
+
+public class UpdateMemberEndpoint(MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint
+{
+ public override void Configure()
+ {
+ Put("/members/{@Id}/", x => new { x.Id });
+ AllowAnonymous();
+ }
+
+ public override async Task HandleAsync(UpdateMemberDto req, CancellationToken ct)
+ {
+ Member? member = await memberRepository.SingleOrDefaultAsync(new GetMemberByIdSpec(req.Id), ct);
+ if (member is null)
+ {
+ await Send.NotFoundAsync(ct);
+ return;
+ }
+
+ mapper.Map(req, member);
+ await memberRepository.SaveChangesAsync(ct);
+ await Send.OkAsync(cancellation: ct);
+ }
+}
\ No newline at end of file
diff --git a/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs b/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs
new file mode 100644
index 0000000..8e6f29c
--- /dev/null
+++ b/BookHive/Endpoints/Reviews/CreateReviewEndpoint.cs
@@ -0,0 +1,42 @@
+using BookHive.DTO.Review;
+using BookHive.Models;
+using BookHive.Repositories;
+using BookHive.Specifications.Books;
+using BookHive.Specifications.Members;
+using FastEndpoints;
+
+namespace BookHive.Endpoints.Reviews;
+
+public class CreateReviewEndpoint(
+ ReviewRepository reviewRepository,
+ MemberRepository memberRepository,
+ BookRepository bookRepository,
+ AutoMapper.IMapper mapper)
+ : Endpoint
+{
+ public override void Configure()
+ {
+ Post("/books/{@BookId}/reviews/");
+ AllowAnonymous();
+ }
+
+ public override async Task HandleAsync(CreateReviewDto 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;
+ }
+
+ await reviewRepository.AddAsync(mapper.Map(req), ct);
+ await Send.OkAsync(cancellation: ct);
+ }
+}
\ No newline at end of file