Skip to content

Commit 3c8a250

Browse files
committed
Remove manual validation once Controller validation (@Valid) is implemented.
1 parent 85fb4ff commit 3c8a250

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.codesungrape.hmcts.bookapi.entity.Book;
55
import com.codesungrape.hmcts.bookapi.exception.ResourceNotFoundException;
66
import com.codesungrape.hmcts.bookapi.repository.BookRepository;
7+
import jakarta.transaction.Transactional;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.stereotype.Service;
910

@@ -27,13 +28,14 @@ public class BookService {
2728
* @throws NullPointerException if request is null
2829
* @throws IllegalArgumentException if title is null or blank
2930
*/
31+
@Transactional // Required: This method modifies data
3032
public Book createBook(BookRequest request) {
3133
// Validation check for business rules (e.g., uniqueness, if required)
3234
if (request == null) {
3335
throw new NullPointerException("BookRequest cannot be null");
3436
}
3537

36-
// TODO: Leaving this here for now as i haven't implemented the Controller Layer yet
38+
// TODO: Remove manual validation once Controller validation (@Valid) is implemented.
3739
// The service layer is duplicating validation that already exists in the
3840
// BookRequest DTO with @notblank annotations. Since the DTO has validation
3941
// constraints, this manual check is redundant when Spring's validation
@@ -59,6 +61,7 @@ public Book createBook(BookRequest request) {
5961
}
6062

6163
// Soft Delete
64+
@Transactional // Required: This method modifies data
6265
public void deleteBookById(UUID bookId) {
6366

6467
// find the book only if it's not already soft-deleted

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ void testCreateBook_Success() {
140140
verify(testBookRepository, times(1)).save(any(Book.class));
141141
}
142142

143-
// CoPilot feedback:
144-
// This test will fail because BookRequest uses @value from Lombok with @notblank validation.
145-
// The @notblank constraint on the title field means that creating a BookRequest with a null
146-
// title should trigger validation failure at the DTO level, not allow the object to be
147-
// created. Either the test expectations are incorrect, or the DTO validation is not being
148-
// applied. The same issue affects tests on lines 105-116, 119-127, and 130-138.
149-
150143
@Test
151144
void testCreateBook_NullRequest_ThrowsException() {
152145
// Act & Assert

0 commit comments

Comments
 (0)