fix(catalog): guard against null external IDs in manga update pipeline

- MangaUpdateService.update(): skip update when both aniListId and malId
  are null, preventing IllegalStateException for manually-created manga
- MangaUpdateService.fetchExternalMangaData(): return null instead of
  throwing when no external IDs available
- MangaResolutionService.createAndNotifyManga(): only enqueue update
  command when at least one external ID exists, avoiding dead-lettered
  queue messages
This commit is contained in:
Rodrigo Verdiani 2026-07-14 14:11:55 -03:00
parent 7d8cdd2be8
commit 331df77d28
2 changed files with 15 additions and 7 deletions

View File

@ -157,12 +157,14 @@ public class MangaResolutionService {
mangaRepository.save(
Manga.builder().title(title).aniListId(aniListId).malId(malId).build());
if (nonNull(aniListId) || nonNull(malId)) {
try {
mangaUpdateProducer.sendMangaUpdateCommand(new MangaUpdateCommand(manga.getId()));
} catch (Exception e) {
log.error(
"Failed to send manga update command for manga '{}' (ID: {})", title, manga.getId(), e);
}
}
return manga;
} catch (DataIntegrityViolationException e) {

View File

@ -1,5 +1,6 @@
package com.magamochi.catalog.service;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import com.magamochi.catalog.model.dto.MangaDataDTO;
@ -49,6 +50,12 @@ public class MangaUpdateService {
log.info("Updating manga with ID {}", mangaId);
var manga = mangaService.find(mangaId);
if (isNull(manga.getAniListId()) && isNull(manga.getMalId())) {
log.info("Skipping update for manga {}: no external IDs available", mangaId);
return;
}
var mangaData = fetchExternalMangaData(manga);
applyUpdatesToDatabase(manga, mangaData);
@ -95,8 +102,7 @@ public class MangaUpdateService {
throw (RuntimeException) fetchException;
}
throw new IllegalStateException(
"Cannot update manga: No external provider IDs found for Manga " + manga.getId());
return null;
}
private void applyUpdatesToDatabase(Manga manga, MangaDataDTO mangaData) {