From 902c45f0cd012a63768dfa375c95fc8febad1e89 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 20 Oct 2021 13:11:58 +0200 Subject: [PATCH] endpoint created for acc periods by-person --- .../AccompanyingCourseApiController.php | 25 ++++++++++++++++++- .../ChillPersonExtension.php | 8 ++++++ .../ChillPersonBundle/chill.api.specs.yaml | 23 +++++++++++++++++ .../config/services/controller.yaml | 10 +++++--- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 8201752af..e7243fba1 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -18,7 +18,11 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\MainBundle\Entity\Scope; +use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository; +use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Symfony\Component\Workflow\Registry; +use Symfony\Component\Routing\Annotation\Route; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; class AccompanyingCourseApiController extends ApiController { @@ -28,14 +32,18 @@ class AccompanyingCourseApiController extends ApiController private Registry $registry; + private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository; + public function __construct( EventDispatcherInterface $eventDispatcher, ValidatorInterface $validator, - Registry $registry + Registry $registry, + AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository ) { $this->eventDispatcher = $eventDispatcher; $this->validator = $validator; $this->registry = $registry; + $this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository; } public function confirmApi($id, Request $request, $_format): Response @@ -187,4 +195,19 @@ $workflow = $this->registry->get($accompanyingPeriod); return null; } + + /** + * @Route("/api/1.0/person/accompanying-course/by-person/{person_id}.{_format}", + * name="chill_person_accompanyingperiod_by_person", + * requirements={ + * "_format"="json" + * }) + * + * @ParamConverter("person", options={"id" = "person_id"}) + */ + public function getAccompanyingPeriodsByPerson(Person $person){ + $accompanyingPeriods = $person->getAccompanyingPeriods(); + return $this->json(\array_values($accompanyingPeriods), Response::HTTP_OK, [], ['groups' => [ 'read']]); + } + } diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index bc3b798fa..1dd1a7979 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -585,6 +585,14 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE, ] ], + 'findAccompanyingPeriodsByPerson' => [ + 'path' => '/by-person/{person_id}.{_format}', + 'controller_action' => 'findAccompanyingPeriodsByPerson', + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ] + ] ] ], [ diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 4041c52b7..5d3f07259 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -1058,6 +1058,29 @@ paths: description: "OK" 400: description: "transition cannot be applyed" + + /1.0/person/accompanying-course/by-person/{person_id}.json: + get: + tags: + - accompanying period + summary: get a list of accompanying periods for a person + description: Returns a list of the current accompanying periods for a person + parameters: + - name: person_id + in: path + required: true + description: The person id + schema: + type: integer + format: integer + minimum: 1 + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" /1.0/person/accompanying-period/origin.json: get: diff --git a/src/Bundle/ChillPersonBundle/config/services/controller.yaml b/src/Bundle/ChillPersonBundle/config/services/controller.yaml index 489168425..c61362583 100644 --- a/src/Bundle/ChillPersonBundle/config/services/controller.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/controller.yaml @@ -41,10 +41,12 @@ services: tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\AccompanyingCourseApiController: - arguments: - $eventDispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' - $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' - $registry: '@Symfony\Component\Workflow\Registry' + autowire: true + autoconfigure: true + # arguments: + # $eventDispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' + # $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' + # $registry: '@Symfony\Component\Workflow\Registry' tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\PersonApiController: