Compare commits
3 Commits
260b47f5b6
...
c6245b7e97
| Author | SHA1 | Date | |
|---|---|---|---|
| c6245b7e97 | |||
| bc8fe69e20 | |||
| 7df2ea1b7a |
@ -43,8 +43,10 @@ public class MangaIngestReviewController {
|
|||||||
operationId = "resolveMangaIngestReview")
|
operationId = "resolveMangaIngestReview")
|
||||||
@PostMapping("/ingest-reviews")
|
@PostMapping("/ingest-reviews")
|
||||||
public DefaultResponseDTO<Void> resolveMangaIngestReview(
|
public DefaultResponseDTO<Void> resolveMangaIngestReview(
|
||||||
@RequestParam Long id, @RequestParam String malId) {
|
@RequestParam Long id,
|
||||||
mangaIngestReviewService.resolveImportReview(id, malId);
|
@RequestParam(required = false) Long malId,
|
||||||
|
@RequestParam(required = false) Long aniListId) {
|
||||||
|
mangaIngestReviewService.resolveIngestReview(id, aniListId, malId);
|
||||||
|
|
||||||
return DefaultResponseDTO.ok().build();
|
return DefaultResponseDTO.ok().build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,66 +1,96 @@
|
|||||||
package com.magamochi.catalog.service;
|
package com.magamochi.catalog.service;
|
||||||
|
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
import com.magamochi.catalog.model.dto.MangaIngestReviewDTO;
|
import com.magamochi.catalog.model.dto.MangaIngestReviewDTO;
|
||||||
|
import com.magamochi.catalog.model.entity.MangaContentProvider;
|
||||||
import com.magamochi.catalog.model.entity.MangaIngestReview;
|
import com.magamochi.catalog.model.entity.MangaIngestReview;
|
||||||
|
import com.magamochi.catalog.model.repository.MangaContentProviderRepository;
|
||||||
import com.magamochi.catalog.model.repository.MangaIngestReviewRepository;
|
import com.magamochi.catalog.model.repository.MangaIngestReviewRepository;
|
||||||
import com.magamochi.common.exception.NotFoundException;
|
import com.magamochi.common.exception.NotFoundException;
|
||||||
|
import com.magamochi.ingestion.service.ContentProviderService;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MangaIngestReviewService {
|
public class MangaIngestReviewService {
|
||||||
|
private final MangaResolutionService mangaResolutionService;
|
||||||
|
private final ContentProviderService contentProviderService;
|
||||||
|
|
||||||
private final MangaIngestReviewRepository mangaIngestReviewRepository;
|
private final MangaIngestReviewRepository mangaIngestReviewRepository;
|
||||||
|
private final MangaContentProviderRepository mangaContentProviderRepository;
|
||||||
|
|
||||||
public List<MangaIngestReviewDTO> get() {
|
public List<MangaIngestReviewDTO> get() {
|
||||||
return mangaIngestReviewRepository.findAll().stream().map(MangaIngestReviewDTO::from).toList();
|
return mangaIngestReviewRepository.findAll().stream().map(MangaIngestReviewDTO::from).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteIngestReview(Long id) {
|
public void deleteIngestReview(Long id) {
|
||||||
var importReview = getImportReviewThrowIfNotFound(id);
|
var importReview = get(id);
|
||||||
|
|
||||||
mangaIngestReviewRepository.delete(importReview);
|
mangaIngestReviewRepository.delete(importReview);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveImportReview(Long id, String malId) {
|
public void resolveIngestReview(Long id, Long aniListId, Long malId) {
|
||||||
throw new NotImplementedException();
|
if (aniListId == 0) {
|
||||||
// var importReview = getImportReviewThrowIfNotFound(id);
|
aniListId = null;
|
||||||
//
|
}
|
||||||
// jikanRateLimiter.acquire();
|
|
||||||
// var jikanResult = jikanClient.getMangaById(Long.parseLong(malId)).data();
|
if (malId == 0) {
|
||||||
//
|
malId = null;
|
||||||
// if (isNull(jikanResult)) {
|
}
|
||||||
// throw new NotFoundException("MyAnimeList manga not found for ID: " + id);
|
|
||||||
// }
|
if (isNull(aniListId) && isNull(malId)) {
|
||||||
//
|
throw new IllegalArgumentException("At least one of aniListId or malId must be provided");
|
||||||
// var manga =
|
}
|
||||||
// mangaRepository
|
|
||||||
// .findByTitleIgnoreCase(jikanResult.title())
|
var ingestReview = get(id);
|
||||||
// .orElseGet(
|
var mangaTitle = ingestReview.getMangaTitle();
|
||||||
// () ->
|
var contentProviderId = ingestReview.getContentProvider().getId();
|
||||||
// mangaRepository.save(
|
|
||||||
// Manga.builder()
|
if (mangaContentProviderRepository.existsByMangaTitleIgnoreCaseAndContentProvider_Id(
|
||||||
// .title(jikanResult.title())
|
mangaTitle, contentProviderId)) {
|
||||||
// .malId(Long.parseLong(malId))
|
log.info(
|
||||||
// .build()));
|
"Manga with mangaTitle '{}' already exists for provider '{}', skipping ingest",
|
||||||
//
|
mangaTitle,
|
||||||
// if (!mangaContentProviderRepository.existsByMangaAndContentProviderAndUrlIgnoreCase(
|
contentProviderId);
|
||||||
// manga, importReview.getContentProvider(), importReview.getUrl())) {
|
return;
|
||||||
// mangaContentProviderRepository.save(
|
}
|
||||||
// MangaContentProvider.builder()
|
|
||||||
// .manga(manga)
|
var manga = mangaResolutionService.findOrCreateManga(aniListId, malId);
|
||||||
// .mangaTitle(importReview.getMangaTitle())
|
|
||||||
// .contentProvider(importReview.getContentProvider())
|
try {
|
||||||
// .url(importReview.getUrl())
|
var contentProvider = contentProviderService.find(contentProviderId);
|
||||||
// .build());
|
|
||||||
// }
|
mangaContentProviderRepository.save(
|
||||||
//
|
MangaContentProvider.builder()
|
||||||
// mangaIngestReviewRepository.delete(importReview);
|
.manga(manga)
|
||||||
|
.mangaTitle(mangaTitle)
|
||||||
|
.contentProvider(contentProvider)
|
||||||
|
.url(ingestReview.getUrl())
|
||||||
|
.build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(
|
||||||
|
"Failed to ingest manga with mangaTitle '{}' from provider '{}'",
|
||||||
|
mangaTitle,
|
||||||
|
contentProviderId,
|
||||||
|
e);
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
mangaIngestReviewRepository.delete(ingestReview);
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
"Successfully ingested manga with mangaTitle '{}' from provider {}",
|
||||||
|
mangaTitle,
|
||||||
|
contentProviderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MangaIngestReview getImportReviewThrowIfNotFound(Long id) {
|
private MangaIngestReview get(Long id) {
|
||||||
return mangaIngestReviewRepository
|
return mangaIngestReviewRepository
|
||||||
.findById(id)
|
.findById(id)
|
||||||
.orElseThrow(() -> new NotFoundException("Import review not found for ID: " + id));
|
.orElseThrow(() -> new NotFoundException("Import review not found for ID: " + id));
|
||||||
|
|||||||
@ -71,12 +71,28 @@ public class MangaUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MangaDataDTO fetchExternalMangaData(Manga manga) {
|
private MangaDataDTO fetchExternalMangaData(Manga manga) {
|
||||||
|
Exception fetchException = null;
|
||||||
|
|
||||||
if (nonNull(manga.getAniListId())) {
|
if (nonNull(manga.getAniListId())) {
|
||||||
return aniListService.getMangaDataById(manga.getAniListId());
|
try {
|
||||||
|
return aniListService.getMangaDataById(manga.getAniListId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to fetch manga data from AniList for Manga ID {}", manga.getId(), e);
|
||||||
|
fetchException = e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonNull(manga.getMalId())) {
|
if (nonNull(manga.getMalId())) {
|
||||||
return myAnimeListService.getMangaDataById(manga.getMalId());
|
try {
|
||||||
|
return myAnimeListService.getMangaDataById(manga.getMalId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to fetch manga data from MyAnimeList for Manga ID {}", manga.getId(), e);
|
||||||
|
fetchException = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonNull(fetchException)) {
|
||||||
|
throw (RuntimeException) fetchException;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user