feat: CreateMangaFromMangadex endpoint + tests, missing image saving

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-11 00:10:54 +01:00
parent ae0eac3197
commit 50080f9779
14 changed files with 387 additions and 29 deletions

View File

@@ -55,13 +55,30 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
public function save(DomainManga $manga): void
{
$entity = $this->entityManager->find(EntityManga::class, $manga->getId()->getValue())
?? new EntityManga();
$this->updateEntity($entity, $manga);
$entity = new EntityManga();
$entity->setTitle($manga->getTitle()->getValue())
->setSlug($manga->getSlug()->getValue())
->setDescription($manga->getDescription())
->setAuthor($manga->getAuthor())
->setPublicationYear($manga->getPublicationYear())
->setGenres($manga->getGenres())
->setStatus($manga->getStatus())
->setExternalId($manga->getExternalId()->getValue())
->setImageUrl($manga->getImageUrl())
->setMonitored(false);
if ($manga->getRating() !== null) {
$entity->setRating($manga->getRating());
}
$this->entityManager->persist($entity);
$this->entityManager->flush();
// Met à jour l'ID du modèle du domaine avec l'ID généré par la BDD
if ($entity->getId()) {
$manga->updateId(new MangaId((string) $entity->getId()));
}
}
public function delete(DomainManga $manga): void
@@ -121,29 +138,6 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
);
}
private function updateEntity(EntityManga $entity, DomainManga $manga): void
{
$entity->setTitle($manga->getTitle()->getValue())
->setSlug($manga->getSlug()->getValue())
->setDescription($manga->getDescription())
->setAuthor($manga->getAuthor())
->setPublicationYear($manga->getPublicationYear())
->setGenres($manga->getGenres())
->setStatus($manga->getStatus());
if ($manga->getExternalId()) {
$entity->setExternalId($manga->getExternalId()->getValue());
}
if ($manga->getImageUrl()) {
$entity->setImageUrl($manga->getImageUrl());
}
if ($manga->getRating()) {
$entity->setRating($manga->getRating());
}
}
private function toChapterDomain(EntityChapter $entity): Chapter
{
return new Chapter(