具有有限属性的操作/获取
Action / GET with limited properties
当然已经问过了,但是...
拥有这个实体
/**
* 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”将 return 所有具有 @GROUP=GET:FORM
的属性
备用 collectionOperations“GETDATES”将 return 所有具有 @GROUP=GET:DATES
的属性
可通过不同路线(理想情况下)访问这些操作。
GET => # http://api/forms?createdBy.id=25 => 所有属性
GETDATES => http://api/forms有限?createdBy.id=25 => 只有日期
ps:我希望这对可读性更好。
感谢 Grégoire Hébert(https://whosebug.com/users/4887997/gr%C3%A9goire-hebert) 的支持(在 Slack 上)。
解决方案非常简单。
在 ApiResource() 中创建一个集合操作:
- 方法=获取
- 路径(将成为路线)
- 要应用于所需属性的组的规范化上下文
它给出:
collectionOperations={"GET","GETLIMITED"={"method"="GET","path"="formslist","normalization_context"={"groups"="GET:LIMITED"}}},
当然已经问过了,但是... 拥有这个实体
/**
* 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”将 return 所有具有 @GROUP=GET:FORM
的属性备用 collectionOperations“GETDATES”将 return 所有具有 @GROUP=GET:DATES
的属性可通过不同路线(理想情况下)访问这些操作。
GET => # http://api/forms?createdBy.id=25 => 所有属性
GETDATES => http://api/forms有限?createdBy.id=25 => 只有日期
ps:我希望这对可读性更好。
感谢 Grégoire Hébert(https://whosebug.com/users/4887997/gr%C3%A9goire-hebert) 的支持(在 Slack 上)。 解决方案非常简单。 在 ApiResource() 中创建一个集合操作:
- 方法=获取
- 路径(将成为路线)
- 要应用于所需属性的组的规范化上下文
它给出:
collectionOperations={"GET","GETLIMITED"={"method"="GET","path"="formslist","normalization_context"={"groups"="GET:LIMITED"}}},