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

Update MemberService.java #55

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
23 changes: 21 additions & 2 deletions src/main/java/com/libraryman_api/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,29 @@ public void deleteMember(int memberId) {
Members member = memberRepository.findById(memberId)
.orElseThrow(() -> new ResourceNotFoundException("Member not found"));

// TODO: Implement logic to check if the member has any outstanding fines or borrowed books.
// If there are no pending obligations, delete all related notifications, borrowings, and fines.
// Check for outstanding fines
List<Fines> outstandingFines = fineRepository.findByMemberIdAndIsPaidFalse(memberId);
if (!outstandingFines.isEmpty()) {
throw new MemberDeletionException("Cannot delete member with outstanding fines.");
}

// Check for borrowed books
List<Borrowings> borrowedBooks = borrowingRepository.getAllBorrowingsOfAMember(memberId);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import for Borrowings

if (!borrowedBooks.isEmpty()) {
throw new MemberDeletionException("Cannot delete member with borrowed books.");
}

// Delete related notifications
notificationRepository.deleteByMemberId(memberId);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add all relevant imports


// Delete related borrowings and fines
borrowingRepository.deleteByMemberId(memberId);
fineRepository.deleteByMemberId(memberId);

// Send account deletion notification
notificationService.accountDeletionNotification(member);

// Delete the member
memberRepository.delete(member);
}
}