From b42981b2a1c69daf454872c59a8f2ee356729044 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Sun, 13 Jul 2025 21:27:54 -0500 Subject: [PATCH] chore: cleanup --- src/Base/Service/MediaFiles.php | 2 +- ...chCommand.php => LibrarySearchCommand.php} | 2 +- ...chHandler.php => LibrarySearchHandler.php} | 21 ++++++++----------- ...SearchInput.php => LibrarySearchInput.php} | 8 +++---- ...archResult.php => LibrarySearchResult.php} | 8 +++---- src/Library/Framework/Controller/Api.php | 10 ++++----- .../Action/Handler/GetMediaInfoHandler.php | 1 - templates/search/fragments.html.twig | 6 +++--- 8 files changed, 27 insertions(+), 31 deletions(-) rename src/Library/Action/Command/{SearchCommand.php => LibrarySearchCommand.php} (86%) rename src/Library/Action/Handler/{SearchHandler.php => LibrarySearchHandler.php} (72%) rename src/Library/Action/Input/{SearchInput.php => LibrarySearchInput.php} (81%) rename src/Library/Action/Result/{SearchResult.php => LibrarySearchResult.php} (52%) diff --git a/src/Base/Service/MediaFiles.php b/src/Base/Service/MediaFiles.php index c8bc847..7f80971 100644 --- a/src/Base/Service/MediaFiles.php +++ b/src/Base/Service/MediaFiles.php @@ -140,7 +140,7 @@ class MediaFiles return $path; } - public function episodeExists(string $tvshowTitle, int $seasonNumber, int $episodeNumber) + public function episodeExists(string $tvshowTitle, int $seasonNumber, int $episodeNumber): SplFileInfo|false { $existingEpisodes = $this->getEpisodes($tvshowTitle, false); diff --git a/src/Library/Action/Command/SearchCommand.php b/src/Library/Action/Command/LibrarySearchCommand.php similarity index 86% rename from src/Library/Action/Command/SearchCommand.php rename to src/Library/Action/Command/LibrarySearchCommand.php index 00a6728..76f1d91 100644 --- a/src/Library/Action/Command/SearchCommand.php +++ b/src/Library/Action/Command/LibrarySearchCommand.php @@ -4,7 +4,7 @@ namespace App\Library\Action\Command; use OneToMany\RichBundle\Contract\CommandInterface; -class SearchCommand implements CommandInterface +class LibrarySearchCommand implements CommandInterface { public function __construct( public ?string $term = null, diff --git a/src/Library/Action/Handler/SearchHandler.php b/src/Library/Action/Handler/LibrarySearchHandler.php similarity index 72% rename from src/Library/Action/Handler/SearchHandler.php rename to src/Library/Action/Handler/LibrarySearchHandler.php index 3757b3c..34c578e 100644 --- a/src/Library/Action/Handler/SearchHandler.php +++ b/src/Library/Action/Handler/LibrarySearchHandler.php @@ -3,16 +3,16 @@ namespace App\Library\Action\Handler; use App\Base\Service\MediaFiles; -use App\Library\Action\Command\SearchCommand; -use App\Library\Action\Result\SearchResult; +use App\Library\Action\Command\LibrarySearchCommand; +use App\Library\Action\Result\LibrarySearchResult; use OneToMany\RichBundle\Contract\CommandInterface; use OneToMany\RichBundle\Contract\HandlerInterface; use OneToMany\RichBundle\Contract\ResultInterface; /** - * @implements HandlerInterface + * @implements HandlerInterface */ -class SearchHandler implements HandlerInterface +class LibrarySearchHandler implements HandlerInterface { private array $searchTypes = [ 'episode_by_title' => 'episodeByTitle', @@ -40,7 +40,7 @@ class SearchHandler implements HandlerInterface return null; } - private function episodeByTitle(CommandInterface $command): ?SearchResult + private function episodeByTitle(CommandInterface $command): ?LibrarySearchResult { $result = $this->mediaFiles->episodeExists( $command->title, @@ -50,14 +50,11 @@ class SearchHandler implements HandlerInterface $exists = $result instanceof \SplFileInfo; - return new SearchResult( + + return new LibrarySearchResult( input: $command, - message: 'Success', - code: 200, - data: [ - 'exists' => $exists, - 'file' => true === $exists ? ['filename' => $result->getFilename(), 'size' => $result->getSize()] : null, - ] + exists: $exists, + file: true === $exists ? $result->getFileInfo() : null, ); } } diff --git a/src/Library/Action/Input/SearchInput.php b/src/Library/Action/Input/LibrarySearchInput.php similarity index 81% rename from src/Library/Action/Input/SearchInput.php rename to src/Library/Action/Input/LibrarySearchInput.php index 32cdf0b..1c2bce8 100644 --- a/src/Library/Action/Input/SearchInput.php +++ b/src/Library/Action/Input/LibrarySearchInput.php @@ -2,15 +2,15 @@ namespace App\Library\Action\Input; -use App\Library\Action\Command\SearchCommand; +use App\Library\Action\Command\LibrarySearchCommand; use OneToMany\RichBundle\Attribute\SourceQuery; use OneToMany\RichBundle\Contract\CommandInterface; use OneToMany\RichBundle\Contract\InputInterface; /** - * @implements InputInterface + * @implements InputInterface */ -class SearchInput implements InputInterface +class LibrarySearchInput implements InputInterface { public function __construct( #[SourceQuery('term', nullify: true)] @@ -27,7 +27,7 @@ class SearchInput implements InputInterface public function toCommand(): CommandInterface { - return new SearchCommand( + return new LibrarySearchCommand( term: $this->term, title: $this->title, imdbId: $this->imdbId, diff --git a/src/Library/Action/Result/SearchResult.php b/src/Library/Action/Result/LibrarySearchResult.php similarity index 52% rename from src/Library/Action/Result/SearchResult.php rename to src/Library/Action/Result/LibrarySearchResult.php index 2dce110..87435ae 100644 --- a/src/Library/Action/Result/SearchResult.php +++ b/src/Library/Action/Result/LibrarySearchResult.php @@ -4,12 +4,12 @@ namespace App\Library\Action\Result; use OneToMany\RichBundle\Contract\ResultInterface; -class SearchResult implements ResultInterface +class LibrarySearchResult implements ResultInterface { public function __construct( public object|array $input, - public string $message, - public int $code, - public ?array $data, + public bool $exists, + public ?\SplFileInfo $file = null, + public ?object $ptn = null, ) {} } diff --git a/src/Library/Framework/Controller/Api.php b/src/Library/Framework/Controller/Api.php index 855e404..b4c17b7 100644 --- a/src/Library/Framework/Controller/Api.php +++ b/src/Library/Framework/Controller/Api.php @@ -2,9 +2,9 @@ namespace App\Library\Framework\Controller; -use App\Library\Action\Handler\SearchHandler; -use App\Library\Action\Input\SearchInput; -use App\Library\Action\Result\SearchResult; +use App\Library\Action\Handler\LibrarySearchHandler; +use App\Library\Action\Input\LibrarySearchInput; +use App\Library\Action\Result\LibrarySearchResult; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -14,7 +14,7 @@ use Symfony\UX\Turbo\TurboBundle; class Api extends AbstractController { #[Route('/api/library/search', name: 'api.library.search', methods: ['GET'])] - public function search(SearchInput $input, SearchHandler $handler, Request $request): Response + public function search(LibrarySearchInput $input, LibrarySearchHandler $handler, Request $request): Response { $result = $handler->handle($input->toCommand()); @@ -25,7 +25,7 @@ class Api extends AbstractController return $this->json($handler->handle($input->toCommand())); } - private function sendFragmentResponse(SearchResult $result, Request $request): Response + private function sendFragmentResponse(LibrarySearchResult $result, Request $request): Response { $request->setRequestFormat(TurboBundle::STREAM_FORMAT); return $this->renderBlock( diff --git a/src/Search/Action/Handler/GetMediaInfoHandler.php b/src/Search/Action/Handler/GetMediaInfoHandler.php index c4ce8c6..24ae107 100644 --- a/src/Search/Action/Handler/GetMediaInfoHandler.php +++ b/src/Search/Action/Handler/GetMediaInfoHandler.php @@ -2,7 +2,6 @@ namespace App\Search\Action\Handler; -use App\Base\Service\MediaFiles; use App\Search\Action\Command\GetMediaInfoCommand; use App\Search\Action\Result\GetMediaInfoResult; use App\Tmdb\Tmdb; diff --git a/templates/search/fragments.html.twig b/templates/search/fragments.html.twig index 798a049..cd70cf0 100644 --- a/templates/search/fragments.html.twig +++ b/templates/search/fragments.html.twig @@ -1,14 +1,14 @@ {% block media_exists_badge %}