feat : add Gitea test connection endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\ApiResource;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\State\GiteaTestConnectionProvider;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/settings/gitea/test',
|
||||||
|
input: false,
|
||||||
|
normalizationContext: ['groups' => ['gitea_test:read']],
|
||||||
|
provider: GiteaTestConnectionProvider::class,
|
||||||
|
processor: GiteaTestConnectionProvider::class,
|
||||||
|
security: "is_granted('ROLE_ADMIN')",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)]
|
||||||
|
final class GiteaTestConnection
|
||||||
|
{
|
||||||
|
#[Groups(['gitea_test:read'])]
|
||||||
|
public bool $success = false;
|
||||||
|
}
|
||||||
@@ -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\GiteaTestConnection;
|
||||||
|
use App\Service\GiteaApiService;
|
||||||
|
|
||||||
|
final readonly class GiteaTestConnectionProvider implements ProviderInterface, ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private GiteaApiService $giteaApiService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): GiteaTestConnection
|
||||||
|
{
|
||||||
|
return new GiteaTestConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): GiteaTestConnection
|
||||||
|
{
|
||||||
|
$result = new GiteaTestConnection();
|
||||||
|
$result->success = $this->giteaApiService->testConnection();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user