feat : add DashboardProvider for container status overview
This commit is contained in:
50
src/State/DashboardProvider.php
Normal file
50
src/State/DashboardProvider.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\State;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\ApiResource\Dashboard;
|
||||||
|
use App\Repository\ApplicationRepository;
|
||||||
|
use App\Service\DockerService;
|
||||||
|
|
||||||
|
final readonly class DashboardProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ApplicationRepository $applicationRepository,
|
||||||
|
private DockerService $dockerService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Dashboard
|
||||||
|
{
|
||||||
|
$applications = $this->applicationRepository->findAll();
|
||||||
|
|
||||||
|
$dto = new Dashboard();
|
||||||
|
|
||||||
|
foreach ($applications as $app) {
|
||||||
|
$envs = [];
|
||||||
|
|
||||||
|
foreach ($app->getEnvironments() as $env) {
|
||||||
|
$containerStatus = $this->dockerService->getContainerStatus($env->getContainerName());
|
||||||
|
|
||||||
|
$envs[] = [
|
||||||
|
'id' => $env->getId(),
|
||||||
|
'name' => $env->getName(),
|
||||||
|
'status' => $containerStatus['status'],
|
||||||
|
'version' => $containerStatus['version'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$dto->applications[] = [
|
||||||
|
'name' => $app->getName(),
|
||||||
|
'slug' => $app->getSlug(),
|
||||||
|
'giteaUrl' => $app->getGiteaUrl(),
|
||||||
|
'environments' => $envs,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user