Skip to content

Commit

Permalink
Changes fines.java to fine.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaynegi45 committed Nov 13, 2024
1 parent eaf4315 commit eab9601
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
30 changes: 18 additions & 12 deletions src/main/java/com/libraryman_api/borrowing/BorrowingRepository.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,18 +17,18 @@
@Repository
public interface BorrowingRepository extends JpaRepository<Borrowings, Integer> {

{
try {
Page<Borrowings> 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> 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<Borrowings> findByMember_memberId(int memberId, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/libraryman_api/borrowing/Borrowings.java
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -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)
Expand All @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/libraryman_api/borrowing/BorrowingsDto.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/libraryman_api/fine/FineRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.stereotype.Repository;

@Repository
public interface FineRepository extends JpaRepository<Fines, Integer> {
public interface FineRepository extends JpaRepository<Fine, Integer> {
}


0 comments on commit eab9601

Please sign in to comment.