Skip to content

Instantly share code, notes, and snippets.

@bendavies
Last active March 20, 2018 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendavies/f1895a4089035d754b099d7b69a04c39 to your computer and use it in GitHub Desktop.
Save bendavies/f1895a4089035d754b099d7b69a04c39 to your computer and use it in GitHub Desktop.
{
"_embedded": {
"parent": {
"_links": {
"self": {
"href": "/divisions/b76de4be-d59e-4562-b99c-78dafd04eef2"
}
},
"id": "b76de4be-d59e-4562-b99c-78dafd04eef2",
"name": "Parent",
}
},
"_links": {
"parent": {
"href": "/divisions/b76de4be-d59e-4562-b99c-78dafd04eef2"
},
"self": {
"href": "/divisions/eb336846-faa9-49f2-b99c-dc811b0a2fbd"
}
},
"id": "eb336846-faa9-49f2-b99c-dc811b0a2fbd",
"name": "Child"
}
{
"_links": {
"parent": {
"href": "/divisions/b76de4be-d59e-4562-b99c-78dafd04eef2"
},
"self": {
"href": "/divisions/eb336846-faa9-49f2-b99c-dc811b0a2fbd"
}
},
"id": "eb336846-faa9-49f2-b99c-dc811b0a2fbd",
"name": "Child"
}
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* collectionOperations={
* "get" = {"method" = "GET", "path" = "/divisions/", "normalization_context" = {"groups" = {"division"}}}
* },
* itemOperations={
* "get" = {"method" = "GET", "path" = "/divisions/{id}", "requirements" = {"id" = "%uuid_regex%"}, "normalization_context" = {"groups" = {"division"}}}
* }
* )
* @ORM\Entity
*/
class Division
{
/**
* @var Uuid
*
* @Groups("division")
*
* @ORM\Id
* @ORM\Column(type="guid")
* @ORM\GeneratedValue(strategy="NONE")
*/
protected $id;
/**
* @var string
*
* @Groups("division")
*
* @ORM\Column(type="string")
*/
protected $name;
/**
* @var Division
*
* @ApiProperty(readableLink=false)
* @Groups("division")
*
* @ORM\ManyToOne(targetEntity="App\Entity\Division", inversedBy="children")
*/
private $parent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment