mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
GET for relationship fixed: associated relation displayed
This commit is contained in:
parent
18ca01b0dc
commit
b7466c7e85
@ -23,12 +23,6 @@ class RelationshipApiController extends ApiController
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function createEntity(string $action, Request $request): object
|
||||
{
|
||||
$relationship = parent::createEntity($action, $request);
|
||||
return $relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/relation/relationship/by-person/{person_id}.json",
|
||||
* name="chill_relation_relationship_by_person")
|
||||
@ -39,6 +33,7 @@ class RelationshipApiController extends ApiController
|
||||
{
|
||||
//TODO: add permissions? (voter?)
|
||||
$relationships = $this->repository->findByPerson($person);
|
||||
dump($relationships[0]->getRelation());
|
||||
|
||||
return $this->json(\array_values($relationships), Response::HTTP_OK, [], ['groups' => [ 'read']]);
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ class RelationshipRepository extends ServiceEntityRepository
|
||||
{
|
||||
// return all relationships of which person is part? or only where person is the fromPerson?
|
||||
return $this->createQueryBuilder('r')
|
||||
->andWhere('r.fromPerson = :val')
|
||||
->select('r, t') // entity Relationship
|
||||
->join('r.relation', 't')
|
||||
->where('r.fromPerson = :val')
|
||||
->orWhere('r.toPerson = :val')
|
||||
->setParameter('val', $personId)
|
||||
->getQuery()
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
||||
|
||||
class RelationshipNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
use ObjectToPopulateTrait;
|
||||
|
||||
use DenormalizerAwareTrait;
|
||||
|
||||
public function normalize($relationship, ?string $format = null, array $context = [])
|
||||
{
|
||||
return [
|
||||
'type' => 'relationship',
|
||||
'fromPerson' => $this->normalizer->normalize($relationship->getFromPerson()),
|
||||
'toPerson' => $this->normalizer->normalize($relationship->getToPerson()),
|
||||
'relation' => $this->normalizer->normalize($relationship->getRelation()),
|
||||
'reverse' => $relationship->getReverse()
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null)
|
||||
{
|
||||
return $data instanceof Relationship;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user