feat: Reader beginning

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-16 16:15:42 +01:00
parent e90c0a140e
commit 55945adc53
37 changed files with 1057 additions and 47 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Domain\Scraping\Application\CommandHandler;
use App\Domain\Scraping\Application\Command\ScrapeChapter;
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
use App\Domain\Scraping\Domain\Contract\Repository\ScrapingJobRepositoryInterface;
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
use App\Domain\Scraping\Domain\Event\ChapterScraped;
@@ -18,6 +19,7 @@ readonly class ScrapeChapterHandler
public function __construct(
private ScraperInterface $scraper,
private ScrapingJobRepositoryInterface $scrapingJobRepository,
private ChapterRepositoryInterface $chapterRepository,
private MessageBusInterface $eventBus
) {
}
@@ -42,6 +44,9 @@ readonly class ScrapeChapterHandler
$this->eventBus->dispatch(new ChapterScrapingFailed($command->mangaId, $command->chapterNumber, $job->failureReason));
}elseif ($job->status === ScrapingStatus::COMPLETED) {
$this->eventBus->dispatch(new ChapterScraped($job->getId()));
$chapter = $this->chapterRepository->getByMangaIdAndChapterNumber($command->mangaId, $command->chapterNumber);
$chapter->cbzPath = $job->cbzPath->getPath();
$this->chapterRepository->save($chapter);
}
$this->scrapingJobRepository->save($job);

View File

@@ -7,4 +7,5 @@ use App\Domain\Scraping\Domain\Model\Chapter;
interface ChapterRepositoryInterface
{
public function getByMangaIdAndChapterNumber(string $mangaId, int $chapterNumber): Chapter;
}
public function save(Chapter $chapter): void;
}

View File

@@ -9,5 +9,6 @@ class Chapter
public readonly string $mangaId,
public readonly int $chapterNumber,
public readonly int $volumeNumber,
public ?string $cbzPath = null,
) {}
}
}

View File

@@ -2,17 +2,16 @@
namespace App\Domain\Scraping\Domain\Model\ValueObject;
class CbzPath
readonly class CbzPath
{
public function __construct(private readonly string $path)
public function __construct(private string $path)
{
if (empty($path)) {
throw new \InvalidArgumentException('Le chemin du fichier CBZ ne peut pas être vide');
}
}
public function getPath(): string
{
return $this->path;
}
}
}

View File

@@ -21,15 +21,15 @@ use Symfony\Component\Validator\Constraints as Assert;
readonly class ScrapeChapterRequest
{
public function __construct(
#[ApiProperty(description: 'ID du chapitre à scraper')]
#[Assert\NotBlank]
public string $chapterId,
#[ApiProperty(description: 'ID de la source à utiliser')]
#[Assert\NotBlank]
public string $sourceId,
#[ApiProperty(description: 'ID du manga')]
#[Assert\NotBlank]
public string $mangaId,
#[ApiProperty(description: 'Numéro du chapitre')]
#[Assert\NotBlank]
public string $chapterNumber,
#[ApiProperty(description: 'ID de la source')]
#[Assert\NotBlank]
public string $sourceId,
) {
}
}

View File

@@ -22,9 +22,9 @@ final class ScrapeChapterStateProcessor implements ProcessorInterface
{
$this->commandBus->dispatch(
new ScrapeChapter(
$data->chapterId,
$data->sourceId,
$data->mangaId
$data->mangaId,
$data->chapterNumber,
$data->sourceId
)
);
}

View File

@@ -7,12 +7,15 @@ use App\Domain\Scraping\Domain\Exception\ChapterNotFoundException;
use App\Domain\Scraping\Domain\Model\Chapter;
use App\Entity\Chapter as EntityChapter;
use Doctrine\ORM\EntityManagerInterface;
class LegacyChapterRepository implements ChapterRepositoryInterface
readonly class LegacyChapterRepository implements ChapterRepositoryInterface
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private EntityManagerInterface $entityManager,
) {}
/**
* @throws ChapterNotFoundException
*/
public function getByMangaIdAndChapterNumber(string $mangaId, int $chapterNumber): Chapter
{
$chapterEntity = $this->entityManager->getRepository(EntityChapter::class)->findOneBy([
@@ -31,4 +34,23 @@ class LegacyChapterRepository implements ChapterRepositoryInterface
volumeNumber: $chapterEntity->getVolume(),
);
}
/**
* @throws ChapterNotFoundException
*/
public function save(Chapter $chapter): void
{
$chapterEntity = $this->entityManager->getRepository(EntityChapter::class)->findOneBy([
'id' => $chapter->id,
]);
if (!$chapterEntity) {
throw new ChapterNotFoundException();
}
$chapterEntity->setCbzPath($chapter->cbzPath);
$this->entityManager->persist($chapterEntity);
$this->entityManager->flush();
}
}