|
| 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\ApiResource\Issue7916; |
| 15 | + |
| 16 | +use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter; |
| 17 | +use ApiPlatform\Doctrine\Orm\State\Options; |
| 18 | +use ApiPlatform\Metadata\ApiResource; |
| 19 | +use ApiPlatform\Metadata\GetCollection; |
| 20 | +use ApiPlatform\Metadata\QueryParameter; |
| 21 | +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7916\UserAction; |
| 22 | + |
| 23 | +/** |
| 24 | + * API Resource DTO for UserAction using stateOptions pattern. |
| 25 | + * This is a separate API Resource for the UserAction entity which is NOT itself marked #[ApiResource]. |
| 26 | + * |
| 27 | + * Tests that nested property filters work on relations to non-ApiResource entities (User). |
| 28 | + * |
| 29 | + * @see https://github.com/api-platform/core/issues/7916 |
| 30 | + */ |
| 31 | +#[ApiResource( |
| 32 | + operations: [ |
| 33 | + new GetCollection( |
| 34 | + uriTemplate: '/user-actions', |
| 35 | + parameters: [ |
| 36 | + 'name' => new QueryParameter( |
| 37 | + filter: new PartialSearchFilter(), |
| 38 | + property: 'user.name', |
| 39 | + ), |
| 40 | + 'email' => new QueryParameter( |
| 41 | + filter: new PartialSearchFilter(), |
| 42 | + property: 'user.email', |
| 43 | + ), |
| 44 | + ], |
| 45 | + ), |
| 46 | + ], |
| 47 | + stateOptions: new Options(entityClass: UserAction::class), |
| 48 | +)] |
| 49 | +class UserActionResource |
| 50 | +{ |
| 51 | + public ?int $id = null; |
| 52 | + public ?string $action = null; |
| 53 | +} |
0 commit comments