fix: delete manga
All checks were successful
Build and Deploy / deploy (push) Successful in 1m2s

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-02-11 16:27:11 +01:00
parent f75b535426
commit b5a832fbbc
2 changed files with 41 additions and 1 deletions

View File

@@ -5,15 +5,16 @@ namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\DeleteMangaProcessor;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\DeleteMangaProvider;
#[ApiResource(
shortName: 'Manga',
operations: [
new Delete(
uriTemplate: '/mangas/{id}',
provider: DeleteMangaProvider::class,
processor: DeleteMangaProcessor::class,
name: 'delete_manga',
read: false,
openapiContext: [
'summary' => 'Delete a manga',
'description' => 'Permanently deletes a manga and all its associated chapters',

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Manga\Infrastructure\ApiPlatform\Resource\DeleteMangaResource;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
readonly class DeleteMangaProvider implements ProviderInterface
{
public function __construct(
private MangaRepositoryInterface $mangaRepository
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): DeleteMangaResource
{
if (!isset($uriVariables['id'])) {
throw new NotFoundHttpException('Manga ID is required');
}
$mangaId = $uriVariables['id'];
try {
$manga = $this->mangaRepository->findById($mangaId);
if (!$manga) {
throw new MangaNotFoundException(sprintf('Manga with id %s not found', $mangaId));
}
return new DeleteMangaResource($mangaId);
} catch (MangaNotFoundException $e) {
throw new NotFoundHttpException('Manga not found');
}
}
}