feat: button to add movie monitor
This commit is contained in:
16
src/Download/Action/Command/AddMovieMonitorCommand.php
Normal file
16
src/Download/Action/Command/AddMovieMonitorCommand.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Action\Command;
|
||||
|
||||
use App\Download\Framework\Entity\MovieMonitor;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
|
||||
class AddMovieMonitorCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $userEmail,
|
||||
public string $title,
|
||||
public string $imdbId,
|
||||
public string $tmdbId,
|
||||
) {}
|
||||
}
|
||||
45
src/Download/Action/Handler/AddMovieMonitorHandler.php
Normal file
45
src/Download/Action/Handler/AddMovieMonitorHandler.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Action\Handler;
|
||||
|
||||
use App\Download\Action\Command\AddMovieMonitorCommand;
|
||||
use App\Download\Action\Result\MonitorMovieResult;
|
||||
use App\Download\Framework\Entity\MovieMonitor;
|
||||
use App\Download\Framework\Repository\MovieMonitorRepository;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use DateTimeImmutable;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
/** @implements HandlerInterface<AddMovieMonitorCommand> */
|
||||
readonly class AddMovieMonitorHandler implements HandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private MovieMonitorRepository $movieMonitorRepository,
|
||||
private UserRepository $userRepository,
|
||||
) {}
|
||||
|
||||
public function handle(CommandInterface $command): ResultInterface
|
||||
{
|
||||
$user = $this->userRepository->findOneBy(['email' => $command->userEmail]);
|
||||
$monitor = new MovieMonitor();
|
||||
$monitor->setTmdbId($command->tmdbId);
|
||||
$monitor->setImdbId($command->imdbId);
|
||||
$monitor->setTitle($command->title);
|
||||
$monitor->setUser($user);
|
||||
$monitor->setCreatedAt(new DateTimeImmutable());
|
||||
$monitor->setSearchCount(0);
|
||||
$monitor->setStatus('New');
|
||||
|
||||
$this->movieMonitorRepository->getEntityManager()->persist($monitor);
|
||||
$this->movieMonitorRepository->getEntityManager()->flush();
|
||||
|
||||
return new MonitorMovieResult(
|
||||
status: 'OK',
|
||||
result: [
|
||||
'monitor' => $monitor,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
31
src/Download/Action/Input/AddMovieMonitorInput.php
Normal file
31
src/Download/Action/Input/AddMovieMonitorInput.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Action\Input;
|
||||
|
||||
use App\Download\Action\Command\AddMovieMonitorCommand;
|
||||
use OneToMany\RichBundle\Attribute\SourceRoute;
|
||||
use OneToMany\RichBundle\Attribute\SourceSecurity;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
use OneToMany\RichBundle\Contract\InputInterface;
|
||||
|
||||
class AddMovieMonitorInput implements InputInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[SourceSecurity]
|
||||
public string $userEmail,
|
||||
|
||||
#[SourceRoute('title')]
|
||||
public string $title,
|
||||
|
||||
#[SourceRoute('tmdbId')]
|
||||
public string $tmdbId,
|
||||
|
||||
#[SourceRoute('imdbId')]
|
||||
public string $imdbId,
|
||||
) {}
|
||||
|
||||
public function toCommand(): CommandInterface
|
||||
{
|
||||
return new AddMovieMonitorCommand($this->userEmail, $this->title, $this->tmdbId, $this->imdbId);
|
||||
}
|
||||
}
|
||||
13
src/Download/Action/Result/AddMovieMonitorResult.php
Normal file
13
src/Download/Action/Result/AddMovieMonitorResult.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Download\Action\Result;
|
||||
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
class AddMovieMonitorResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $status,
|
||||
public array $result,
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user