fix(service): add transactional support to author delete and update methods (#653)

This commit is contained in:
brios
2026-04-22 17:27:40 -04:00
committed by Zach Yale
parent 791a4eab6e
commit fd00da3a4e
@@ -28,6 +28,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers; import reactor.core.scheduler.Schedulers;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.nio.file.Files; import java.nio.file.Files;
@@ -42,6 +43,7 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
@AllArgsConstructor @AllArgsConstructor
@Transactional(readOnly = true)
public class AuthorMetadataService { public class AuthorMetadataService {
private final AuthorRepository authorRepository; private final AuthorRepository authorRepository;
@@ -93,6 +95,7 @@ public class AuthorMetadataService {
.toList(); .toList();
} }
@Transactional
public AuthorDetails matchAuthor(Long authorId, AuthorMatchRequest request) { public AuthorDetails matchAuthor(Long authorId, AuthorMatchRequest request) {
AuthorEntity author = authorRepository.findById(authorId) AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId)); .orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
@@ -120,6 +123,7 @@ public class AuthorMetadataService {
return toAuthorDetails(author); return toAuthorDetails(author);
} }
@Transactional
public AuthorDetails quickMatchAuthor(Long authorId, String region) { public AuthorDetails quickMatchAuthor(Long authorId, String region) {
AuthorEntity author = authorRepository.findById(authorId) AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId)); .orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
@@ -169,6 +173,7 @@ public class AuthorMetadataService {
.filter(java.util.Objects::nonNull); .filter(java.util.Objects::nonNull);
} }
@Transactional
public void unmatchAuthors(List<Long> authorIds) { public void unmatchAuthors(List<Long> authorIds) {
for (Long authorId : authorIds) { for (Long authorId : authorIds) {
AuthorEntity author = authorRepository.findById(authorId).orElse(null); AuthorEntity author = authorRepository.findById(authorId).orElse(null);
@@ -184,6 +189,7 @@ public class AuthorMetadataService {
} }
} }
@Transactional
public void deleteAuthors(List<Long> authorIds) { public void deleteAuthors(List<Long> authorIds) {
for (Long authorId : authorIds) { for (Long authorId : authorIds) {
AuthorEntity author = authorRepository.findById(authorId).orElse(null); AuthorEntity author = authorRepository.findById(authorId).orElse(null);
@@ -205,6 +211,7 @@ public class AuthorMetadataService {
} }
} }
@Transactional
public void uploadAuthorPhoto(Long authorId, MultipartFile file) { public void uploadAuthorPhoto(Long authorId, MultipartFile file) {
AuthorEntity author = authorRepository.findById(authorId) AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId)); .orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
@@ -221,6 +228,7 @@ public class AuthorMetadataService {
} }
} }
@Transactional
public AuthorDetails updateAuthor(Long authorId, AuthorUpdateRequest request) { public AuthorDetails updateAuthor(Long authorId, AuthorUpdateRequest request) {
AuthorEntity author = authorRepository.findById(authorId) AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId)); .orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));
@@ -261,6 +269,7 @@ public class AuthorMetadataService {
.take(50); .take(50);
} }
@Transactional
public void uploadAuthorPhotoFromUrl(Long authorId, String imageUrl) { public void uploadAuthorPhotoFromUrl(Long authorId, String imageUrl) {
AuthorEntity author = authorRepository.findById(authorId) AuthorEntity author = authorRepository.findById(authorId)
.orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId)); .orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(authorId));