This commit is contained in:
parent
f75b535426
commit
b5a832fbbc
@@ -5,15 +5,16 @@ namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Delete;
|
use ApiPlatform\Metadata\Delete;
|
||||||
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\DeleteMangaProcessor;
|
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\DeleteMangaProcessor;
|
||||||
|
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\DeleteMangaProvider;
|
||||||
|
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
shortName: 'Manga',
|
shortName: 'Manga',
|
||||||
operations: [
|
operations: [
|
||||||
new Delete(
|
new Delete(
|
||||||
uriTemplate: '/mangas/{id}',
|
uriTemplate: '/mangas/{id}',
|
||||||
|
provider: DeleteMangaProvider::class,
|
||||||
processor: DeleteMangaProcessor::class,
|
processor: DeleteMangaProcessor::class,
|
||||||
name: 'delete_manga',
|
name: 'delete_manga',
|
||||||
read: false,
|
|
||||||
openapiContext: [
|
openapiContext: [
|
||||||
'summary' => 'Delete a manga',
|
'summary' => 'Delete a manga',
|
||||||
'description' => 'Permanently deletes a manga and all its associated chapters',
|
'description' => 'Permanently deletes a manga and all its associated chapters',
|
||||||
|
|||||||
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user