Basée sur Symfony
/**
* @ORM\Entity(repositoryClass=RecipeRepository::class)
* @ApiResource()
* @ApiFilter(LimitGroupFilter::class)
*/
class Recipe
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read:recipe"})
* @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Groups({"read:recipe", "write:recipe"})
* @ApiFilter(SearchFilter::class, strategy="partial")
*/
private $name;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
* @Groups({"read:recipe:full", "write:recipe"})
*/
private $description;
/**
* @ORM\Column(type="datetime")
* @Groups({"read:recipe"})
*/
private $createdAt;
}
Il y a de nombreux moyens d'ajouter de la logique
Peut être intégré à une application "classique"
/**
* @ORM\Entity(repositoryClass=RecipeRepository::class)
* @ApiResource(
* attributes={"pagination_items_per_page"=10},
* normalizationContext={"groups"={"read:recipe", "read:category","read:recipe:list"}},
* denormalizationContext={"groups"={"write:recipe"}},
* itemOperations={
* "put",
* "delete",
* "get"={
* "normalization_context"={"groups"={"read:recipe", "read:recipe:full"}}
* }
* }
* )
* @ApiFilter(LimitGroupFilter::class)
*/
class Recipe
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read:recipe"})
* @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Groups({"read:recipe", "write:recipe"})
* @ApiFilter(SearchFilter::class, strategy="partial")
*/
private $name;
Il est difficile de choisir une approche
Attention à certaines requêtes SQL