Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Enhance Reporting and Analytics Capabilities #102

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
@Repository
public interface BorrowingRepository extends JpaRepository<Borrowings, Integer> {

public Page<BorrowingsDto> getAllBorrowingsOfMember(int memberId, Pageable pageable) {
sanchitc05 marked this conversation as resolved.
Show resolved Hide resolved
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.");
}
}

@Query(value = "SELECT b.title AS bookTitle, COUNT(*) AS borrowCount " +
"FROM borrowings br JOIN books b ON br.book_id = b.book_id " +
"GROUP BY b.book_id ORDER BY borrowCount DESC LIMIT :limit", nativeQuery = true)
Expand All @@ -21,4 +34,4 @@ public interface BorrowingRepository extends JpaRepository<Borrowings, Integer>
"WHERE b.borrowDate BETWEEN :startDate AND :endDate " +
"GROUP BY FUNCTION('DATE', b.borrowDate)")
Map<String, Long> getBorrowingTrendsBetweenDates(LocalDate startDate, LocalDate endDate);
}
}