feat: ajout de la fonctionnalité de récupération des chapitres de manga, avec mise à jour de l'API et des composants pour gérer la récupération asynchrone des chapitres, ainsi que des améliorations dans la gestion des erreurs et des tests associés.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-07-06 16:20:15 +02:00
parent 5a5569cf2c
commit ee2a9b3750
14 changed files with 137 additions and 34 deletions

View File

@@ -5,6 +5,6 @@ namespace App\Domain\Manga\Application\Command;
readonly class FetchMangaChapters
{
public function __construct(
public string $externalId
public string $mangaId
) {}
}
}

View File

@@ -24,7 +24,7 @@ readonly class CreateMangaFromMangadexHandler
public function handle(CreateMangaFromMangadex $command): void
{
$manga = $this->mangaProvider->findByExternalId(new ExternalId($command->externalId));
if ($manga === null) {
throw new MangaNotFoundException('Manga not found on Mangadex');
}
@@ -32,10 +32,10 @@ readonly class CreateMangaFromMangadexHandler
try {
// Télécharge l'image originale
$fullImagePath = $this->imageProcessor->downloadImage($manga->getImageUrl());
// Crée la miniature à partir de l'image originale
$thumbnailPath = $this->imageProcessor->createThumbnail($fullImagePath);
// Met à jour le manga avec les nouveaux chemins d'images
$manga->updateImageUrls(new ImageUrls($fullImagePath, $thumbnailPath));
} catch (\Exception $e) {
@@ -43,7 +43,7 @@ readonly class CreateMangaFromMangadexHandler
}
$this->mangaRepository->save($manga);
$this->messageBus->dispatch(new MangaCreated($command->externalId));
$this->messageBus->dispatch(new MangaCreated($manga->getId()->getValue(), $command->externalId));
}
}
}

View File

@@ -54,7 +54,7 @@ readonly class CreateMangaHandler
$this->mangaRepository->save($manga);
if ($command->externalId) {
$this->messageBus->dispatch(new MangaCreated($command->externalId));
$this->messageBus->dispatch(new MangaCreated($manga->getId()->getValue(), $command->externalId));
}
}
}

View File

@@ -19,12 +19,18 @@ readonly class FetchMangaChaptersHandler
public function handle(FetchMangaChapters $command): void
{
$manga = $this->mangaRepository->findByExternalId(new ExternalId($command->externalId));
$manga = $this->mangaRepository->findById($command->mangaId);
if ($manga === null) {
throw new \RuntimeException('Manga not found');
}
if ($manga->getExternalId() === null) {
throw new \RuntimeException('Manga has no external ID');
}
$externalId = $manga->getExternalId()->getValue();
$offset = 0;
$limit = 500;
$hasMore = true;
@@ -34,7 +40,7 @@ readonly class FetchMangaChaptersHandler
while ($hasMore) {
$feed = $this->mangadexClient->getMangaFeed(
$command->externalId,
$externalId,
$offset,
$limit
);

View File

@@ -5,6 +5,7 @@ namespace App\Domain\Manga\Domain\Event;
readonly class MangaCreated
{
public function __construct(
public string $mangaId,
public string $externalId
) {}
}
}

View File

@@ -8,7 +8,7 @@ use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\CreateMangaProce
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
shortName: 'Manga',
shortName: 'Mangadex',
operations: [
new Post(
uriTemplate: '/mangas/create-from-mangadex',
@@ -40,4 +40,4 @@ class CreateMangaResource
{
#[Assert\NotBlank]
public string $externalId;
}
}

View File

@@ -8,19 +8,53 @@ use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\FetchMangaChapte
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
shortName: 'Chapters',
shortName: 'Mangadex',
operations: [
new Post(
uriTemplate: '/manga/chapters/fetch',
processor: FetchMangaChaptersProcessor::class,
status: 202
status: 202,
description: 'Déclenche la récupération des chapitres d\'un manga',
openapiContext: [
'summary' => 'Récupérer les chapitres d\'un manga',
'description' => 'Lance le processus de récupération des chapitres depuis la source externe pour un manga donné',
'requestBody' => [
'description' => 'Données requises pour récupérer les chapitres',
'required' => true,
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'mangaId' => [
'type' => 'string',
'format' => 'uuid',
'description' => 'L\'identifiant unique du manga',
'example' => '123e4567-e89b-12d3-a456-426614174000'
]
],
'required' => ['mangaId']
]
]
]
],
'responses' => [
'202' => [
'description' => 'Demande de récupération acceptée et mise en file d\'attente'
],
'422' => [
'description' => 'Données de validation invalides'
]
]
]
)
]
)]
class FetchMangaChaptersResource
{
public function __construct(
#[Assert\NotBlank]
public string $externalId
#[Assert\NotBlank(message: 'L\'identifiant du manga est obligatoire')]
#[Assert\Uuid(message: 'L\'identifiant du manga doit être un UUID valide')]
public string $mangaId
) {}
}
}

View File

@@ -21,7 +21,7 @@ readonly class FetchMangaChaptersProcessor implements ProcessorInterface
}
$this->messageBus->dispatch(
new FetchMangaChapters($data->externalId)
new FetchMangaChapters($data->mangaId)
);
}
}
}

View File

@@ -15,7 +15,7 @@ readonly class MangaCreatedListener
public function __invoke(MangaCreated $event): void
{
$this->messageBus->dispatch(
new FetchMangaChapters($event->externalId)
new FetchMangaChapters($event->mangaId)
);
}
}
}