Improvements, and fixed pagination

feature/integration-ogboot
Manuel Aranda Rosales 2024-08-19 15:01:32 +02:00
parent 159d38570a
commit f483b94a70
17 changed files with 455 additions and 356 deletions

2
.env
View File

@ -24,7 +24,7 @@ APP_SECRET=e95c7f17da15ce1b03d77ad655379c34
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
#DATABASE_URL="mysql://root:root@127.0.0.1:3336/dimio?serverVersion=8.0.32&charset=utf8mb4"
DATABASE_URL="mysql://root:root@ogcore-database:3306/ogcore?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
OG_1_DATABASE_URL="mysql://root:root@ogcore-database:3306/ogcore_old_og?serverVersion=10.11.2-MariaDB&charset=utf8mb4"

View File

@ -7,7 +7,7 @@
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.3",
"api-platform/core": "^3.2",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",

624
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ resources:
filters:
- 'api_platform.filter.client.order'
- 'api_platform.filter.client.search'
- 'api_platform.filter.client.boolean'
ApiPlatform\Metadata\Get:
provider: App\State\Provider\ClientProvider
ApiPlatform\Metadata\Put:

View File

@ -13,6 +13,7 @@ resources:
filters:
- 'api_platform.filter.organizational_unit.order'
- 'api_platform.filter.organizational_unit.search'
ApiPlatform\Metadata\Get:
security: 'is_granted("ORGANIZATIONAL_UNIT_VIEW", object)'
provider: App\State\Provider\OrganizationalUnitProvider

View File

@ -2,39 +2,20 @@ api_platform:
title: 'OgCore Api'
description: 'Api Documentation for OgCore'
version: 1.0.0
path_segment_name_generator: 'api_platform.path_segment_name_generator.dash'
path_segment_name_generator: api_platform.path_segment_name_generator.dash
defaults:
pagination_client_items_per_page: true
collection:
pagination:
items_per_page_parameter_name: 'itemsPerPage'
formats:
jsonld: [ 'application/ld+json' ]
jsonhal: [ 'application/hal+json' ]
jsonapi: [ 'application/vnd.api+json' ]
json: [ 'application/json' ]
xml: [ 'application/xml', 'text/xml' ]
yaml: [ 'application/x-yaml' ]
csv: [ 'text/csv' ]
html: [ 'text/html' ]
json: [ 'application/json' ]
csv: [ 'text/csv' ]
patch_formats:
jsonld: ['application/ld+json', 'application/json']
mapping:
paths: ['%kernel.project_dir%/config/api_platform', '%kernel.project_dir%/src/Dto']
use_symfony_listeners: true
collection:
pagination:
items_per_page_parameter_name: 'itemsPerPage'
defaults:
pagination_client_items_per_page: true
denormalization_context:
allow_extra_attributes: false
cache_headers:
vary: [ 'Content-Type', 'Authorization', 'Origin' ]
extra_properties:
standard_put: true
rfc_7807_compliant_errors: true
event_listeners_backward_compatibility_layer: false
keep_legacy_inflector: true
docs_formats:
jsonld: ['application/ld+json']
jsonopenapi: ['application/vnd.openapi+json']
html: ['text/html']
swagger:
versions: [3]
api_keys:

View File

@ -2,19 +2,19 @@ server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.html index.php;
location / {
try_files $uri /index.php?$is_args$args;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/index.php(/|$) {
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param DOCUMENT_ROOT $document_root;
internal;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
}
location ~ \.php$ {

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240819062421 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE og_live ADD synchronized TINYINT(1) DEFAULT NULL');
$this->addSql('ALTER TABLE pxe_template ADD synchronized TINYINT(1) DEFAULT 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 synchronized');
$this->addSql('ALTER TABLE pxe_template DROP synchronized');
}
}

View File

@ -13,6 +13,9 @@ final class OgLiveOutput extends AbstractOutput
#[Groups(['og-live:read'])]
public string $name;
#[Groups(['og-live:read'])]
public ?bool $synchronized = false;
#[Groups(['og-live:read'])]
public ?string $downloadUrl = '';
@ -27,6 +30,7 @@ final class OgLiveOutput extends AbstractOutput
parent::__construct($ogLive);
$this->name = $ogLive->getName();
$this->synchronized = $ogLive->isSynchronized();
$this->downloadUrl = $ogLive->getDownloadUrl();
$this->createdAt = $ogLive->getCreatedAt();
$this->createdBy = $ogLive->getCreatedBy();

View File

@ -13,6 +13,9 @@ final class PxeTemplateOutput extends AbstractOutput
#[Groups(['pxe-template:read'])]
public string $name;
#[Groups(['pxe-template:read'])]
public ?bool $synchronized = null;
#[Groups(['pxe-template:read'])]
public ?string $templateContent = '';
@ -27,6 +30,7 @@ final class PxeTemplateOutput extends AbstractOutput
parent::__construct($pxeTemplate);
$this->name = $pxeTemplate->getName();
$this->synchronized = $pxeTemplate->isSynchronized();
$this->templateContent = $pxeTemplate->getTemplateContent();
$this->createdAt = $pxeTemplate->getCreatedAt();
$this->createdBy = $pxeTemplate->getCreatedBy();

View File

@ -12,6 +12,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
class OgLive extends AbstractEntity
{
use NameableTrait;
use SynchronizedTrait;
#[ORM\Column(length: 255, nullable: true)]
private ?string $downloadUrl = null;

View File

@ -13,8 +13,9 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
class PxeTemplate extends AbstractEntity
{
use NameableTrait;
use SynchronizedTrait;
#[ORM\Column(length: 255, type: Types::TEXT)]
#[ORM\Column(type: Types::TEXT, length: 255)]
private ?string $templateContent = null;
public function getTemplateContent(): ?string

View File

@ -0,0 +1,23 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
trait SynchronizedTrait
{
#[ORM\Column(type: 'boolean', nullable: true)]
private bool $synchronized = false;
public function isSynchronized(): ?bool
{
return $this->synchronized;
}
public function setSynchronized(?bool $synchronized): self
{
$this->synchronized = $synchronized;
return $this;
}
}

View File

@ -20,7 +20,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface
$this->addRefreshToken($openApi);
$this->addSearchEndpoint($openApi);
$this->addStatusEndpoint($openApi); // Agregar el nuevo endpoint
return $openApi;
}
@ -126,4 +126,53 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface
])
));
}
private function addStatusEndpoint(OpenApi $openApi): void
{
$openApi
->getPaths()
->addPath('/og-boot/status', (new Model\PathItem())->withGet(
(new Model\Operation('getStatus'))
->withTags(['OgBoot'])
->withResponses([
Response::HTTP_OK => [
'description' => 'Service status',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'status' => [
'type' => 'string',
'example' => 'ok',
],
'uptime' => [
'type' => 'integer',
'example' => 12345,
],
],
],
],
],
],
Response::HTTP_SERVICE_UNAVAILABLE => [
'description' => 'Service unavailable',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'error' => [
'type' => 'string',
'example' => 'Service is down',
],
],
],
],
],
],
])
->withSummary('Get service status')
));
}
}

View File

@ -21,12 +21,12 @@ use App\Repository\OrganizationalUnitRepository;
use App\Service\ChangeClientNetworkSettingsService;
use Doctrine\ORM\EntityManagerInterface;
class OrganizationalUnitProcessor implements ProcessorInterface
readonly class OrganizationalUnitProcessor implements ProcessorInterface
{
public function __construct(
private readonly OrganizationalUnitRepository $organizationalUnitRepository,
private readonly ValidatorInterface $validator,
private readonly ChangeClientNetworkSettingsService $changeClientNetworkSettingsService,
private OrganizationalUnitRepository $organizationalUnitRepository,
private ValidatorInterface $validator,
private ChangeClientNetworkSettingsService $changeClientNetworkSettingsService,
)
{
}

View File

@ -13,11 +13,11 @@ use App\Dto\Input\ClientInput;
use App\Dto\Output\ClientOutput;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ClientProvider implements ProviderInterface
readonly class ClientProvider implements ProviderInterface
{
public function __construct(
private readonly ProviderInterface $collectionProvider,
private readonly ProviderInterface $itemProvider
private ProviderInterface $collectionProvider,
private ProviderInterface $itemProvider
)
{
}

View File

@ -14,7 +14,7 @@ use App\Dto\Output\OrganizationalUnitOutput;
use App\Entity\OrganizationalUnit;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
readonly class OrganizationalUnitProvider implements ProviderInterface
final readonly class OrganizationalUnitProvider implements ProviderInterface
{
public function __construct(
private ProviderInterface $collectionProvider,