如何解决属性受限的操作/ GET
当然已经问过了,但是... 有这个实体
/**
* A form
*
* @ORM\Entity(repositoryClass=FormRepository::class)
*
* @ORM\Table(
* name="forms",* options={"comment":"Table of the forms"},* indexes={
* @ORM\Index(name="forms_idx_dofc",columns={"dateofcreation"}),* @ORM\Index(name="forms_idx_dofu",columns={"dateofupdate"}),* @ORM\Index(name="forms_idx_dofs",columns={"dateofsubmission"})
* }
* )
*
* @ApiResource(
* routePrefix="/",* shortName="Forms",* description="API Access : form Entity",* collectionoperations={"GET"},* itemOperations={"GET"},* attributes={
* "normalization_context"={
* "groups"={
* "GET:FORM"
* }
* },* "order"={
* "dateofsubmission",* "dateofupdate",* "dateofcreation"
* }
* }
* )
*
*/
class Form
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer",options={"comment":"Primary Key,Auto generated"})
*/
private $id;
/**
* @var datetime Date of creation of the form.
*
* @ORM\Column(type="datetime",options={"comment":"date of creation of the form"})
*
* @Assert\NotBlank(message="The date time when was created the form should not be blank")
* @Assert\DateTime(message="The data time when was created the form should be the type DateTime")
*
* @Groups({"GET:FORM"})
*
* @ApiFilter(OrderFilter::class,strategy="ASC")
*/
private $dateofcreation;
/**
* @var datetime Date of update of the form.
*
* @ORM\Column(type="datetime",options={"comment":"date of update of the form"})
*
* @Assert\NotBlank(message="The date time when was updated the form should not be blank")
* @Assert\DateTime(message="The data time when was updated the form should be the type DateTime")
*
* @Groups({"GET:FORM"})
*
* @ApiFilter(OrderFilter::class,strategy="ASC")
*/
private $dateofupdate;
/**
* @var person Person that has created the form.
*
* @ORM\ManyToOne(targetEntity=Person::class,inversedBy="forms")
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"GET:FORM"})
*
* @ApiFilter(SearchFilter::class,properties={"createdBy.id":"exact","createdBy.givenname":"ipartial","createdBy.familyname":"ipartial"})
* @ApiFilter(OrderFilter::class,strategy="ASC")
*/
private $createdBy;
...
我希望有: 基本collectionoperations“ GET”将返回所有具有@ GROUP = GET:FORM
的属性备用collectionoperations“ GETDATES”将返回所有具有@ GROUP = GET:DATES的属性
可以(最好)通过不同的路径访问这些操作。
GET =>#http:// api / forms?createdBy.id = 25 =>所有属性
GETDATES => http:// api / formsLimited?createdBy.id = 25 =>仅日期
ps:我希望这样做对可读性更好。
解决方法
感谢GrégoireHébert(https://stackoverflow.com/users/4887997/gr%C3%A9goire-hebert)的支持(在Slack上)。 解决方案非常简单。 在ApiResource()中创建具有以下内容的收集操作:
- 方法=获取
- 路径(将成为路线)
- 要应用于所需属性的组的规范化上下文
它给出:
collectionOperations={"GET","GETLIMITED"={"method"="GET","path"="formslist","normalization_context"={"groups"="GET:LIMITED"}}},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。