feat: ajout de la gestion des sources préférées pour les mangas, incluant la récupération et la configuration des sources via l'API, ainsi que l'intégration d'une modale pour l'interface utilisateur.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-06-20 15:33:54 +02:00
parent 15d92d1aff
commit 75f8e1686c
22 changed files with 1168 additions and 41 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Domain\Scraping\Infrastructure\Persistence;
use App\Domain\Scraping\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Scraping\Domain\Model\Manga;
use App\Entity\Manga as EntityManga;
use App\Entity\ContentSource;
use Doctrine\ORM\EntityManagerInterface;
readonly class LegacyMangaRepository implements MangaRepositoryInterface
@@ -26,17 +27,49 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
// Récupération des sources préférées
$preferredSourceIds = [];
foreach ($mangaEntity->getPreferredSources() as $source) {
$preferredSourceIds[] = $source->getId();
$preferredSourceIds[] = (string) $source->getId();
}
return new Manga(
$mangaEntity->getId(),
(string) $mangaEntity->getId(),
$mangaEntity->getTitle(),
$mangaEntity->getSlug(),
$mangaEntity->getDescription() ?? '',
$mangaEntity->getAuthor() ?? '',
$mangaEntity->getPublicationYear() ?? '',
(string) ($mangaEntity->getPublicationYear() ?? ''),
$preferredSourceIds,
);
}
public function updatePreferredSources(string $mangaId, array $sourceIds): void
{
/** @var EntityManga|null $mangaEntity */
$mangaEntity = $this->entityManager->getRepository(EntityManga::class)->find($mangaId);
if (!$mangaEntity) {
throw new \InvalidArgumentException("Manga not found with ID: {$mangaId}");
}
// Si pas de sources, vider les sources préférées
if (empty($sourceIds)) {
$mangaEntity->setPreferredSources([]);
$this->entityManager->flush();
return;
}
// Récupérer les sources existantes
$sources = $this->entityManager->getRepository(ContentSource::class)->findBy(['id' => $sourceIds]);
// Maintenir l'ordre exact des sources comme dans l'ancien controller
$orderedPreferredSources = array_map(
fn ($id) => current(array_filter($sources, fn ($s) => $s->getId() == $id)),
$sourceIds
);
// Filtrer les sources nulles (au cas où certaines n'existeraient pas)
$validSources = array_filter($orderedPreferredSources);
$mangaEntity->setPreferredSources($validSources);
$this->entityManager->flush();
}
}