diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 8871ca7..352abc2 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -1,6 +1,6 @@ api_platform: - title: 'OgCore API' - description: 'API Documentation for OgCore' + title: 'OgCore Api' + description: 'Api Documentation for OgCore' version: 1.0.0 path_segment_name_generator: 'api_platform.path_segment_name_generator.dash' formats: diff --git a/src/Controller/Api/SearchController.php b/src/Controller/Api/SearchController.php new file mode 100644 index 0000000..45a5d44 --- /dev/null +++ b/src/Controller/Api/SearchController.php @@ -0,0 +1,37 @@ +query->get('filters'); + if ($filters) { + $filters = json_decode($filters, true); + } + + $repository = $entityManager->getRepository(Client::class); + $queryBuilder = $repository->createQueryBuilder('e'); + + if (!empty($filters)) { + foreach ($filters as $field => $value) { + $queryBuilder->andWhere("e.$field = :$field") + ->setParameter($field, $value); + } + } + + $results = $queryBuilder->getQuery()->getResult(); + + return new JsonResponse($results); + } +} diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index 5f45ffc..564f65b 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -15,63 +15,63 @@ final class ClientInput #[Assert\NotBlank(message: 'validators.client.name.not_blank')] #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.name', - example: "examples.client.name", + description: 'El nombre del cliente', + example: 'Cliente 1', )] public ?string $name = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.serial_number', - example: "examples.client.serial_number" + description: 'La descripción del cliente', + example: 'Cliente descripcion 1', )] public ?string $serialNumber = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.network_interface', - example: "examples.client.network_interface" + description: 'La interfaz de red del cliente', + example: 'eth0' )] public ?string $netiface = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.network_driver', - example: "examples.client.network_driver" + description: 'El driver de red del cliente', + example: 'e1000e' )] public ?string $netDriver = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.mac_address', - example: "examples.client.mac_address" + description: 'La dirección MAC del cliente', + example: '00:00:00:00:00:00' )] public ?string $mac = null; #[Groups(['client:write'])] #[Assert\Ip(message: 'validators.ip_address.invalid')] #[ApiProperty( - description: 'descriptions.client.ip_address', - example: "examples.client.ip_address" + description: 'La dirección IP del cliente', + example: '192.168.1.1' )] public ?string $ip = null; #[Assert\NotNull(message: 'validators.organizational_unit.not_null')] #[Groups(['client:write', 'client:patch'])] #[ApiProperty( - description: 'descriptions.client.organizational_unit' + description: 'La unidad organizativa del cliente' )] public ?OrganizationalUnitOutput $organizationalUnit = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.menu' + description: 'El menú del cliente' )] public ?MenuOutput $menu = null; #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.hardware_profile' + description: 'El perfil de hardware del cliente' )] public ?HardwareProfileOutput $hardwareProfile = null; diff --git a/src/Dto/Input/HardwareInput.php b/src/Dto/Input/HardwareInput.php index 7674310..4e763bd 100644 --- a/src/Dto/Input/HardwareInput.php +++ b/src/Dto/Input/HardwareInput.php @@ -10,7 +10,7 @@ use Symfony\Component\Validator\Constraints as Assert; final class HardwareInput { - #[Assert\NotBlank] + #[Assert\NotBlank(message: 'validators.hardware.name.not_blank')] #[Groups(['hardware:write'])] #[ApiProperty(description: 'The name of the hardware', example: "Hardware 1")] public ?string $name = null; @@ -19,7 +19,7 @@ final class HardwareInput #[ApiProperty(description: 'The description of the hardware', example: "Hardware 1 description")] public ?string $description = null; - #[Assert\NotNull] + #[Assert\NotNull(message: 'validators.hardware.type.not_null')] #[Groups(['hardware:write'])] #[ApiProperty(description: 'The type of the hardware', example: "Server")] public ?HardwareTypeOutput $type = null; diff --git a/src/Dto/Input/HardwareTypeInput.php b/src/Dto/Input/HardwareTypeInput.php index 9eb0ae1..7078492 100644 --- a/src/Dto/Input/HardwareTypeInput.php +++ b/src/Dto/Input/HardwareTypeInput.php @@ -8,7 +8,7 @@ use Symfony\Component\Validator\Constraints as Assert; class HardwareTypeInput { - #[Assert\NotBlank] + #[Assert\NotBlank(message: 'validators.hardware_type.name.not_blank')] #[Groups(['hardware-type:write'])] public ?string $name = null; diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index d6623ab..10c46a5 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -11,7 +11,7 @@ use Symfony\Component\Validator\Constraints as Assert; final class ImageInput { - #[Assert\NotBlank] + #[Assert\NotBlank(message: 'validators.image.name.not_blank')] #[Groups(['image:write'])] #[ApiProperty(description: 'The name of the image', example: "Image 1")] public ?string $name = null; diff --git a/src/Dto/Input/NetworkSettingsInput.php b/src/Dto/Input/NetworkSettingsInput.php index 750f0de..e32c732 100644 --- a/src/Dto/Input/NetworkSettingsInput.php +++ b/src/Dto/Input/NetworkSettingsInput.php @@ -18,11 +18,11 @@ class NetworkSettingsInput #[Groups(['organizational-unit:write'])] public ?string $proxy = null; - #[Assert\Ip()] + #[Assert\Ip(message: 'validators.network_settings.ip_address.invalid')] #[Groups(['organizational-unit:write'])] public ?string $dns = null; - #[Assert\Ip()] + #[Assert\Ip(message: 'validators.network_settings.ip_address.invalid')] #[Groups(['organizational-unit:write'])] public ?string $netmask = null; @@ -36,15 +36,15 @@ class NetworkSettingsInput #[Groups(['organizational-unit:write'])] public ?string $p2pMode = null; - #[Assert\GreaterThan(0)] + #[Assert\GreaterThan(0, message: 'validators.network_settings.p2p_time.invalid')] #[Groups(['organizational-unit:write'])] public ?int $p2pTime = null; - #[Assert\Ip()] + #[Assert\Ip(message: 'validators.network_settings.ip_address.invalid')] #[Groups(['organizational-unit:write'])] public ?string $mcastIp = null; - #[Assert\GreaterThan(0)] + #[Assert\GreaterThan(0, message: 'validators.network_settings.mcast_speed.invalid')] #[Groups(['organizational-write:write'])] public ?int $mcastSpeed = null; diff --git a/src/Dto/Input/OperativeSystemInput.php b/src/Dto/Input/OperativeSystemInput.php index a38d809..8ebac93 100644 --- a/src/Dto/Input/OperativeSystemInput.php +++ b/src/Dto/Input/OperativeSystemInput.php @@ -8,7 +8,7 @@ use Symfony\Component\Validator\Constraints as Assert; class OperativeSystemInput { - #[Assert\NotBlank] + #[Assert\NotBlank(message: 'validators.operative_system.name.not_blank')] #[Groups(['operative-system:write'])] public ?string $name = null; diff --git a/src/Dto/Input/OrganizationalUnitInput.php b/src/Dto/Input/OrganizationalUnitInput.php index 7ce2c2b..1b83437 100644 --- a/src/Dto/Input/OrganizationalUnitInput.php +++ b/src/Dto/Input/OrganizationalUnitInput.php @@ -16,7 +16,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[OrganizationalUnitParent] class OrganizationalUnitInput { - #[Assert\NotBlank] + #[Assert\NotBlank(message: 'validators.organizational_unit.name.not_blank')] #[Groups(['organizational-unit:write'])] public ?string $name = null; diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index d7a732e..9e0ae6f 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -19,6 +19,8 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface $openApi = $this->decorated->__invoke($context); $this->addRefreshToken($openApi); + $this->addSearchEndpoint($openApi); + return $openApi; } @@ -75,4 +77,53 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface ) )); } + private function addSearchEndpoint(OpenApi $openApi): void + { + $openApi + ->getPaths() + ->addPath('/search', (new Model\PathItem())->withGet( + (new Model\Operation('getSearch')) + ->withTags(['Search']) + ->withResponses([ + Response::HTTP_OK => [ + 'description' => 'Search results', + 'content' => [ + 'application/json' => [ + 'schema' => [ + 'type' => 'object', + 'properties' => [ + 'results' => [ + 'type' => 'array', + 'items' => [ + 'type' => 'object', + 'properties' => [ + 'id' => [ + 'type' => 'integer', + 'example' => 1, + ], + 'name' => [ + 'type' => 'string', + 'example' => 'Item name', + ], + ], + ], + ], + ], + ], + ], + ], + ], + ]) + ->withSummary('Search for items') + ->withParameters([ + new Model\Parameter( + 'query', + 'query', + 'Search query parameter', + true, + false, + ), + ]) + )); + } } \ No newline at end of file diff --git a/translations/validators.en.yaml b/translations/validators.en.yaml index e205608..e5b6e69 100644 --- a/translations/validators.en.yaml +++ b/translations/validators.en.yaml @@ -9,5 +9,31 @@ validators: not_null: 'The organizational unit should not be null.' view: + name: + not_blank: 'The name should not be blank.' + + hardware: + name: + not_blank: 'The name should not be blank.' + type: + not_null: 'The type should not be null.' + + hardware_type: + name: + not_blank: 'The name should not be blank.' + + image: + name: + not_blank: 'The name should not be blank.' + + network_settings: + ip_address: + invalid: 'The IP address "{{ value }}" is not valid.' + p2p_time: + invalid: 'The P2P time "{{ value }}" is not valid.' + mcast_speed: + invalid: 'The MCAST speed "{{ value }}" is not valid.' + + operative_system: name: not_blank: 'The name should not be blank.' \ No newline at end of file diff --git a/translations/validators.es.yaml b/translations/validators.es.yaml index 732c4f0..9bf6d15 100644 --- a/translations/validators.es.yaml +++ b/translations/validators.es.yaml @@ -9,5 +9,31 @@ validators: not_null: 'La unidad organizativa no debería estar vacía.' view: + name: + not_blank: 'El nombre no debería estar vacío.' + + hardware: + name: + not_blank: 'El nombre no debería estar vacío.' + type: + not_null: 'El tipo no debería estar vacío.' + + hardware_type: + name: + not_blank: 'El nombre no debería estar vacío.' + + image: + name: + not_blank: 'El nombre no debería estar vacío.' + + network_settings: + ip_address: + invalid: 'La dirección IP "{{ value }}" no es válida.' + p2p_time: + invalid: 'El tiempo P2P "{{ value }}" no es válido.' + mcast_speed: + invalid: 'La velocidad MCAST "{{ value }}" no es válida.' + + operative_system: name: not_blank: 'El nombre no debería estar vacío.' \ No newline at end of file