feat: mise à jour de la gestion des chapitres en remplaçant les types d'identifiants par des flottants pour une meilleure cohérence, ajout de la documentation pour les méthodes de recherche de chapitres, et amélioration de la gestion des exceptions lors de la récupération des chapitres.
This commit is contained in:
parent
5928cfd5f0
commit
c0bd9c69b1
@@ -52,20 +52,20 @@ readonly class FetchMangaChaptersHandler
|
||||
// Définir les règles de priorité des langues (fr > en > autres)
|
||||
$shouldReplaceChapter = false;
|
||||
|
||||
if (!isset($chaptersByNumber[$chapterNumber])) {
|
||||
if (!isset($chaptersByNumber[(string) $chapterNumber])) {
|
||||
// Si c'est le premier chapitre avec ce numéro qu'on rencontre
|
||||
$shouldReplaceChapter = true;
|
||||
$chapterNumbers[] = $chapterNumber;
|
||||
} else if ($language === 'fr') {
|
||||
// Le français est toujours prioritaire
|
||||
$shouldReplaceChapter = true;
|
||||
} else if ($language === 'en' && $chapterLanguages[$chapterNumber] !== 'fr') {
|
||||
} else if ($language === 'en' && $chapterLanguages[(string) $chapterNumber] !== 'fr') {
|
||||
// L'anglais est prioritaire sur les autres langues, sauf le français
|
||||
$shouldReplaceChapter = true;
|
||||
}
|
||||
|
||||
if ($shouldReplaceChapter) {
|
||||
$chaptersByNumber[$chapterNumber] = new Chapter(
|
||||
$chaptersByNumber[(string) $chapterNumber] = new Chapter(
|
||||
new ChapterId((string) Uuid::uuid4()),
|
||||
$manga->getId()->getValue(),
|
||||
$chapterNumber,
|
||||
@@ -75,7 +75,7 @@ readonly class FetchMangaChaptersHandler
|
||||
false,
|
||||
new \DateTimeImmutable()
|
||||
);
|
||||
$chapterLanguages[$chapterNumber] = $language;
|
||||
$chapterLanguages[(string) $chapterNumber] = $language;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ readonly class FetchMangaChaptersHandler
|
||||
|
||||
// Sauvegarde uniquement les nouveaux chapitres
|
||||
foreach ($chaptersByNumber as $chapterNumber => $chapter) {
|
||||
if (!isset($existingChapters[$chapterNumber])) {
|
||||
if (!isset($existingChapters[(float) $chapterNumber])) {
|
||||
$this->mangaRepository->saveChapter($chapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,9 @@ interface MangaRepositoryInterface
|
||||
public function findBySlug(MangaSlug $slug): ?Manga;
|
||||
public function search(string $query, int $page = 1, int $limit = 20): array;
|
||||
public function countSearch(string $query): int;
|
||||
/**
|
||||
* @param float[] $chapterNumbers
|
||||
* @return array<float, Chapter>
|
||||
*/
|
||||
public function findExistingChaptersByNumbers(string $mangaId, array $chapterNumbers): array;
|
||||
}
|
||||
|
||||
@@ -200,6 +200,10 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float[] $chapterNumbers
|
||||
* @return array<float, Chapter>
|
||||
*/
|
||||
public function findExistingChaptersByNumbers(string $mangaId, array $chapterNumbers): array
|
||||
{
|
||||
$queryBuilder = $this->entityManager->createQueryBuilder()
|
||||
@@ -208,13 +212,13 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
->where('c.manga = :mangaId')
|
||||
->andWhere('c.number IN (:chapterNumbers)')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setParameter('chapterNumbers', $chapterNumbers);
|
||||
->setParameter('chapterNumbers', array_map('floatval', $chapterNumbers));
|
||||
|
||||
$chapters = $queryBuilder->getQuery()->getResult();
|
||||
|
||||
$chaptersByNumber = [];
|
||||
foreach ($chapters as $chapter) {
|
||||
$chaptersByNumber[$chapter->getNumber()] = $this->toChapterDomain($chapter);
|
||||
$chaptersByNumber[(float) $chapter->getNumber()] = $this->toChapterDomain($chapter);
|
||||
}
|
||||
|
||||
return $chaptersByNumber;
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Domain\Scraping\Domain\Contract\Service\ImageDownloaderInterface;
|
||||
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScraped;
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
||||
use App\Domain\Scraping\Domain\Model\Chapter;
|
||||
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
||||
use App\Domain\Scraping\Domain\Model\Source;
|
||||
use App\Domain\Scraping\Domain\Model\ValueObject\CbzGenerationRequest;
|
||||
@@ -41,6 +42,7 @@ readonly class ScrapeChapterHandler
|
||||
$job = null;
|
||||
try {
|
||||
// 1. Récupération du chapitre
|
||||
/**@var Chapter $chapter */
|
||||
$chapter = $this->chapterRepository->getById($command->chapterId);
|
||||
if (!$chapter) {
|
||||
throw new \InvalidArgumentException("Chapter not found with ID: {$command->chapterId}");
|
||||
|
||||
@@ -7,6 +7,9 @@ use App\Domain\Scraping\Domain\Model\Chapter;
|
||||
interface ChapterRepositoryInterface
|
||||
{
|
||||
public function getById(string $id): ?Chapter;
|
||||
public function getByMangaIdAndChapterNumber(string $mangaId, int $chapterNumber): Chapter;
|
||||
/**
|
||||
* @throws ChapterNotFoundException
|
||||
*/
|
||||
public function getByMangaIdAndChapterNumber(string $mangaId, float $chapterNumber): Chapter;
|
||||
public function save(Chapter $chapter): void;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ class Chapter
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly string $mangaId,
|
||||
public readonly int $chapterNumber,
|
||||
public readonly int $volumeNumber,
|
||||
public ?string $cbzPath = null,
|
||||
public readonly float $chapterNumber,
|
||||
public readonly ?int $volumeNumber,
|
||||
public ?string $cbzPath,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -36,23 +36,23 @@ readonly class LegacyChapterRepository implements ChapterRepositoryInterface
|
||||
/**
|
||||
* @throws ChapterNotFoundException
|
||||
*/
|
||||
public function getByMangaIdAndChapterNumber(string $mangaId, int $chapterNumber): Chapter
|
||||
public function getByMangaIdAndChapterNumber(string $mangaId, float $chapterNumber): Chapter
|
||||
{
|
||||
$chapterEntity = $this->entityManager->getRepository(EntityChapter::class)->findOneBy([
|
||||
$entity = $this->entityManager->getRepository(EntityChapter::class)->findOneBy([
|
||||
'manga' => $mangaId,
|
||||
'number' => $chapterNumber,
|
||||
'number' => $chapterNumber
|
||||
]);
|
||||
|
||||
if (!$chapterEntity) {
|
||||
if ($entity === null) {
|
||||
throw new ChapterNotFoundException();
|
||||
}
|
||||
|
||||
return new Chapter(
|
||||
id: $chapterEntity->getId(),
|
||||
mangaId: $chapterEntity->getManga()->getId(),
|
||||
chapterNumber: $chapterEntity->getNumber(),
|
||||
volumeNumber: $chapterEntity->getVolume(),
|
||||
cbzPath: $chapterEntity->getCbzPath(),
|
||||
id: $entity->getId(),
|
||||
mangaId: $entity->getManga()->getId(),
|
||||
chapterNumber: $entity->getNumber(),
|
||||
volumeNumber: $entity->getVolume(),
|
||||
cbzPath: $entity->getCbzPath(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user