feat: ajout de la gestion des sources de contenu avec création de composants, formulaires et API pour l'importation, l'exportation et la configuration des sources de scraping.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-06-27 16:40:48 +02:00
parent 32b4e4fbb2
commit dac2f91998
15 changed files with 1364 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ use ApiPlatform\Metadata\Get;
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider\ExportContentSourceStateProvider;
#[ApiResource(
shortName: 'ContentSourceExport',
shortName: 'ContentSource',
operations: [
new Get(
uriTemplate: '/content-sources/export',

View File

@@ -8,7 +8,7 @@ use App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor\ImportContentS
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
shortName: 'ContentSourceImport',
shortName: 'ContentSource',
operations: [
new Post(
uriTemplate: '/content-sources/import',

View File

@@ -6,6 +6,7 @@ use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor\UpsertContentSourceStateProcessor;
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider\GetContentSourceStateProvider;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
@@ -20,6 +21,7 @@ use Symfony\Component\Validator\Constraints as Assert;
),
new Put(
uriTemplate: '/content-sources/{id}',
provider: GetContentSourceStateProvider::class,
processor: UpsertContentSourceStateProcessor::class,
input: UpsertContentSourceResource::class,
description: 'Met à jour une source de contenu existante'

View File

@@ -33,4 +33,16 @@ readonly class ContentSourceMapper
return $entity;
}
public function updateEntity(ContentSourceEntity $entity, ContentSource $contentSource): ContentSourceEntity
{
$entity->setBaseUrl($contentSource->getBaseUrl())
->setChapterUrlFormat($contentSource->getChapterUrlFormat())
->setScrapingType($contentSource->getScrapingType())
->setImageSelector($contentSource->getImageSelector())
->setNextPageSelector($contentSource->getNextPageSelector())
->setChapterSelector($contentSource->getChapterSelector());
return $entity;
}
}

View File

@@ -34,14 +34,24 @@ readonly class DoctrineContentSourceRepository implements ContentSourceRepositor
public function save(ContentSource $contentSource): void
{
$entity = $this->mapper->toEntity($contentSource);
if ($contentSource->getId()) {
// Update existing entity
$entity = $this->entityManager->find(ContentSourceEntity::class, $contentSource->getId());
if ($entity) {
// Update existing entity with new values
$this->mapper->updateEntity($entity, $contentSource);
$this->entityManager->flush();
}
} else {
// Create new entity
$entity = $this->mapper->toEntity($contentSource);
$this->entityManager->persist($entity);
$this->entityManager->flush();
$this->entityManager->persist($entity);
$this->entityManager->flush();
// Met à jour l'ID du modèle du domaine si nécessaire
if ($entity->getId() && $contentSource->getId() === null) {
$contentSource->updateId($entity->getId());
// Met à jour l'ID du modèle du domaine
if ($entity->getId()) {
$contentSource->updateId($entity->getId());
}
}
}