Skip to content

Commit 13f3a4b

Browse files
committed
Improve not-found error; tidy comments; update Javadoc
1 parent 3c8a250 commit 13f3a4b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/main/java/com/codesungrape/hmcts/bookapi/service/BookService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ public Book createBook(BookRequest request) {
6060
return savedBook;
6161
}
6262

63-
// Soft Delete
63+
/**
64+
* Performs a soft delete on a Book entity by marking it as deleted.
65+
* This operation is idempotent - repeated calls will not trigger additional database writes.
66+
*
67+
* @param bookId The UUID of the book to soft delete
68+
* @throws ResourceNotFoundException if no book exists with the given ID
69+
*/
6470
@Transactional // Required: This method modifies data
6571
public void deleteBookById(UUID bookId) {
6672

67-
// find the book only if it's not already soft-deleted
6873
Book book = bookRepository.findById(bookId)
69-
.orElseThrow(() -> new ResourceNotFoundException("Book not found"));
74+
.orElseThrow(() -> new ResourceNotFoundException(String.format(
75+
"Book not found with id: %s", bookId
76+
)));
7077

7178
// Idempotent way to mark soft-delete and save
7279
if (!book.isDeleted()) {

src/test/java/com/codesungrape/hmcts/bookapi/BookServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void testDeleteBookById_ShouldDoNothing_WhenAlreadyDeleted() {
325325
testBookService.deleteBookById(testId);
326326

327327
// Assert
328-
// Verify save was NEVER called (it entered the 'false' branch of if)
328+
// Verify save was NEVER called (the if condition was false, so the if block was skipped)
329329
verify(testBookRepository, never()).save(any(Book.class));
330330
}
331331
}

0 commit comments

Comments
 (0)