File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
main/java/com/codesungrape/hmcts/bookapi/service
test/java/com/codesungrape/hmcts/bookapi Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff 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 ()) {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments