-
-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(metadata): try to improve handling of stateOptions
- Loading branch information
1 parent
99262dc
commit 11cc1e5
Showing
6 changed files
with
440 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter; | ||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata\ApiFilter; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Agent; | ||
use Symfony\Component\Serializer\Attribute\Groups; | ||
|
||
#[ApiFilter(DateFilter::class, properties: ['birthday'], alias: 'app_filter_date')] | ||
#[ApiResource( | ||
shortName: 'Agent', | ||
operations: [ | ||
new GetCollection(parameters: [ | ||
'bla[:property]' => new QueryParameter(filter: 'app_filter_date'), | ||
]), | ||
], | ||
stateOptions: new Options(entityClass: Agent::class) | ||
)] | ||
#[ApiFilter(DateFilter::class, properties: ['birthday'])] | ||
#[ApiResource( | ||
shortName: 'AgentSimple', | ||
operations: [ | ||
new GetCollection(), | ||
], | ||
stateOptions: new Options(entityClass: Agent::class) | ||
)] | ||
class AgentApi | ||
{ | ||
#[Groups(['agent:read'])] | ||
private ?int $id = null; | ||
|
||
#[Groups(['agent:read', 'agent:write'])] | ||
private ?string $name = null; | ||
|
||
#[Groups(['agent:read', 'agent:write'])] | ||
private ?\DateTimeInterface $birthday = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(?int $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getBirthday(): ?\DateTimeInterface | ||
{ | ||
return $this->birthday; | ||
} | ||
|
||
public function setBirthday(?\DateTimeInterface $birthday): self | ||
{ | ||
$this->birthday = $birthday; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
#[ODM\Document] | ||
class AgentDocument | ||
{ | ||
#[ODM\Id(strategy: 'INCREMENT', type: 'int')] | ||
public ?int $id = null; | ||
|
||
#[ODM\Field] | ||
public ?string $name = null; | ||
|
||
#[ODM\Field] | ||
public ?string $apiKey = null; | ||
|
||
#[ODM\Field] | ||
public ?\DateTimeImmutable $createdAt = null; | ||
|
||
#[ODM\Field] | ||
public ?\DateTimeImmutable $birthday = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(int $id): static | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): static | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getApiKey(): ?string | ||
{ | ||
return $this->apiKey; | ||
} | ||
|
||
public function setApiKey(string $apiKey): static | ||
{ | ||
$this->apiKey = $apiKey; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCreatedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
public function setCreatedAt(\DateTimeImmutable $createdAt): static | ||
{ | ||
$this->createdAt = $createdAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function getBirthday(): ?\DateTimeImmutable | ||
{ | ||
return $this->birthday; | ||
} | ||
|
||
public function setBirthday(\DateTimeImmutable $birthday): static | ||
{ | ||
$this->birthday = $birthday; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
class Agent | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
public ?int $id = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
public ?string $name = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
public ?string $apiKey = null; | ||
|
||
#[ORM\Column] | ||
public ?\DateTimeImmutable $createdAt = null; | ||
|
||
#[ORM\Column] | ||
public ?\DateTimeImmutable $birthday = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(int $id): static | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): static | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getApiKey(): ?string | ||
{ | ||
return $this->apiKey; | ||
} | ||
|
||
public function setApiKey(string $apiKey): static | ||
{ | ||
$this->apiKey = $apiKey; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCreatedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->createdAt; | ||
} | ||
|
||
public function setCreatedAt(\DateTimeImmutable $createdAt): static | ||
{ | ||
$this->createdAt = $createdAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function getBirthday(): ?\DateTimeImmutable | ||
{ | ||
return $this->birthday; | ||
} | ||
|
||
public function setBirthday(\DateTimeImmutable $birthday): static | ||
{ | ||
$this->birthday = $birthday; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.