44import com .codesungrape .hmcts .bookapi .entity .Book ;
55import com .codesungrape .hmcts .bookapi .exception .ResourceNotFoundException ;
66import com .codesungrape .hmcts .bookapi .repository .BookRepository ;
7+ import jakarta .transaction .Transactional ;
78import lombok .RequiredArgsConstructor ;
89import 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
0 commit comments