Skip to content

Commit 4009120

Browse files
committed
fix(metadata): add tests for nested property filtering with non-ApiResource entities
#7916
1 parent 14a3d52 commit 4009120

5 files changed

Lines changed: 416 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17+
18+
#[ODM\Document]
19+
class NonResourceRelation
20+
{
21+
#[ODM\Id(type: 'string', strategy: 'INCREMENT')]
22+
private ?string $id = null;
23+
24+
#[ODM\Field(type: 'string')]
25+
private string $name = '';
26+
27+
#[ODM\Field(type: 'string')]
28+
private string $category = '';
29+
30+
public function getId(): ?string
31+
{
32+
return $this->id;
33+
}
34+
35+
public function getName(): string
36+
{
37+
return $this->name;
38+
}
39+
40+
public function setName(string $name): self
41+
{
42+
$this->name = $name;
43+
44+
return $this;
45+
}
46+
47+
public function getCategory(): string
48+
{
49+
return $this->category;
50+
}
51+
52+
public function setCategory(string $category): self
53+
{
54+
$this->category = $category;
55+
56+
return $this;
57+
}
58+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\Entity;
15+
16+
use Doctrine\ORM\Mapping as ORM;
17+
18+
#[ORM\Entity]
19+
class NonResourceRelation
20+
{
21+
#[ORM\Id]
22+
#[ORM\GeneratedValue]
23+
#[ORM\Column(type: 'integer')]
24+
private ?int $id = null;
25+
26+
#[ORM\Column(length: 255)]
27+
private string $name = '';
28+
29+
#[ORM\Column(length: 255)]
30+
private string $category = '';
31+
32+
public function getId(): ?int
33+
{
34+
return $this->id;
35+
}
36+
37+
public function getName(): string
38+
{
39+
return $this->name;
40+
}
41+
42+
public function setName(string $name): self
43+
{
44+
$this->name = $name;
45+
46+
return $this;
47+
}
48+
49+
public function getCategory(): string
50+
{
51+
return $this->category;
52+
}
53+
54+
public function setCategory(string $category): self
55+
{
56+
$this->category = $category;
57+
58+
return $this;
59+
}
60+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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\Entity;
15+
16+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Metadata\GetCollection;
19+
use ApiPlatform\Metadata\QueryParameter;
20+
use Doctrine\ORM\Mapping as ORM;
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+
#[ORM\Entity]
41+
class ResourceWithNonResourceRelation
42+
{
43+
#[ORM\Id]
44+
#[ORM\GeneratedValue]
45+
#[ORM\Column(type: 'integer')]
46+
private ?int $id = null;
47+
48+
#[ORM\Column(length: 255)]
49+
private string $title = '';
50+
51+
#[ORM\ManyToOne(targetEntity: NonResourceRelation::class)]
52+
private ?NonResourceRelation $nonResourceRelation = null;
53+
54+
public function getId(): ?int
55+
{
56+
return $this->id;
57+
}
58+
59+
public function getTitle(): string
60+
{
61+
return $this->title;
62+
}
63+
64+
public function setTitle(string $title): self
65+
{
66+
$this->title = $title;
67+
68+
return $this;
69+
}
70+
71+
public function getNonResourceRelation(): ?NonResourceRelation
72+
{
73+
return $this->nonResourceRelation;
74+
}
75+
76+
public function setNonResourceRelation(?NonResourceRelation $nonResourceRelation): self
77+
{
78+
$this->nonResourceRelation = $nonResourceRelation;
79+
80+
return $this;
81+
}
82+
}

0 commit comments

Comments
 (0)