GET and POST both working.

This commit is contained in:
Julie Lenaerts 2021-10-29 09:29:27 +02:00
parent 69e3a0a6cd
commit 3a7af94058
5 changed files with 68 additions and 34 deletions

View File

@ -32,8 +32,6 @@ class AccompanyingCourseApiController extends ApiController
private Registry $registry; private Registry $registry;
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
public function __construct( public function __construct(
EventDispatcherInterface $eventDispatcher, EventDispatcherInterface $eventDispatcher,
ValidatorInterface $validator, ValidatorInterface $validator,

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
class LoadRelationships extends Fixture implements DependentFixtureInterface
{
public function getDependencies()
{
}
public function load(ObjectManager $manager)
{
}
}

View File

@ -879,14 +879,10 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
'actions' => [ 'actions' => [
'_entity' => [ '_entity' => [
'methods' => [ 'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
Request::METHOD_POST => true, Request::METHOD_POST => true,
Request::METHOD_PATCH => true Request::METHOD_PATCH => true
], ],
'roles' => [ 'roles' => [
Request::METHOD_GET => 'ROLE_USER',
Request::METHOD_HEAD => 'ROLE_USER',
Request::METHOD_POST => 'ROLE_USER', Request::METHOD_POST => 'ROLE_USER',
Request::METHOD_PATCH => 'ROLE_USER' Request::METHOD_PATCH => 'ROLE_USER'
] ]

View File

@ -3,10 +3,16 @@
namespace Chill\PersonBundle\Entity\Relationships; namespace Chill\PersonBundle\Entity\Relationships;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="chill_person_relations") * @ORM\Table(name="chill_person_relations")
* @DiscriminatorMap(typeProperty="type", mapping={
* "relation"=Relation::class
* })
*/ */
class Relation class Relation
{ {
@ -15,17 +21,19 @@ class Relation
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
*/ */
private $id; private ?int $id = null;
/** /**
* @ORM\Column(type="json", nullable=true) * @ORM\Column(type="json", nullable=true)
* @Serializer\Groups({"read"})
*/ */
private $title = []; private array $title = [];
/** /**
* @ORM\Column(type="json", nullable=true) * @ORM\Column(type="json", nullable=true)
* @Serializer\Groups({"read"})
*/ */
private $reverseTitle = []; private array $reverseTitle = [];
public function getId(): ?int public function getId(): ?int
{ {

View File

@ -2,50 +2,60 @@
namespace Chill\PersonBundle\Entity\Relationships; namespace Chill\PersonBundle\Entity\Relationships;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relation; use Chill\PersonBundle\Entity\Relationships\Relation;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="chill_person_relationships") * @ORM\Table(name="chill_person_relationships")
* @DiscriminatorColumn(name="relation_id", type="integer")
* @DiscriminatorMap(typeProperty="type", mapping={
* "relationship"=Relationship::class
* })
*
*/ */
class Relationship class Relationship implements TrackCreationInterface, TrackUpdateInterface
{ {
/** /**
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Groups({"read"}) * @Serializer\Groups({"read"})
*/ */
private $id; private ?int $id = null;
/** /**
* @ORM\ManyToOne(targetEntity=Person::class) * @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank() * @Assert\NotNull()
* @Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})
*/ */
private $fromPerson; private ?Person $fromPerson = null;
/** /**
* @ORM\ManyToOne(targetEntity=Person::class) * @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank() * @Assert\NotNull()
* @Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})
*/ */
private $toPerson; private ?Person $toPerson = null;
/** /**
* @ORM\ManyToOne(targetEntity=Relation::class) * @ORM\ManyToOne(targetEntity=Relation::class)
* @ORM\JoinColumn(nullable=false, name="relation_id", referencedColumnName="id") * @ORM\JoinColumn(nullable=false, name="relation_id", referencedColumnName="id")
* @Assert\NotBlank() * @Assert\NotNull()
* @Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})
*/ */
private $relation; private ?Relation $relation = null;
/** /**
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
@ -53,30 +63,30 @@ class Relationship
* type="bool", * type="bool",
* message="This must be of type boolean" * message="This must be of type boolean"
* ) * )
* @Groups({"read"}) * @Serializer\Groups({"read", "write"})
*/ */
private $reverse; private bool $reverse;
/** /**
* @ORM\ManyToOne(targetEntity=User::class) * @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
private $createdBy; private ?User $createdBy = null;
/** /**
* @ORM\Column(type="datetime_immutable") * @ORM\Column(type="datetime_immutable")
*/ */
private $createdAt; private ?DateTimeImmutable $createdAt = null;
/** /**
* @ORM\ManyToOne(targetEntity=User::class) * @ORM\ManyToOne(targetEntity=User::class)
*/ */
private $updatedBy; private ?User $updatedBy = null;
/** /**
* @ORM\Column(type="datetime_immutable", nullable=true) * @ORM\Column(type="datetime_immutable", nullable=true)
*/ */
private $updatedAt; private ?DateTimeImmutable $updatedAt = null;
public function getId(): ?int public function getId(): ?int
@ -125,9 +135,9 @@ class Relationship
return $this->createdBy; return $this->createdBy;
} }
public function setCreatedBy(?User $createdBy): self public function setCreatedBy(?User $user): self
{ {
$this->createdBy = $createdBy; $this->createdBy = $user;
return $this; return $this;
} }
@ -137,7 +147,7 @@ class Relationship
return $this->createdAt; return $this->createdAt;
} }
public function setCreatedAt(\DateTimeImmutable $createdAt): self public function setCreatedAt(\DateTimeInterface $createdAt): self
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
@ -161,7 +171,7 @@ class Relationship
return $this->updatedAt; return $this->updatedAt;
} }
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{ {
$this->updatedAt = $updatedAt; $this->updatedAt = $updatedAt;