feat: scraping endpoints, job persistence, firsts unit tests, legacy entities usage

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-07 11:56:51 +01:00
parent c55cd62ec7
commit 0374ab0e46
34 changed files with 348 additions and 326 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Domain\Scraping\Infrastructure\Persistence;
use App\Domain\Scraping\Domain\Contract\Repository\SourceRepositoryInterface;
use App\Domain\Scraping\Domain\Exception\SourceNotFoundException;
use App\Domain\Scraping\Domain\Model\Source;
use App\Domain\Scraping\Domain\Model\ValueObject\SourceId;
use App\Entity\ContentSource;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
readonly class LegacySourceRepository implements SourceRepositoryInterface
{
public function __construct(
private EntityManagerInterface $entityManager
) {
}
/**
* @throws SourceNotFoundException
*/
public function getById(string $id): Source
{
/** @var ContentSource|null $source */
$source = $this->entityManager->getRepository(ContentSource::class)->find($id);
if (!$source) {
throw new SourceNotFoundException("Source not found");
}
return new Source(
id: new SourceId($source->getId()),
name: $source->getCleanBaseUrl(),
description: 'Legacy Source: ' . $source->getBaseUrl(),
baseUrl: $source->getBaseUrl(),
scrappingParameters: [
'imageSelector' => $source->getImageSelector(),
'nextPageSelector' => $source->getNextPageSelector(),
'chapterUrlFormat' => $source->getChapterUrlFormat(),
'scrapingType' => $source->getScrapingType(),
'chapterSelector' => $source->getChapterSelector()
],
isActive: true,
createdAt: new DateTimeImmutable(),
updatedAt: new DateTimeImmutable()
);
}
}