feat: ajout de la gestion des URL d'image et de miniature dans les réponses des mangas, avec mise à jour des classes et des tests associés
This commit is contained in:
parent
6ea24deacf
commit
7051bf5274
@@ -44,6 +44,7 @@ readonly class FetchMangaChaptersHandler
|
||||
$chapterData['attributes']['title'],
|
||||
isset($chapterData['attributes']['volume']) ? (int) $chapterData['attributes']['volume'] : null,
|
||||
true,
|
||||
false,
|
||||
new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ readonly class GetMangaBySlugHandler
|
||||
status: $manga->getStatus(),
|
||||
externalId: $manga->getExternalId()?->getValue(),
|
||||
imageUrl: $manga->getImageUrl(),
|
||||
thumbnailUrl: $manga->getImageUrls()?->getThumbnail(),
|
||||
rating: $manga->getRating()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Domain\Manga\Application\Query\SearchManga;
|
||||
use App\Domain\Manga\Application\Response\MangaSearchItem;
|
||||
use App\Domain\Manga\Application\Response\MangaSearchResponse;
|
||||
use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
|
||||
readonly class SearchMangaHandler
|
||||
{
|
||||
@@ -19,7 +20,8 @@ readonly class SearchMangaHandler
|
||||
|
||||
return new MangaSearchResponse(
|
||||
array_map(
|
||||
fn ($manga) => new MangaSearchItem(
|
||||
fn (Manga$manga) => new MangaSearchItem(
|
||||
id: $manga->getId()->getValue(),
|
||||
externalId: $manga->getExternalId()->getValue(),
|
||||
title: $manga->getTitle()->getValue(),
|
||||
slug: $manga->getSlug()->getValue(),
|
||||
@@ -29,6 +31,7 @@ readonly class SearchMangaHandler
|
||||
genres: $manga->getGenres(),
|
||||
status: $manga->getStatus(),
|
||||
imageUrl: $manga->getImageUrl(),
|
||||
thumbnailUrl: $manga->getImageUrls()?->getThumbnail(),
|
||||
rating: $manga->getRating()
|
||||
),
|
||||
$mangaCollection->getItems()
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Domain\Manga\Application\QueryHandler\GetMangaByIdHandler;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
|
||||
@@ -36,17 +37,19 @@ class GetMangaByIdHandlerTest extends TestCase
|
||||
{
|
||||
// Arrange
|
||||
$manga = new Manga(
|
||||
new MangaId('123'),
|
||||
new MangaTitle('One Piece'),
|
||||
new MangaSlug('one-piece'),
|
||||
'Description test',
|
||||
'Eiichiro Oda',
|
||||
1997,
|
||||
['action', 'adventure'],
|
||||
'ongoing',
|
||||
new ExternalId('external-123'),
|
||||
'http://example.com/image.jpg',
|
||||
4.5
|
||||
id: new MangaId('123'),
|
||||
title: new MangaTitle('One Piece'),
|
||||
slug: new MangaSlug('one-piece'),
|
||||
description: 'Description test',
|
||||
author: 'Eiichiro Oda',
|
||||
publicationYear: 1997,
|
||||
genres: ['action', 'adventure'],
|
||||
status: 'ongoing',
|
||||
externalId: new ExternalId('external-123'),
|
||||
imageUrl: 'http://example.com/image.jpg',
|
||||
rating: 4.5,
|
||||
imageUrls: new ImageUrls('http://example.com/image.jpg', 'http://example.com/thumbnail.jpg'),
|
||||
createdAt: new \DateTimeImmutable()
|
||||
);
|
||||
$this->repository->save($manga);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Domain\Manga\Application\Query\GetMangaBySlug;
|
||||
use App\Domain\Manga\Application\QueryHandler\GetMangaBySlugHandler;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
|
||||
@@ -37,6 +38,8 @@ class GetMangaBySlugHandlerTest extends TestCase
|
||||
status: 'ongoing',
|
||||
externalId: null,
|
||||
imageUrl: 'https://example.com/image.jpg',
|
||||
imageUrls: new ImageUrls('https://example.com/image.jpg', 'https://example.com/thumbnail.jpg'),
|
||||
|
||||
rating: 4.5
|
||||
);
|
||||
$this->repository->save($manga);
|
||||
|
||||
@@ -25,6 +25,7 @@ class GetMangaBySlugTest extends AbstractApiTestCase
|
||||
'genres' => ['Action', 'Adventure'],
|
||||
'status' => 'ongoing',
|
||||
'imageUrl' => 'https://example.com/image.jpg',
|
||||
'thumbnailUrl' => 'https://example.com/thumbnail.jpg',
|
||||
'rating' => 4.5,
|
||||
'monitored' => true
|
||||
]);
|
||||
@@ -44,7 +45,8 @@ class GetMangaBySlugTest extends AbstractApiTestCase
|
||||
'genres' => ['Action', 'Adventure'],
|
||||
'status' => 'ongoing',
|
||||
'imageUrl' => 'https://example.com/image.jpg',
|
||||
'rating' => 4.5
|
||||
'rating' => 4.5,
|
||||
'imageUrl' => 'https://example.com/image.jpg',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,9 @@ class GetMangaListTest extends AbstractApiTestCase
|
||||
->setStatus('ongoing')
|
||||
->setRating(4.5)
|
||||
->setMonitored(false)
|
||||
;
|
||||
->setImageUrl('https://via.placeholder.com/150')
|
||||
->setThumbnailUrl('https://via.placeholder.com/150')
|
||||
->setCreatedAt(new \DateTimeImmutable('2020-01-01'));
|
||||
|
||||
$this->entityManager->persist($manga);
|
||||
$this->entityManager->flush();
|
||||
|
||||
@@ -33,6 +33,7 @@ class GetMangaTest extends AbstractApiTestCase
|
||||
->setStatus('ongoing')
|
||||
->setExternalId('external-123')
|
||||
->setImageUrl('http://example.com/image.jpg')
|
||||
->setThumbnailUrl('http://example.com/thumbnail.jpg')
|
||||
->setRating(4.5)
|
||||
->setMonitored(true);
|
||||
|
||||
|
||||
@@ -63,10 +63,12 @@ class SearchMangaTest extends AbstractApiTestCase
|
||||
|
||||
// Then
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$data = $response->toArray();
|
||||
|
||||
$this->assertCount(2, $data['items']);
|
||||
$titles = array_map(fn($item) => $item['title'], $data['items']);
|
||||
|
||||
$this->assertCount(2, $data['items']['hydra:member']);
|
||||
$titles = array_map(fn($item) => $item['title'], $data['items']['hydra:member']);
|
||||
$this->assertContains('One Piece', $titles);
|
||||
$this->assertContains('One Punch Man', $titles);
|
||||
}
|
||||
@@ -89,9 +91,9 @@ class SearchMangaTest extends AbstractApiTestCase
|
||||
$this->assertResponseIsSuccessful();
|
||||
$data = $response->toArray();
|
||||
|
||||
$this->assertCount(1, $data['items']);
|
||||
$this->assertEquals('Dragon Ball', $data['items'][0]['title']);
|
||||
$this->assertEquals('dragon-ball', $data['items'][0]['slug']);
|
||||
$this->assertCount(1, $data['items']['hydra:member']);
|
||||
$this->assertEquals('Dragon Ball', $data['items']['hydra:member'][0]['title']);
|
||||
$this->assertEquals('dragon-ball', $data['items']['hydra:member'][0]['slug']);
|
||||
}
|
||||
|
||||
// public function testSearchMangaWithPagination(): void
|
||||
@@ -131,7 +133,10 @@ class SearchMangaTest extends AbstractApiTestCase
|
||||
->setGenres(['action'])
|
||||
->setStatus('ongoing')
|
||||
->setRating(4.5)
|
||||
->setMonitored(false);
|
||||
->setMonitored(false)
|
||||
->setImageUrl('https://via.placeholder.com/150')
|
||||
->setThumbnailUrl('https://via.placeholder.com/150')
|
||||
->setCreatedAt(new \DateTimeImmutable('2020-01-01'));
|
||||
|
||||
$this->entityManager->persist($manga);
|
||||
$this->entityManager->flush();
|
||||
|
||||
Reference in New Issue
Block a user