diff --git a/bin/createPipeline.php b/bin/createPipeline.php index 7da7ebd..6faa25e 100644 --- a/bin/createPipeline.php +++ b/bin/createPipeline.php @@ -94,10 +94,7 @@ class {$stepClassName} implements TaskInterface ) { } - public function __invoke( - \$payload, - PipelineInterface \$pipeline - ): void + public function __invoke(\$payload, PipelineInterface \$pipeline): void { /** @var {$payloadClassName} \${$payloadVariableName} */ \${$payloadVariableName} = \$payload; diff --git a/src/ApiDomain/Console/config/console.php b/src/ApiDomain/Console/config/console.php index de724cb..1c9a59c 100644 --- a/src/ApiDomain/Console/config/console.php +++ b/src/ApiDomain/Console/config/console.php @@ -3,11 +3,13 @@ use MyTube\API\Console\Command\AnalyzeVideoTitlesCommand; use MyTube\API\Console\Command\InitializeDataCommand; use MyTube\API\Console\Command\RbacUpdateCommand; +use MyTube\API\Console\Command\ReadUntaggedVideosCommand; return [ 'commands' => [ InitializeDataCommand::class, RbacUpdateCommand::class, AnalyzeVideoTitlesCommand::class, + ReadUntaggedVideosCommand::class, ] ]; diff --git a/src/ApiDomain/Console/config/service_manager.php b/src/ApiDomain/Console/config/service_manager.php index 77e3fcc..6df4f49 100644 --- a/src/ApiDomain/Console/config/service_manager.php +++ b/src/ApiDomain/Console/config/service_manager.php @@ -3,6 +3,7 @@ use MyTube\API\Console\Command\AnalyzeVideoTitlesCommand; use MyTube\API\Console\Command\InitializeDataCommand; use MyTube\API\Console\Command\RbacUpdateCommand; +use MyTube\API\Console\Command\ReadUntaggedVideosCommand; use Reinfi\DependencyInjection\Factory\AutoWiringFactory; return [ @@ -10,5 +11,6 @@ return [ InitializeDataCommand::class => AutoWiringFactory::class, RbacUpdateCommand::class => AutoWiringFactory::class, AnalyzeVideoTitlesCommand::class => AutoWiringFactory::class, + ReadUntaggedVideosCommand::class => AutoWiringFactory::class, ], ]; diff --git a/src/ApiDomain/Console/src/Command/AnalyzeVideoTitlesCommand.php b/src/ApiDomain/Console/src/Command/AnalyzeVideoTitlesCommand.php index e65824f..724f2a6 100644 --- a/src/ApiDomain/Console/src/Command/AnalyzeVideoTitlesCommand.php +++ b/src/ApiDomain/Console/src/Command/AnalyzeVideoTitlesCommand.php @@ -46,7 +46,7 @@ class AnalyzeVideoTitlesCommand extends Command /** @var Tag $match */ foreach ($matches as $match) { - $io->info(sprintf(" - added Tag '%s'", $match->getDescription())); + echo sprintf("Added Tag '%s'", $match->getDescription()); } $this->entityManager->persist($video); diff --git a/src/ApiDomain/Console/src/Command/ReadUntaggedVideosCommand.php b/src/ApiDomain/Console/src/Command/ReadUntaggedVideosCommand.php new file mode 100644 index 0000000..68fb543 --- /dev/null +++ b/src/ApiDomain/Console/src/Command/ReadUntaggedVideosCommand.php @@ -0,0 +1,64 @@ +getName()); + + $this->videoRepository = $this->entityManager->getRepository(Video::class); + } + + protected function execute( + InputInterface $input, + OutputInterface $output + ): int { + $io = new SymfonyStyle($input, $output); + + try { + $qb = $this->videoRepository + ->createQueryBuilder('v') + ->leftJoin('v.tags', 't') + ->groupBy('v.id') + ->having('COUNT(t.id) = 0') + ->orderBy('v.title'); + + $videos = $qb->getQuery()->execute(); + + /** @var Video $video */ + foreach ($videos as $video) { + echo $video->getTitle() . PHP_EOL; + } + + $io->info('total: ' . count($videos)); + + $io->success('OK!'); + } catch (\Throwable $e) { + $io->error($e->getMessage()); + $io->error($e->getTraceAsString()); + $this->logger->error($e->getMessage(), ['exception' => $e]); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +} diff --git a/src/ApiDomain/External/Authentication/src/Handler/ConfirmRegistrationHandler.php b/src/ApiDomain/External/Authentication/src/Handler/ConfirmRegistrationHandler.php index 0aa0f57..46720b1 100644 --- a/src/ApiDomain/External/Authentication/src/Handler/ConfirmRegistrationHandler.php +++ b/src/ApiDomain/External/Authentication/src/Handler/ConfirmRegistrationHandler.php @@ -7,6 +7,7 @@ namespace MyTube\API\External\Authentication\Handler; use MyTube\API\External\User\Formatter\UserFormatter; use MyTube\Handling\Registration\Handler\Command\ConfirmRegistration\ConfirmRegistrationCommandBuilder; use MyTube\Handling\Registration\Handler\Command\ConfirmRegistration\ConfirmRegistrationCommandHandler; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use MyTube\Infrastructure\Session\Middleware\SessionMiddleware; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; @@ -25,10 +26,7 @@ class ConfirmRegistrationHandler implements RequestHandlerInterface public function handle(ServerRequestInterface $request): ResponseInterface { - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( Uuid::fromString($data['id']), diff --git a/src/ApiDomain/External/Authentication/src/Handler/LoginUserHandler.php b/src/ApiDomain/External/Authentication/src/Handler/LoginUserHandler.php index 6ee13b0..04605f5 100644 --- a/src/ApiDomain/External/Authentication/src/Handler/LoginUserHandler.php +++ b/src/ApiDomain/External/Authentication/src/Handler/LoginUserHandler.php @@ -6,6 +6,7 @@ namespace MyTube\API\External\Authentication\Handler; use MyTube\Handling\UserSession\Handler\Command\LoginUser\LoginUserCommandBuilder; use MyTube\Handling\UserSession\Handler\Command\LoginUser\LoginUserCommandHandler; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use MyTube\Infrastructure\Session\Middleware\SessionMiddleware; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; @@ -23,10 +24,7 @@ class LoginUserHandler implements RequestHandlerInterface public function handle(ServerRequestInterface $request): ResponseInterface { $session = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE); - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( $session, diff --git a/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php b/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php index 3ee04ec..4f5a3e2 100644 --- a/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php +++ b/src/ApiDomain/External/Authentication/src/Handler/RegisterUserHandler.php @@ -8,6 +8,7 @@ use MyTube\Handling\Registration\Handler\Command\RegisterUser\RegisterUserComman use MyTube\Handling\Registration\Handler\Command\RegisterUser\RegisterUserCommandHandler; use MyTube\Infrastructure\Exception\Middleware\MyTubeExceptionHandlerMiddleware; use MyTube\Infrastructure\Logging\Logger\Logger; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use MyTube\Infrastructure\Request\Middleware\AnalyzeHeaderMiddleware; use MyTube\Infrastructure\Response\SuccessResponse; use MyTube\Infrastructure\Session\Middleware\SessionMiddleware; @@ -28,10 +29,7 @@ class RegisterUserHandler implements RequestHandlerInterface public function handle(ServerRequestInterface $request): ResponseInterface { $host = $request->getAttribute(AnalyzeHeaderMiddleware::HOST_ATTRIBUTE); - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( $data['username'], diff --git a/src/ApiDomain/External/Tag/config/routes.php b/src/ApiDomain/External/Tag/config/routes.php index e3b172a..a40efa9 100644 --- a/src/ApiDomain/External/Tag/config/routes.php +++ b/src/ApiDomain/External/Tag/config/routes.php @@ -2,6 +2,8 @@ use MyTube\API\External\Tag\Handler\AddAliasHandler; use MyTube\API\External\Tag\Handler\CreateHandler; +use MyTube\API\External\Tag\Handler\ReadDetailsHandler; +use MyTube\API\External\Tag\Handler\ReadVideoListHandler; return [ [ @@ -20,4 +22,20 @@ return [ AddAliasHandler::class, ], ], + [ + 'name' => 'tag.read-details', + 'path' => '/api/tag/read-details[/]', + 'allowed_methods' => ['POST'], + 'middleware' => [ + ReadDetailsHandler::class, + ], + ], + [ + 'name' => 'tag.read-video-list', + 'path' => '/api/tag/read-video-list[/]', + 'allowed_methods' => ['POST'], + 'middleware' => [ + ReadVideoListHandler::class, + ], + ], ]; diff --git a/src/ApiDomain/External/Tag/config/service_manager.php b/src/ApiDomain/External/Tag/config/service_manager.php index 4a6c866..a3ba791 100644 --- a/src/ApiDomain/External/Tag/config/service_manager.php +++ b/src/ApiDomain/External/Tag/config/service_manager.php @@ -2,8 +2,12 @@ use MyTube\API\External\Tag\Handler\AddAliasHandler; use MyTube\API\External\Tag\Handler\CreateHandler; +use MyTube\API\External\Tag\Handler\ReadDetailsHandler; +use MyTube\API\External\Tag\Handler\ReadVideoListHandler; use MyTube\API\External\Tag\ResponseFormatter\AddAliasResponseFormatter; use MyTube\API\External\Tag\ResponseFormatter\CreateResponseFormatter; +use MyTube\API\External\Tag\ResponseFormatter\ReadDetailsResponseFormatter; +use MyTube\API\External\Tag\ResponseFormatter\ReadVideoListResponseFormatter; use Reinfi\DependencyInjection\Factory\AutoWiringFactory; return [ @@ -11,9 +15,13 @@ return [ // Handler AddAliasHandler::class => AutoWiringFactory::class, CreateHandler::class => AutoWiringFactory::class, + ReadDetailsHandler::class => AutoWiringFactory::class, + ReadVideoListHandler::class => AutoWiringFactory::class, // Response Formatter AddAliasResponseFormatter::class => AutoWiringFactory::class, CreateResponseFormatter::class => AutoWiringFactory::class, + ReadDetailsResponseFormatter::class => AutoWiringFactory::class, + ReadVideoListResponseFormatter::class => AutoWiringFactory::class, ], ]; diff --git a/src/ApiDomain/External/Tag/src/Handler/AddAliasHandler.php b/src/ApiDomain/External/Tag/src/Handler/AddAliasHandler.php index 06937ed..879809d 100644 --- a/src/ApiDomain/External/Tag/src/Handler/AddAliasHandler.php +++ b/src/ApiDomain/External/Tag/src/Handler/AddAliasHandler.php @@ -9,6 +9,7 @@ use MyTube\Handling\Tag\Exception\TagNotFoundByIdException; use MyTube\Handling\Tag\Handler\Command\AddAlias\AddAliasCommandHandler; use MyTube\Handling\Tag\Handler\Command\AddAlias\AddAliasCommandBuilder; use MyTube\API\External\Tag\ResponseFormatter\AddAliasResponseFormatter; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -30,10 +31,7 @@ class AddAliasHandler implements RequestHandlerInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $addAliasCommand = $this->addAliasCommandBuilder->build( Uuid::fromString($data['tagId']), diff --git a/src/ApiDomain/External/Tag/src/Handler/CreateHandler.php b/src/ApiDomain/External/Tag/src/Handler/CreateHandler.php index 1bac6c9..20b4550 100644 --- a/src/ApiDomain/External/Tag/src/Handler/CreateHandler.php +++ b/src/ApiDomain/External/Tag/src/Handler/CreateHandler.php @@ -8,6 +8,7 @@ use MyTube\Handling\Tag\Exception\TagAlreadyExistsException; use MyTube\Handling\Tag\Handler\Command\Create\CreateCommandHandler; use MyTube\Handling\Tag\Handler\Command\Create\CreateCommandBuilder; use MyTube\API\External\Tag\ResponseFormatter\CreateResponseFormatter; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -27,10 +28,7 @@ class CreateHandler implements RequestHandlerInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $createCommand = $this->createCommandBuilder->build( $data['description'] diff --git a/src/ApiDomain/External/Tag/src/Handler/ReadDetailsHandler.php b/src/ApiDomain/External/Tag/src/Handler/ReadDetailsHandler.php new file mode 100644 index 0000000..1b6dc03 --- /dev/null +++ b/src/ApiDomain/External/Tag/src/Handler/ReadDetailsHandler.php @@ -0,0 +1,41 @@ +getAttribute(AnalyzeBodyMiddleware::JSON_DATA); + + $readDetailsQuery = $this->readDetailsQueryBuilder->build( + Uuid::fromString($data['tagId']), + ); + $result = $this->readDetailsQueryHandler->execute($readDetailsQuery); + + return new SuccessResponse($this->responseFormatter->format($result)); + } +} diff --git a/src/ApiDomain/External/Tag/src/Handler/ReadVideoListHandler.php b/src/ApiDomain/External/Tag/src/Handler/ReadVideoListHandler.php new file mode 100644 index 0000000..3960aa7 --- /dev/null +++ b/src/ApiDomain/External/Tag/src/Handler/ReadVideoListHandler.php @@ -0,0 +1,40 @@ +getAttribute(AnalyzeBodyMiddleware::JSON_DATA); + + $readVideoListQuery = $this->readVideoListQueryBuilder->build( + Uuid::fromString($data['tagId']), + $data['query'] ?? null, + $data['page'], + $data['perPage'], + ); + $result = $this->readVideoListQueryHandler->execute($readVideoListQuery); + + return new SuccessResponse($this->responseFormatter->format($result)); + } +} diff --git a/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadDetailsResponseFormatter.php b/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadDetailsResponseFormatter.php new file mode 100644 index 0000000..36f9553 --- /dev/null +++ b/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadDetailsResponseFormatter.php @@ -0,0 +1,29 @@ +getTag(); + + $aliases = []; + + /** @var TagAlias $alias */ + foreach ($tag->getAliases() as $alias) { + $aliases[] = $alias->getDescription(); + } + + return [ + 'id' => $tag->getId()->toString(), + 'description' => $tag->getDescription(), + 'aliases' => $aliases + ]; + } +} diff --git a/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadVideoListResponseFormatter.php b/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadVideoListResponseFormatter.php new file mode 100644 index 0000000..aecd149 --- /dev/null +++ b/src/ApiDomain/External/Tag/src/ResponseFormatter/ReadVideoListResponseFormatter.php @@ -0,0 +1,44 @@ +getPaginator(); + $videos = $paginator->getIterator(); + + $items = []; + + /** @var Video $video */ + foreach ($videos as $video) { + $tags = []; + + /** @var Tag $tag */ + foreach ($video->getTags() as $tag) { + $tags[] = [ + 'id' => $tag->getId(), + 'description' => $tag->getDescription() + ]; + } + + $items[] = [ + 'title' => $video->getTitle(), + 'id' => $video->getId(), + 'tags' => $tags + ]; + } + + return [ + 'total' => $paginator->count(), + 'items' => $items, + ]; + } +} diff --git a/src/ApiDomain/External/TagList/src/Handler/ReadListHandler.php b/src/ApiDomain/External/TagList/src/Handler/ReadListHandler.php index 030e155..77fbd5a 100644 --- a/src/ApiDomain/External/TagList/src/Handler/ReadListHandler.php +++ b/src/ApiDomain/External/TagList/src/Handler/ReadListHandler.php @@ -28,8 +28,6 @@ class ReadListHandler implements RequestHandlerInterface $readListQuery = $this->readListQueryBuilder->build( $data['query'] ?? null, - $data['page'], - $data['perPage'], ); $result = $this->readListQueryHandler->execute($readListQuery); diff --git a/src/ApiDomain/External/TagList/src/ResponseFormatter/ReadListResponseFormatter.php b/src/ApiDomain/External/TagList/src/ResponseFormatter/ReadListResponseFormatter.php index 55c3a5c..a21103b 100644 --- a/src/ApiDomain/External/TagList/src/ResponseFormatter/ReadListResponseFormatter.php +++ b/src/ApiDomain/External/TagList/src/ResponseFormatter/ReadListResponseFormatter.php @@ -11,9 +11,7 @@ class ReadListResponseFormatter { public function format(ReadListQueryResult $readListQueryResult): array { - $paginator = $readListQueryResult->getPaginator(); - $tags = $paginator->getIterator(); - + $tags = $readListQueryResult->getItems(); $items = []; /** @var Tag $tag */ @@ -25,7 +23,7 @@ class ReadListResponseFormatter } return [ - 'total' => $paginator->count(), + 'total' => count($items), 'items' => $items, ]; } diff --git a/src/ApiDomain/External/User/src/Handler/ChangePasswordHandler.php b/src/ApiDomain/External/User/src/Handler/ChangePasswordHandler.php index be832b7..0e8c7ba 100644 --- a/src/ApiDomain/External/User/src/Handler/ChangePasswordHandler.php +++ b/src/ApiDomain/External/User/src/Handler/ChangePasswordHandler.php @@ -26,10 +26,7 @@ class ChangePasswordHandler implements RequestHandlerInterface /** @var User $user */ $user = $request->getAttribute(LoggedInUserMiddleware::USER_KEY); - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( $user, diff --git a/src/ApiDomain/External/User/src/Handler/ChangeUsernameHandler.php b/src/ApiDomain/External/User/src/Handler/ChangeUsernameHandler.php index 23f5d77..f4498b5 100644 --- a/src/ApiDomain/External/User/src/Handler/ChangeUsernameHandler.php +++ b/src/ApiDomain/External/User/src/Handler/ChangeUsernameHandler.php @@ -7,6 +7,7 @@ namespace MyTube\API\External\User\Handler; use MyTube\Data\Business\Entity\User; use MyTube\Handling\User\Handler\Command\ChangeUsername\ChangeUsernameCommandBuilder; use MyTube\Handling\User\Handler\Command\ChangeUsername\ChangeUsernameCommandHandler; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use MyTube\Infrastructure\Response\SuccessResponse; use MyTube\Infrastructure\Session\Middleware\LoggedInUserMiddleware; use Psr\Http\Message\ResponseInterface; @@ -25,11 +26,7 @@ class ChangeUsernameHandler implements RequestHandlerInterface { /** @var User $user */ $user = $request->getAttribute(LoggedInUserMiddleware::USER_KEY); - - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( $user, diff --git a/src/ApiDomain/External/User/src/Handler/CreateUserHandler.php b/src/ApiDomain/External/User/src/Handler/CreateUserHandler.php index f16389a..b9a09a5 100644 --- a/src/ApiDomain/External/User/src/Handler/CreateUserHandler.php +++ b/src/ApiDomain/External/User/src/Handler/CreateUserHandler.php @@ -8,6 +8,7 @@ use MyTube\API\External\User\Formatter\UserFormatter; use MyTube\Handling\User\Handler\Command\CreateUser\CreateUserCommandBuilder; use MyTube\Handling\User\Handler\Command\CreateUser\CreateUserCommandHandler; use Laminas\Diactoros\Response\JsonResponse; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -23,10 +24,7 @@ class CreateUserHandler implements RequestHandlerInterface public function handle(ServerRequestInterface $request): ResponseInterface { - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $query = $this->builder->build( $data['username'], diff --git a/src/ApiDomain/External/Video/src/Handler/ReadDetailsHandler.php b/src/ApiDomain/External/Video/src/Handler/ReadDetailsHandler.php index 5e70b95..198dd83 100644 --- a/src/ApiDomain/External/Video/src/Handler/ReadDetailsHandler.php +++ b/src/ApiDomain/External/Video/src/Handler/ReadDetailsHandler.php @@ -8,6 +8,7 @@ use MyTube\Handling\Video\Exception\VideoNotFoundByIdException; use MyTube\Handling\Video\Handler\Query\ReadDetails\ReadDetailsQueryHandler; use MyTube\Handling\Video\Handler\Query\ReadDetails\ReadDetailsQueryBuilder; use MyTube\API\External\Video\ResponseFormatter\ReadDetailsResponseFormatter; +use MyTube\Infrastructure\Request\Middleware\AnalyzeBodyMiddleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -28,10 +29,7 @@ class ReadDetailsHandler implements RequestHandlerInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { - $data = json_decode( - $request->getBody()->getContents(), - true - ); + $data = $request->getAttribute(AnalyzeBodyMiddleware::JSON_DATA); $readDetailsQuery = $this->readDetailsQueryBuilder->build( Uuid::fromString($data['videoId']) diff --git a/src/ApiDomain/External/Video/src/ResponseFormatter/ReadDetailsResponseFormatter.php b/src/ApiDomain/External/Video/src/ResponseFormatter/ReadDetailsResponseFormatter.php index c3e11af..bfd0b76 100644 --- a/src/ApiDomain/External/Video/src/ResponseFormatter/ReadDetailsResponseFormatter.php +++ b/src/ApiDomain/External/Video/src/ResponseFormatter/ReadDetailsResponseFormatter.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace MyTube\API\External\Video\ResponseFormatter; +use MyTube\Data\Business\Entity\Tag; use MyTube\Handling\Video\Handler\Query\ReadDetails\ReadDetailsQueryResult; class ReadDetailsResponseFormatter @@ -12,9 +13,20 @@ class ReadDetailsResponseFormatter { $video = $readDetailsQueryResult->getVideo(); + $tags = []; + + /** @var Tag $tag */ + foreach ($video->getTags() as $tag) { + $tags = [ + 'id' => $tag->getId(), + 'description' => $tag->getDescription(), + ]; + } + return [ 'id' => $video->getId(), - 'title' => $video->getTitle() + 'title' => $video->getTitle(), + 'tags' => $tags, ]; } } diff --git a/src/ApiDomain/External/VideoList/src/ResponseFormatter/ReadListResponseFormatter.php b/src/ApiDomain/External/VideoList/src/ResponseFormatter/ReadListResponseFormatter.php index d31ef84..bb8202f 100644 --- a/src/ApiDomain/External/VideoList/src/ResponseFormatter/ReadListResponseFormatter.php +++ b/src/ApiDomain/External/VideoList/src/ResponseFormatter/ReadListResponseFormatter.php @@ -23,12 +23,15 @@ class ReadListResponseFormatter /** @var Tag $tag */ foreach ($video->getTags() as $tag) { - $tags[] = $tag->getDescription(); + $tags[] = [ + 'id' => $tag->getId(), + 'description' => $tag->getDescription() + ]; } $items[] = [ 'title' => $video->getTitle(), - 'id' => $video->getId()->toString(), + 'id' => $video->getId(), 'tags' => $tags ]; } diff --git a/src/DataDomain/Business/src/Repository/TagRepository.php b/src/DataDomain/Business/src/Repository/TagRepository.php index d3212aa..11887a2 100644 --- a/src/DataDomain/Business/src/Repository/TagRepository.php +++ b/src/DataDomain/Business/src/Repository/TagRepository.php @@ -3,14 +3,11 @@ namespace MyTube\Data\Business\Repository; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Tools\Pagination\Paginator; class TagRepository extends EntityRepository { public function findByFilter( ?string $query, - int $page, - int $perPage, - ): Paginator + ): array { $queryBuilder = $this->createQueryBuilder('t'); @@ -22,9 +19,6 @@ class TagRepository extends EntityRepository { ->setParameter('query', $query); } - $queryBuilder->setFirstResult($perPage * ($page - 1)); - $queryBuilder->setMaxResults($perPage); - - return new Paginator($queryBuilder->getQuery()); + return $queryBuilder->getQuery()->execute(); } } \ No newline at end of file diff --git a/src/DataDomain/Business/src/Repository/VideoRepository.php b/src/DataDomain/Business/src/Repository/VideoRepository.php index 09b73b1..2a33ba9 100644 --- a/src/DataDomain/Business/src/Repository/VideoRepository.php +++ b/src/DataDomain/Business/src/Repository/VideoRepository.php @@ -5,12 +5,15 @@ namespace MyTube\Data\Business\Repository; use Doctrine\ORM\Tools\Pagination\Paginator; use MyTube\Data\Business\Entity\Registration; use Doctrine\ORM\EntityRepository; +use MyTube\Data\Business\Entity\Tag; +use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType; class VideoRepository extends EntityRepository { public function findByFilter( ?string $query, int $page, int $perPage, + ?Tag $tag = null, ): Paginator { $queryBuilder = $this->createQueryBuilder('v'); @@ -23,6 +26,13 @@ class VideoRepository extends EntityRepository { ->setParameter('query', $query); } + if ($tag !== null) { + $queryBuilder + ->join('v.tags', 't') + ->andWhere('t.id = :tagId') + ->setParameter('tagId', $tag->getId(), UuidBinaryOrderedTimeType::NAME); + } + $queryBuilder->setFirstResult($perPage * ($page - 1)); $queryBuilder->setMaxResults($perPage); diff --git a/src/HandlingDomain/Tag/config/service_manager.php b/src/HandlingDomain/Tag/config/service_manager.php index b847c98..3ae517f 100644 --- a/src/HandlingDomain/Tag/config/service_manager.php +++ b/src/HandlingDomain/Tag/config/service_manager.php @@ -6,6 +6,10 @@ use MyTube\Handling\Tag\Handler\Command\AddAlias\AddAliasCommandBuilder; use MyTube\Handling\Tag\Handler\Command\AddAlias\AddAliasCommandHandler; use MyTube\Handling\Tag\Handler\Command\Create\CreateCommandBuilder; use MyTube\Handling\Tag\Handler\Command\Create\CreateCommandHandler; +use MyTube\Handling\Tag\Handler\Query\ReadDetails\ReadDetailsQueryBuilder; +use MyTube\Handling\Tag\Handler\Query\ReadDetails\ReadDetailsQueryHandler; +use MyTube\Handling\Tag\Handler\Query\ReadVideoList\ReadVideoListQueryBuilder; +use MyTube\Handling\Tag\Handler\Query\ReadVideoList\ReadVideoListQueryHandler; use MyTube\Handling\Tag\Rule\TagAliasExistsRule; use MyTube\Handling\Tag\Rule\TagExistsRule; use Reinfi\DependencyInjection\Factory\AutoWiringFactory; @@ -30,5 +34,11 @@ return [ // Create CreateCommandBuilder::class => AutoWiringFactory::class, CreateCommandHandler::class => AutoWiringFactory::class, + // Read Details + ReadDetailsQueryBuilder::class => AutoWiringFactory::class, + ReadDetailsQueryHandler::class => InjectionFactory::class, + // Read Video List + ReadVideoListQueryBuilder::class => AutoWiringFactory::class, + ReadVideoListQueryHandler::class => InjectionFactory::class, ], ]; diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQuery.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQuery.php new file mode 100644 index 0000000..8cf29e1 --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQuery.php @@ -0,0 +1,20 @@ +tagId; + } +} diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryBuilder.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryBuilder.php new file mode 100644 index 0000000..d3ee7ca --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryBuilder.php @@ -0,0 +1,18 @@ +getTagId(); + + $tag = $this->tagRepository->findOneBy(['id' => $tagId]); + + if ($tag === null) { + throw new TagNotFoundByIdException($tagId); + } + + return new ReadDetailsQueryResult($tag); + } +} diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryResult.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryResult.php new file mode 100644 index 0000000..62b6b07 --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadDetails/ReadDetailsQueryResult.php @@ -0,0 +1,20 @@ +tag; + } +} diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQuery.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQuery.php new file mode 100644 index 0000000..d1e1bd3 --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQuery.php @@ -0,0 +1,38 @@ +tagId; + } + + public function getQuery(): ?string + { + return $this->query; + } + + public function getPage(): int + { + return $this->page; + } + + public function getPerPage(): int + { + return $this->perPage; + } +} diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryBuilder.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryBuilder.php new file mode 100644 index 0000000..5bddd32 --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryBuilder.php @@ -0,0 +1,24 @@ +getTagId(); + + $tag = $this->tagRepository->findOneBy(['id' => $tagId]); + if ($tag === null) { + throw new TagNotFoundByIdException($tagId); + } + + return new ReadVideoListQueryResult( + $this->videoRepository->findByFilter( + query: $readVideoListQuery->getQuery(), + page: $readVideoListQuery->getPage(), + perPage: $readVideoListQuery->getPerPage(), + tag: $tag + ) + ); + } +} diff --git a/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryResult.php b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryResult.php new file mode 100644 index 0000000..6bd75c6 --- /dev/null +++ b/src/HandlingDomain/Tag/src/Handler/Query/ReadVideoList/ReadVideoListQueryResult.php @@ -0,0 +1,20 @@ +paginator; + } +} diff --git a/src/HandlingDomain/TagList/config/service_manager.php b/src/HandlingDomain/TagList/config/service_manager.php index c1f936e..7b8cc39 100644 --- a/src/HandlingDomain/TagList/config/service_manager.php +++ b/src/HandlingDomain/TagList/config/service_manager.php @@ -12,6 +12,6 @@ return [ /// CQRS // ReadList ReadListQueryBuilder::class => AutoWiringFactory::class, - ReadListQueryHandler::class => AutoWiringFactory::class, + ReadListQueryHandler::class => InjectionFactory::class, ], ]; diff --git a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQuery.php b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQuery.php index 10c97de..34b011e 100644 --- a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQuery.php +++ b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQuery.php @@ -8,8 +8,6 @@ class ReadListQuery { public function __construct( private readonly ?string $query, - private readonly int $page, - private readonly int $perPage, ) { } @@ -17,14 +15,4 @@ class ReadListQuery { return $this->query; } - - public function getPage(): int - { - return $this->page; - } - - public function getPerPage(): int - { - return $this->perPage; - } } diff --git a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryBuilder.php b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryBuilder.php index fe7e4a9..c56d449 100644 --- a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryBuilder.php +++ b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryBuilder.php @@ -8,13 +8,9 @@ class ReadListQueryBuilder { public function build( ?string $query, - int $page, - int $perPage, ): ReadListQuery { return new ReadListQuery( $query, - $page, - $perPage, ); } } diff --git a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryHandler.php b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryHandler.php index 86ca00a..1a70ce6 100644 --- a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryHandler.php +++ b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryHandler.php @@ -25,8 +25,6 @@ class ReadListQueryHandler return new ReadListQueryResult( $this->tagRepository->findByFilter( $readListQuery->getQuery(), - $readListQuery->getPage(), - $readListQuery->getPerPage() ) ); } diff --git a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryResult.php b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryResult.php index 446e9d6..5a2d4c8 100644 --- a/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryResult.php +++ b/src/HandlingDomain/TagList/src/Handler/Query/ReadList/ReadListQueryResult.php @@ -4,17 +4,15 @@ declare(strict_types=1); namespace MyTube\Handling\TagList\Handler\Query\ReadList; -use Doctrine\ORM\Tools\Pagination\Paginator; - class ReadListQueryResult { public function __construct( - private readonly Paginator $paginator + private readonly array $items ) { } - public function getPaginator(): Paginator + public function getItems(): array { - return $this->paginator; + return $this->items; } } diff --git a/src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryHandler.php b/src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryHandler.php index 423d051..e21274a 100644 --- a/src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryHandler.php +++ b/src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryHandler.php @@ -24,9 +24,9 @@ class ReadListQueryHandler { return new ReadListQueryResult( $this->videoRepository->findByFilter( - $readListQuery->getQuery(), - $readListQuery->getPage(), - $readListQuery->getPerPage() + query: $readListQuery->getQuery(), + page: $readListQuery->getPage(), + perPage: $readListQuery->getPerPage() ) ); }