diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index fb2af43..00d855e 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -8,7 +8,7 @@ services: api_platform.filter.client.search: parent: 'api_platform.doctrine.orm.search_filter' - arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact' } ] + arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact', 'ip': exact, 'mac': exact } ] tags: [ 'api_platform.filter' ] api_platform.filter.hardware.order: diff --git a/migrations/Version20240905080435.php b/migrations/Version20240905080435.php new file mode 100644 index 0000000..82c72f8 --- /dev/null +++ b/migrations/Version20240905080435.php @@ -0,0 +1,32 @@ +addSql('ALTER TABLE og_live ADD status VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE og_live DROP status'); + + } +} diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index e9b871c..2572499 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\OgLive; use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; +use App\Model\OgLiveStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -32,13 +33,14 @@ class InstallAction extends AbstractOgBootController $params = [ 'json' => [ - 'url' => $data->getDownloadUrl() + 'url' => $data->getDownloadUrl(), + 'ogCoreId' => $data->getUuid() ] ]; $content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); - $data->setInstalled(true); + $data->setStatus(OgLiveStatus::PENDING); $entityManager->persist($data); $entityManager->flush(); diff --git a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php index caf97e6..61f185f 100644 --- a/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php +++ b/src/Controller/OgBoot/OgLive/Webhook/InstallOgLiveResponseAction.php @@ -3,6 +3,8 @@ namespace App\Controller\OgBoot\OgLive\Webhook; use App\Controller\OgBoot\AbstractOgBootController; +use App\Entity\OgLive; +use App\Model\OgLiveStatus; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -31,6 +33,33 @@ class InstallOgLiveResponseAction extends AbstractController { $data = json_decode($request->getContent(), true); - return new JsonResponse(data: ['hola caracola'], status: Response::HTTP_OK); + if ($data === null || !isset($data['message'], $data['ogCoreId'], $data['details']['result'])) { + return new JsonResponse(['error' => 'Invalid or incomplete JSON data'], Response::HTTP_BAD_REQUEST); + } + + $message = $data['message']; + $ogCoreId = $data['ogCoreId']; + $details = $data['details']; + $result = $details['result']; + + $ogLive = $this->entityManager->getRepository(OgLive::class)->findOneBy(['uuid' => $ogCoreId]); + + if (!$ogLive) { + return new JsonResponse(['error' => 'OgLive not found'], Response::HTTP_NOT_FOUND); + } + + $ogLive->setStatus($details['status'] === 'success' ? OgLiveStatus::ACTIVE : OgLiveStatus::FAILED); + $ogLive->setInstalled($details['status'] === 'success'); + $ogLive->setChecksum($result['id']); + $ogLive->setDistribution($result['distribution']); + $ogLive->setKernel($result['kernel']); + $ogLive->setArchitecture($result['architecture']); + $ogLive->setRevision($result['revision']); + $ogLive->setDirectory($result['directory']); + + $this->entityManager->persist($ogLive); + $this->entityManager->flush(); + + return new JsonResponse(data: 'Oglive updated successfully', status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Dto/Input/OgLiveInput.php b/src/Dto/Input/OgLiveInput.php index d9e86df..2c86228 100644 --- a/src/Dto/Input/OgLiveInput.php +++ b/src/Dto/Input/OgLiveInput.php @@ -4,6 +4,7 @@ namespace App\Dto\Input; use ApiPlatform\Metadata\ApiProperty; use App\Entity\OgLive; +use App\Model\OgLiveStatus; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -36,6 +37,7 @@ final class OgLiveInput $ogLive->setName($this->name); $ogLive->setDownloadUrl($this->downloadUrl); + $ogLive->setStatus(OgLiveStatus::INACTIVE); return $ogLive; } diff --git a/src/Dto/Output/OgLiveOutput.php b/src/Dto/Output/OgLiveOutput.php index bc9fc32..60b0d3d 100644 --- a/src/Dto/Output/OgLiveOutput.php +++ b/src/Dto/Output/OgLiveOutput.php @@ -25,6 +25,9 @@ final class OgLiveOutput extends AbstractOutput #[Groups(['og-live:read'])] public ?string $downloadUrl = ''; + #[Groups(['og-live:read'])] + public ?string $status = ''; + #[Groups(['og-live:read'])] public \DateTime $createdAt; @@ -40,6 +43,7 @@ final class OgLiveOutput extends AbstractOutput $this->installed = $ogLive->isInstalled(); $this->isDefault = $ogLive->getIsDefault(); $this->downloadUrl = $ogLive->getDownloadUrl(); + $this->status = $ogLive->getStatus(); $this->createdAt = $ogLive->getCreatedAt(); $this->createdBy = $ogLive->getCreatedBy(); } diff --git a/src/Entity/OgLive.php b/src/Entity/OgLive.php index 2983c79..df0f872 100644 --- a/src/Entity/OgLive.php +++ b/src/Entity/OgLive.php @@ -52,6 +52,9 @@ class OgLive extends AbstractEntity #[ORM\OneToMany(mappedBy: 'ogLive', targetEntity: Client::class)] private Collection $clients; + #[ORM\Column(length: 255)] + private ?string $status = null; + public function __construct() { parent::__construct(); @@ -205,4 +208,16 @@ class OgLive extends AbstractEntity return $this; } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(string $status): static + { + $this->status = $status; + + return $this; + } } diff --git a/src/Model/OgLiveStatus.php b/src/Model/OgLiveStatus.php new file mode 100644 index 0000000..2b9e744 --- /dev/null +++ b/src/Model/OgLiveStatus.php @@ -0,0 +1,36 @@ + 'Pendiente', + self::ACTIVE => 'Activo', + self::INACTIVE => 'Inactivo', + self::DELETED => 'Eliminado', + self::FAILED => 'Fallido', + ]; + + public static function getOgLiveStatuses(): array + { + return self::OG_LIVE_STATUSES; + } + + public static function getOgLiveStatus(string $ogLiveStatus): ?string + { + return self::OG_LIVE_STATUSES[$ogLiveStatus] ?? null; + } + + public static function getOgLiveStatusKeys(): array + { + return array_keys(self::OG_LIVE_STATUSES); + } +} \ No newline at end of file