|
| 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\PartialSearchFilter; |
| 17 | +use ApiPlatform\Metadata\ApiResource; |
| 18 | +use ApiPlatform\Metadata\GetCollection; |
| 19 | +use ApiPlatform\Metadata\QueryParameter; |
| 20 | +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
| 21 | + |
| 22 | +#[ApiResource( |
| 23 | + shortName: 'ResourceWithNonResourceRelation', |
| 24 | + operations: [ |
| 25 | + new GetCollection( |
| 26 | + uriTemplate: '/resources_with_non_resource_relations', |
| 27 | + parameters: [ |
| 28 | + 'name' => new QueryParameter( |
| 29 | + filter: new PartialSearchFilter(), |
| 30 | + property: 'nonResourceRelation.name', |
| 31 | + ), |
| 32 | + 'category' => new QueryParameter( |
| 33 | + filter: new PartialSearchFilter(), |
| 34 | + property: 'nonResourceRelation.category', |
| 35 | + ), |
| 36 | + ], |
| 37 | + ), |
| 38 | + ] |
| 39 | +)] |
| 40 | +#[ODM\Document] |
| 41 | +class ResourceWithNonResourceRelation |
| 42 | +{ |
| 43 | + #[ODM\Id(type: 'string', strategy: 'INCREMENT')] |
| 44 | + private ?string $id = null; |
| 45 | + |
| 46 | + #[ODM\Field(type: 'string')] |
| 47 | + private string $title = ''; |
| 48 | + |
| 49 | + #[ODM\ReferenceOne(targetDocument: NonResourceRelation::class, storeAs: 'id')] |
| 50 | + private ?NonResourceRelation $nonResourceRelation = null; |
| 51 | + |
| 52 | + public function getId(): ?string |
| 53 | + { |
| 54 | + return $this->id; |
| 55 | + } |
| 56 | + |
| 57 | + public function getTitle(): string |
| 58 | + { |
| 59 | + return $this->title; |
| 60 | + } |
| 61 | + |
| 62 | + public function setTitle(string $title): self |
| 63 | + { |
| 64 | + $this->title = $title; |
| 65 | + |
| 66 | + return $this; |
| 67 | + } |
| 68 | + |
| 69 | + public function getNonResourceRelation(): ?NonResourceRelation |
| 70 | + { |
| 71 | + return $this->nonResourceRelation; |
| 72 | + } |
| 73 | + |
| 74 | + public function setNonResourceRelation(?NonResourceRelation $nonResourceRelation): self |
| 75 | + { |
| 76 | + $this->nonResourceRelation = $nonResourceRelation; |
| 77 | + |
| 78 | + return $this; |
| 79 | + } |
| 80 | +} |
0 commit comments