feat: ajout de la gestion des sources de contenu avec des commandes et des gestionnaires pour l'importation, la mise à jour et l'exportation, ainsi que la création des ressources API correspondantes.
This commit is contained in:
parent
ebcca466a9
commit
32b4e4fbb2
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Application\CommandHandler;
|
||||
|
||||
use App\Domain\Setting\Application\Command\UpsertContentSourceCommand;
|
||||
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
|
||||
use App\Domain\Setting\Domain\Model\ContentSource;
|
||||
|
||||
readonly class UpsertContentSourceCommandHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ContentSourceRepositoryInterface $contentSourceRepository
|
||||
) {}
|
||||
|
||||
public function handle(UpsertContentSourceCommand $command): void
|
||||
{
|
||||
if ($command->id) {
|
||||
// Update existing
|
||||
$contentSource = $this->contentSourceRepository->findById($command->id);
|
||||
if ($contentSource) {
|
||||
$contentSource->update(
|
||||
baseUrl: $command->baseUrl,
|
||||
chapterUrlFormat: $command->chapterUrlFormat,
|
||||
scrapingType: $command->scrapingType,
|
||||
imageSelector: $command->imageSelector,
|
||||
nextPageSelector: $command->nextPageSelector,
|
||||
chapterSelector: $command->chapterSelector,
|
||||
);
|
||||
$this->contentSourceRepository->save($contentSource);
|
||||
}
|
||||
} else {
|
||||
// Create new
|
||||
$contentSource = ContentSource::create(
|
||||
baseUrl: $command->baseUrl,
|
||||
chapterUrlFormat: $command->chapterUrlFormat,
|
||||
scrapingType: $command->scrapingType,
|
||||
imageSelector: $command->imageSelector,
|
||||
nextPageSelector: $command->nextPageSelector,
|
||||
chapterSelector: $command->chapterSelector,
|
||||
);
|
||||
$this->contentSourceRepository->save($contentSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user