fix: limit author name to 255 characters as in table (#801)

This commit is contained in:
Alberto Paro
2025-08-05 04:43:43 +02:00
committed by GitHub
parent c2c7a241bb
commit 95bc88feea

View File

@@ -56,13 +56,15 @@ public class BookCreatorService {
bookEntity.getMetadata().setAuthors(new HashSet<>());
}
authors.stream()
.map(authorName -> truncate(authorName, 255))
.map(authorName -> authorRepository.findByName(authorName)
.orElseGet(() -> authorRepository.save(AuthorEntity.builder().name(authorName).build())))
.forEach(authorEntity -> bookEntity.getMetadata().getAuthors().add(authorEntity));
}
private String truncate(String input, int maxLength) {
if (input == null) return null;
if (input == null)
return null;
return input.length() <= maxLength ? input : input.substring(0, maxLength);
}