From eab9601aac7e794f86e04313048f698abf14bc47 Mon Sep 17 00:00:00 2001 From: Ajay Negi <97536703+ajaynegi45@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:09:09 +0530 Subject: [PATCH] Changes fines.java to fine.java --- .../borrowing/BorrowingRepository.java | 30 +++++++++++-------- .../borrowing/BorrowingService.java | 8 ++--- .../libraryman_api/borrowing/Borrowings.java | 8 ++--- .../borrowing/BorrowingsDto.java | 10 +++---- .../libraryman_api/fine/FineRepository.java | 2 +- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/libraryman_api/borrowing/BorrowingRepository.java b/src/main/java/com/libraryman_api/borrowing/BorrowingRepository.java index fad8870..b0718f4 100644 --- a/src/main/java/com/libraryman_api/borrowing/BorrowingRepository.java +++ b/src/main/java/com/libraryman_api/borrowing/BorrowingRepository.java @@ -1,7 +1,13 @@ package com.libraryman_api.borrowing; + +import com.libraryman_api.exception.InvalidSortFieldException; +import com.libraryman_api.exception.ResourceNotFoundException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.mapping.PropertyReferenceException; import org.springframework.stereotype.Repository; import java.time.LocalDate; @@ -11,18 +17,18 @@ @Repository public interface BorrowingRepository extends JpaRepository { - { - try { - Page borrowings = borrowingRepository.findByMember_memberId(memberId, pageable); - - if (borrowings.isEmpty()) { - throw new ResourceNotFoundException("Member didn't borrow any book"); - } - return borrowings.map(this::EntityToDto); - } catch (PropertyReferenceException ex) { - throw new InvalidSortFieldException("The specified 'sortBy' value is invalid."); - } - } +// { +// try { +// Page borrowings = borrowingRepository.findByMember_memberId(memberId, pageable); +// +// if (borrowings.isEmpty()) { +// throw new ResourceNotFoundException("Member didn't borrow any book"); +// } +// return borrowings.map(this::EntityToDto); +// } catch (PropertyReferenceException ex) { +// throw new InvalidSortFieldException("The specified 'sortBy' value is invalid."); +// } +// } Page findByMember_memberId(int memberId, Pageable pageable); diff --git a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java index 0b05b17..edd62e2 100644 --- a/src/main/java/com/libraryman_api/borrowing/BorrowingService.java +++ b/src/main/java/com/libraryman_api/borrowing/BorrowingService.java @@ -6,7 +6,7 @@ import com.libraryman_api.exception.InvalidSortFieldException; import com.libraryman_api.exception.ResourceNotFoundException; import com.libraryman_api.fine.FineRepository; -import com.libraryman_api.fine.Fines; +import com.libraryman_api.fine.Fine; import com.libraryman_api.member.MemberService; import com.libraryman_api.member.Members; import com.libraryman_api.member.dto.MembersDto; @@ -182,8 +182,8 @@ public synchronized BorrowingsDto returnBook(int borrowingId) { * @param borrowing the borrowing record with an overdue return * @return the saved fine record */ - private Fines imposeFine(Borrowings borrowing) { - Fines fine = new Fines(); + private Fine imposeFine(Borrowings borrowing) { + Fine fine = new Fine(); fine.setAmount(calculateFineAmount(borrowing)); return fineRepository.save(fine); } @@ -205,7 +205,7 @@ public String payFine(int borrowingId) { if (!memberDto.isPresent()) { throw new ResourceNotFoundException("Member not found"); } - Fines fine = borrowingsDto.getFine(); + Fine fine = borrowingsDto.getFine(); if (fine != null && !fine.isPaid()) { fine.setPaid(true); diff --git a/src/main/java/com/libraryman_api/borrowing/Borrowings.java b/src/main/java/com/libraryman_api/borrowing/Borrowings.java index cff70dd..1317bf8 100644 --- a/src/main/java/com/libraryman_api/borrowing/Borrowings.java +++ b/src/main/java/com/libraryman_api/borrowing/Borrowings.java @@ -1,7 +1,7 @@ package com.libraryman_api.borrowing; import com.libraryman_api.book.Book; -import com.libraryman_api.fine.Fines; +import com.libraryman_api.fine.Fine; import com.libraryman_api.member.Members; import jakarta.persistence.*; @@ -24,7 +24,7 @@ public class Borrowings { @OneToOne @JoinColumn(name = "fine_id") - private Fines fine; + private Fine fine; @ManyToOne @JoinColumn(name = "member_id", nullable = false) @@ -51,11 +51,11 @@ public Borrowings(Book book, Members member, Date borrowDate, Date dueDate, Date this.returnDate = returnDate; } - public Fines getFine() { + public Fine getFine() { return fine; } - public void setFine(Fines fine) { + public void setFine(Fine fine) { this.fine = fine; } diff --git a/src/main/java/com/libraryman_api/borrowing/BorrowingsDto.java b/src/main/java/com/libraryman_api/borrowing/BorrowingsDto.java index 6cd72af..08f8f6d 100644 --- a/src/main/java/com/libraryman_api/borrowing/BorrowingsDto.java +++ b/src/main/java/com/libraryman_api/borrowing/BorrowingsDto.java @@ -1,7 +1,7 @@ package com.libraryman_api.borrowing; import com.libraryman_api.book.BookDto; -import com.libraryman_api.fine.Fines; +import com.libraryman_api.fine.Fine; import com.libraryman_api.member.dto.MembersDto; import jakarta.validation.constraints.NotNull; @@ -12,7 +12,7 @@ public class BorrowingsDto { private int borrowingId; @NotNull(message = "Book is required") private BookDto book; - private Fines fine; + private Fine fine; @NotNull(message = "Member is required") private MembersDto member; @@ -21,7 +21,7 @@ public class BorrowingsDto { private Date returnDate; - public BorrowingsDto(int borrowingId, BookDto book, Fines fine, MembersDto member, Date borrowDate, Date dueDate, Date returnDate) { + public BorrowingsDto(int borrowingId, BookDto book, Fine fine, MembersDto member, Date borrowDate, Date dueDate, Date returnDate) { this.borrowingId = borrowingId; this.book = book; this.fine = fine; @@ -50,11 +50,11 @@ public void setBook(BookDto book) { this.book = book; } - public Fines getFine() { + public Fine getFine() { return fine; } - public void setFine(Fines fine) { + public void setFine(Fine fine) { this.fine = fine; } diff --git a/src/main/java/com/libraryman_api/fine/FineRepository.java b/src/main/java/com/libraryman_api/fine/FineRepository.java index 900c26f..5b0030c 100644 --- a/src/main/java/com/libraryman_api/fine/FineRepository.java +++ b/src/main/java/com/libraryman_api/fine/FineRepository.java @@ -4,7 +4,7 @@ import org.springframework.stereotype.Repository; @Repository -public interface FineRepository extends JpaRepository { +public interface FineRepository extends JpaRepository { }