feat(fer-19) : endpoint GET /pont_bascule/health

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-21 14:12:02 +02:00
parent 75d5e9cf54
commit feddac372f
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use App\State\PontBasculeHealthProvider;
use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new Get(
uriTemplate: '/pont_bascule/health',
openapi: new OpenApiOperation(
summary: 'Pont-bascule health check',
description: 'Returns the connection state of the pont-bascule. Always 200, even when unreachable.',
),
normalizationContext: ['groups' => ['pont_bascule:health:read']],
provider: PontBasculeHealthProvider::class,
),
],
)]
final class PontBasculeHealthCheck
{
#[Groups(['pont_bascule:health:read'])]
public bool $healthy = false;
#[Groups(['pont_bascule:health:read'])]
public bool $ok = false;
#[Groups(['pont_bascule:health:read'])]
public bool $busy = false;
#[Groups(['pont_bascule:health:read'])]
public bool $portConnected = false;
#[Groups(['pont_bascule:health:read'])]
public ?string $portError = null;
#[Groups(['pont_bascule:health:read'])]
public ?string $hostname = null;
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\PontBasculeHealthCheck;
use App\Service\PontBasculeService;
final readonly class PontBasculeHealthProvider implements ProviderInterface
{
public function __construct(
private PontBasculeService $pontBasculeService,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): PontBasculeHealthCheck
{
$health = $this->pontBasculeService->checkHealth();
$resource = new PontBasculeHealthCheck();
$resource->healthy = $health->isHealthy();
$resource->ok = $health->isOk();
$resource->busy = $health->isBusy();
$resource->portConnected = $health->isPortConnected();
$resource->portError = $health->getPortError();
$resource->hostname = $health->getHostname();
return $resource;
}
}