feat(setting): implémenter la suppression d'une ContentSource
- Ajoute DeleteContentSourceCommand + CommandHandler (CQRS)
- Expose DELETE /api/content-sources/{id} via API Platform (Resource, Provider, Processor)
- Ajoute 2 tests Feature (204 succès, 404 not found)
- Frontend : méthode delete() dans le repository, action deleteSource() dans le store
- Nouveau composant ContentSourceDeleteModal (modale de confirmation)
- Bouton Supprimer dans la toolbar de ScrapperEdit (visible en mode édition uniquement)
This commit is contained in:
parent
36f873aaca
commit
fc4ab68e8b
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Application\Command;
|
||||
|
||||
readonly class DeleteContentSourceCommand
|
||||
{
|
||||
public function __construct(
|
||||
public int $id
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Application\CommandHandler;
|
||||
|
||||
use App\Domain\Setting\Application\Command\DeleteContentSourceCommand;
|
||||
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
|
||||
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||
|
||||
readonly class DeleteContentSourceCommandHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ContentSourceRepositoryInterface $contentSourceRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(DeleteContentSourceCommand $command): void
|
||||
{
|
||||
$contentSource = $this->contentSourceRepository->findById($command->id);
|
||||
|
||||
if (!$contentSource) {
|
||||
throw new ContentSourceNotFoundException($command->id);
|
||||
}
|
||||
|
||||
$this->contentSourceRepository->delete($contentSource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Infrastructure\ApiPlatform\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor\DeleteContentSourceStateProcessor;
|
||||
use App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider\DeleteContentSourceStateProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'ContentSource',
|
||||
operations: [
|
||||
new Delete(
|
||||
uriTemplate: '/content-sources/{id}',
|
||||
provider: DeleteContentSourceStateProvider::class,
|
||||
processor: DeleteContentSourceStateProcessor::class,
|
||||
name: 'delete_content_source',
|
||||
openapiContext: [
|
||||
'summary' => 'Delete a content source',
|
||||
'description' => 'Permanently deletes a content source',
|
||||
'parameters' => [
|
||||
[
|
||||
'name' => 'id',
|
||||
'in' => 'path',
|
||||
'required' => true,
|
||||
'schema' => [
|
||||
'type' => 'integer'
|
||||
],
|
||||
'description' => 'The content source ID'
|
||||
]
|
||||
],
|
||||
'responses' => [
|
||||
'204' => [
|
||||
'description' => 'Content source successfully deleted'
|
||||
],
|
||||
'404' => [
|
||||
'description' => 'Content source not found'
|
||||
]
|
||||
]
|
||||
]
|
||||
)
|
||||
]
|
||||
)]
|
||||
class DeleteContentSourceResource
|
||||
{
|
||||
public function __construct(
|
||||
public int $id
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Infrastructure\ApiPlatform\State\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Domain\Setting\Application\Command\DeleteContentSourceCommand;
|
||||
use App\Domain\Setting\Application\CommandHandler\DeleteContentSourceCommandHandler;
|
||||
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
readonly class DeleteContentSourceStateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteContentSourceCommandHandler $handler
|
||||
) {
|
||||
}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): int
|
||||
{
|
||||
if (!isset($uriVariables['id'])) {
|
||||
throw new \InvalidArgumentException('Content source ID is required');
|
||||
}
|
||||
|
||||
try {
|
||||
$command = new DeleteContentSourceCommand((int) $uriVariables['id']);
|
||||
$this->handler->handle($command);
|
||||
|
||||
return Response::HTTP_NO_CONTENT;
|
||||
} catch (ContentSourceNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Setting\Infrastructure\ApiPlatform\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Domain\Setting\Domain\Contract\Repository\ContentSourceRepositoryInterface;
|
||||
use App\Domain\Setting\Domain\Exception\ContentSourceNotFoundException;
|
||||
use App\Domain\Setting\Infrastructure\ApiPlatform\Resource\DeleteContentSourceResource;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
readonly class DeleteContentSourceStateProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ContentSourceRepositoryInterface $contentSourceRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): DeleteContentSourceResource
|
||||
{
|
||||
if (!isset($uriVariables['id'])) {
|
||||
throw new NotFoundHttpException('Content source ID is required');
|
||||
}
|
||||
|
||||
$id = (int) $uriVariables['id'];
|
||||
|
||||
try {
|
||||
$contentSource = $this->contentSourceRepository->findById($id);
|
||||
|
||||
if (!$contentSource) {
|
||||
throw new ContentSourceNotFoundException($id);
|
||||
}
|
||||
|
||||
return new DeleteContentSourceResource($id);
|
||||
} catch (ContentSourceNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user