feat(bookstack) : add BookStackTestConnection API resource
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
28
src/ApiResource/BookStackTestConnection.php
Normal file
28
src/ApiResource/BookStackTestConnection.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\ApiResource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use App\State\BookStackTestConnectionProvider;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Post(
|
||||
uriTemplate: '/settings/bookstack/test',
|
||||
input: false,
|
||||
normalizationContext: ['groups' => ['bookstack_test:read']],
|
||||
provider: BookStackTestConnectionProvider::class,
|
||||
processor: BookStackTestConnectionProvider::class,
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class BookStackTestConnection
|
||||
{
|
||||
#[Groups(['bookstack_test:read'])]
|
||||
public bool $success = false;
|
||||
}
|
||||
31
src/State/BookStackTestConnectionProvider.php
Normal file
31
src/State/BookStackTestConnectionProvider.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\ApiResource\BookStackTestConnection;
|
||||
use App\Service\BookStackApiService;
|
||||
|
||||
final readonly class BookStackTestConnectionProvider implements ProviderInterface, ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private BookStackApiService $bookStackApiService,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): BookStackTestConnection
|
||||
{
|
||||
return new BookStackTestConnection();
|
||||
}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): BookStackTestConnection
|
||||
{
|
||||
$result = new BookStackTestConnection();
|
||||
$result->success = $this->bookStackApiService->testConnection();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user