chore: cleanup

This commit is contained in:
2025-07-13 21:27:54 -05:00
parent accfa9c9bf
commit b42981b2a1
8 changed files with 27 additions and 31 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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<SearchCommand,SearchHandler>
* @implements HandlerInterface<LibrarySearchCommand,LibrarySearchHandler>
*/
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,
);
}
}

View File

@@ -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<SearchInput, SearchCommand>
* @implements InputInterface<LibrarySearchInput, LibrarySearchCommand>
*/
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,

View File

@@ -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,
) {}
}

View File

@@ -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(

View File

@@ -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;

View File

@@ -1,14 +1,14 @@
{% block media_exists_badge %}
<turbo-stream action="replace" targets="#{{ target }}">
<template>
{% if result.data['exists'] == true %}
{% if result.exists == true %}
<span data-controller="popover">
<template data-popover-target="content">
<div data-popover-target="card"
class="absolute z-40 p-1 bg-stone-400 p-1 text-black rounded-md m-1 animate-fade">
<p class="font-bold text-sm text-left">Existing file(s) for this episode:</p>
<ul class="list-disc ml-3">
<li class="font-normal">{{ result.data['file']['filename']|strip_media_path }} &mdash; <strong>{{ result.data['file']['size']|filesize }}</strong></li>
<li class="font-normal">{{ result.file.filename|strip_media_path }} &mdash; <strong>{{ result.file.size|filesize }}</strong></li>
</ul>
</div>
</template>
@@ -21,7 +21,7 @@
</span>
{% endif %}
{% if result.data['exists'] == false %}
{% if result.exists == false %}
<small class="py-1 px-1.5 mr-1 grow-0 font-bold bg-rose-600 rounded-lg text-white"
title="Episode has not been downloaded yet.">
missing