feat(share) : endpoint test de connexion (POST settings/share/test)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\ApiResource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use App\State\ShareTestConnectionProvider;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Post(
|
||||
uriTemplate: '/settings/share/test',
|
||||
input: false,
|
||||
normalizationContext: ['groups' => ['share_test:read']],
|
||||
provider: ShareTestConnectionProvider::class,
|
||||
processor: ShareTestConnectionProvider::class,
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class ShareTestConnection
|
||||
{
|
||||
#[Groups(['share_test:read'])]
|
||||
public bool $success = false;
|
||||
|
||||
#[Groups(['share_test:read'])]
|
||||
public ?string $message = null;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\ApiResource\ShareTestConnection;
|
||||
use App\Service\Share\FileSource;
|
||||
|
||||
final readonly class ShareTestConnectionProvider implements ProviderInterface, ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private FileSource $fileSource,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ShareTestConnection
|
||||
{
|
||||
return new ShareTestConnection();
|
||||
}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ShareTestConnection
|
||||
{
|
||||
$result = $this->fileSource->test();
|
||||
|
||||
$dto = new ShareTestConnection();
|
||||
$dto->success = $result->success;
|
||||
$dto->message = $result->message;
|
||||
|
||||
return $dto;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user