feat: GetChapters endpoint + tests
This commit is contained in:
parent
2f615a4936
commit
6667cc224b
@@ -10,6 +10,9 @@ use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
|
||||
use App\Entity\Manga as EntityManga;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Domain\Manga\Domain\Model\Chapter;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
|
||||
use App\Entity\Chapter as EntityChapter;
|
||||
|
||||
readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
{
|
||||
@@ -71,6 +74,36 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function findChapters(string $mangaId, int $page = 1, int $limit = 20, string $sortOrder = 'desc'): array
|
||||
{
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$queryBuilder = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(EntityChapter::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->orderBy('c.number', $sortOrder)
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($limit);
|
||||
|
||||
return array_map(
|
||||
fn (EntityChapter $entity) => $this->toChapterDomain($entity),
|
||||
$queryBuilder->getQuery()->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function countChapters(string $mangaId): int
|
||||
{
|
||||
return $this->entityManager->createQueryBuilder()
|
||||
->select('COUNT(c.id)')
|
||||
->from(EntityChapter::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
private function toDomain(EntityManga $entity): DomainManga
|
||||
{
|
||||
return new DomainManga(
|
||||
@@ -110,4 +143,17 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
$entity->setRating($manga->getRating());
|
||||
}
|
||||
}
|
||||
|
||||
private function toChapterDomain(EntityChapter $entity): Chapter
|
||||
{
|
||||
return new Chapter(
|
||||
id: new ChapterId((string)$entity->getId()),
|
||||
mangaId: $entity->getManga()->getId(),
|
||||
number: $entity->getNumber(),
|
||||
title: $entity->getTitle(),
|
||||
volume: $entity->getVolume(),
|
||||
isVisible: $entity->isVisible(),
|
||||
createdAt: new \DateTimeImmutable()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user