|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Fixtures\TestBundle\Document; |
| 15 | + |
| 16 | +use ApiPlatform\Doctrine\Odm\Filter\FreeTextQueryFilter; |
| 17 | +use ApiPlatform\Doctrine\Odm\Filter\OrFilter; |
| 18 | +use ApiPlatform\Doctrine\Odm\Filter\PartialSearchFilter; |
| 19 | +use ApiPlatform\Metadata\ApiResource; |
| 20 | +use ApiPlatform\Metadata\GetCollection; |
| 21 | +use ApiPlatform\Metadata\QueryParameter; |
| 22 | +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
| 23 | + |
| 24 | +#[ODM\Document] |
| 25 | +#[ApiResource( |
| 26 | + shortName: 'PostCard', |
| 27 | + operations: [ |
| 28 | + new GetCollection( |
| 29 | + uriTemplate: '/post_cards_embedded', |
| 30 | + normalizationContext: ['hydra_prefix' => false], |
| 31 | + parameters: [ |
| 32 | + 'citySearch' => new QueryParameter( |
| 33 | + filter: new PartialSearchFilter(), |
| 34 | + property: 'address.city', |
| 35 | + ), |
| 36 | + 'freeSearch' => new QueryParameter( |
| 37 | + filter: new FreeTextQueryFilter(new OrFilter(new PartialSearchFilter())), |
| 38 | + properties: ['address.city', 'address.street'], |
| 39 | + ), |
| 40 | + ], |
| 41 | + ), |
| 42 | + ] |
| 43 | +)] |
| 44 | +class PostCard |
| 45 | +{ |
| 46 | + #[ODM\Id(type: 'string', strategy: 'INCREMENT')] |
| 47 | + private ?string $id = null; |
| 48 | + |
| 49 | + #[ODM\Field(type: 'string')] |
| 50 | + private string $title; |
| 51 | + |
| 52 | + #[ODM\EmbedOne(targetDocument: PostCardAddress::class)] |
| 53 | + private PostCardAddress $address; |
| 54 | + |
| 55 | + public function __construct() |
| 56 | + { |
| 57 | + $this->address = new PostCardAddress(); |
| 58 | + } |
| 59 | + |
| 60 | + public function getId(): ?string |
| 61 | + { |
| 62 | + return $this->id; |
| 63 | + } |
| 64 | + |
| 65 | + public function getTitle(): string |
| 66 | + { |
| 67 | + return $this->title; |
| 68 | + } |
| 69 | + |
| 70 | + public function setTitle(string $title): self |
| 71 | + { |
| 72 | + $this->title = $title; |
| 73 | + |
| 74 | + return $this; |
| 75 | + } |
| 76 | + |
| 77 | + public function getAddress(): PostCardAddress |
| 78 | + { |
| 79 | + return $this->address; |
| 80 | + } |
| 81 | + |
| 82 | + public function setAddress(PostCardAddress $address): self |
| 83 | + { |
| 84 | + $this->address = $address; |
| 85 | + |
| 86 | + return $this; |
| 87 | + } |
| 88 | +} |
0 commit comments