Files
Mangarr/src/Domain/Manga/Application/CommandHandler/DeleteMangaHandler.php
ext.jeremy.guillot@maxicoffee.domains 7506a7a3c1 style: apply php-cs-fixer formatting (PSR-12)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 20:46:59 +01:00

31 lines
931 B
PHP

<?php
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\DeleteManga;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
use App\Domain\Shared\Domain\Contract\CommandInterface;
readonly class DeleteMangaHandler implements CommandHandlerInterface
{
public function __construct(
private MangaRepositoryInterface $mangaRepository
) {
}
public function handle(CommandInterface $command): void
{
assert($command instanceof DeleteManga);
$manga = $this->mangaRepository->findById($command->mangaId);
if (!$manga) {
throw new MangaNotFoundException(sprintf('Manga with id %s not found', $command->mangaId));
}
$this->mangaRepository->delete($manga);
}
}