src/Dto/SearchResult.php line 11

  1. <?php
  2. namespace App\Dto;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use App\Entity\ApiToken;
  6. use App\State\GlobalSearchProvider;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. #[ApiResource(
  9.     description'Búsqueda global en el sistema',
  10.     operations: [
  11.         new GetCollection(
  12.             uriTemplate'/search',
  13.             normalizationContext: ['groups' => ['search:read']],
  14.             security'is_granted("' ApiToken::SCOPE_USER_READ '")',
  15.             providerGlobalSearchProvider::class,
  16.             openapiContext: [
  17.                 'summary' => 'Búsqueda global por nombre y descripción',
  18.                 'parameters' => [
  19.                     [
  20.                         'name' => 'q',
  21.                         'in' => 'query',
  22.                         'required' => true,
  23.                         'schema' => [
  24.                             'type' => 'string'
  25.                         ],
  26.                         'description' => 'Término de búsqueda'
  27.                     ],
  28.                     [
  29.                         'name' => 'limit',
  30.                         'in' => 'query',
  31.                         'required' => false,
  32.                         'schema' => [
  33.                             'type' => 'integer',
  34.                             'default' => 25
  35.                         ],
  36.                         'description' => 'Número máximo de resultados'
  37.                     ]
  38.                 ]
  39.             ]
  40.         )
  41.     ]
  42. )]
  43. class SearchResult
  44. {
  45.     #[Groups(['search:read'])]
  46.     private string $type;
  47.     #[Groups(['search:read'])]
  48.     private string $id;
  49.     #[Groups(['search:read'])]
  50.     private string $nombre;
  51.     #[Groups(['search:read'])]
  52.     private ?string $descripcion null;
  53.     #[Groups(['search:read'])]
  54.     private ?array $metadata null;
  55.     public function __construct(
  56.         string $type,
  57.         string $id,
  58.         string $nombre,
  59.         ?string $descripcion null,
  60.         ?array $metadata null
  61.     ) {
  62.         $this->type $type;
  63.         $this->id $id;
  64.         $this->nombre $nombre;
  65.         $this->descripcion $descripcion;
  66.         $this->metadata $metadata;
  67.     }
  68.     public function getType(): string
  69.     {
  70.         return $this->type;
  71.     }
  72.     public function setType(string $type): self
  73.     {
  74.         $this->type $type;
  75.         return $this;
  76.     }
  77.     public function getId(): string
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function setId(string $id): self
  82.     {
  83.         $this->id $id;
  84.         return $this;
  85.     }
  86.     public function getNombre(): string
  87.     {
  88.         return $this->nombre;
  89.     }
  90.     public function setNombre(string $nombre): self
  91.     {
  92.         $this->nombre $nombre;
  93.         return $this;
  94.     }
  95.     public function getDescripcion(): ?string
  96.     {
  97.         return $this->descripcion;
  98.     }
  99.     public function setDescripcion(?string $descripcion): self
  100.     {
  101.         $this->descripcion $descripcion;
  102.         return $this;
  103.     }
  104.     public function getMetadata(): ?array
  105.     {
  106.         return $this->metadata;
  107.     }
  108.     public function setMetadata(?array $metadata): self
  109.     {
  110.         $this->metadata $metadata;
  111.         return $this;
  112.     }
  113. }