diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 000720a7f..c8061195b 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -413,6 +413,25 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac ], ], ], + [ + 'class' => \Chill\PersonBundle\Entity\AccompanyingPeriod\Resource::class, + 'name' => 'accompanying_period_resource', + 'base_path' => '/api/1.0/person/accompanying-period/resource', + 'base_role' => 'ROLE_USER', + 'actions' => [ + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => false, + Request::METHOD_PATCH => true, + Request::METHOD_HEAD => false, + Request::METHOD_DELETE => false, + ], + 'roles' => [ + //Request::METHOD_PATCH => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE + ], + ], + ], + ], [ 'class' => \Chill\PersonBundle\Entity\AccompanyingPeriod\Origin::class, 'name' => 'accompanying_period_origin', diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php index c7285a7b0..51ed4bb63 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php @@ -47,7 +47,7 @@ class Resource * @ORM\Column(type="text", nullable=true) * @Groups({"read", "write"}) */ - private string $comment = ''; + private ?string $comment = ''; /** * @ORM\Id diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index d092adb0b..2acf3b749 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -353,6 +353,23 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise]) throw error; }) }, + patchResource({ commit }, payload) { + const body = { type: "accompanying_period_resource" }; + body['resource'] = { + type: payload.result.type, + id: payload.result.id + }; + const url = `/api/1.0/person/accompanying-course/resource/${id}.json`; + + return makeFetch('PATCH', url, body) + .then((response) => { + commit('patchResource', response); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + }, /** * On The Fly */ diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodResourceNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodResourceNormalizer.php index cb883542a..bcce13321 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodResourceNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodResourceNormalizer.php @@ -38,6 +38,15 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface $this->repository = $repository; } + public function normalize($resource, $format = null, array $context = []) + { + return [ + 'type' => 'accompanying_period_resource', + 'id' => $resource->getId(), + 'comment' => $resource->getComment() + ]; + } + public function denormalize($data, $type, $format = null, array $context = []) { $resource = $this->extractObjectToPopulate($type, $context); diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 218904e5e..90228492c 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -752,7 +752,6 @@ paths: resource: type: thirdparty id: 100 - responses: 401: description: "Unauthorized" @@ -1234,6 +1233,54 @@ paths: 404: description: "Not found" + /1.0/person/accompanying-period/resource/{id}.json: + patch: + tags: + - accompanying-course-resource + summary: "Alter the resource" + parameters: + - name: id + in: path + required: true + description: The resource's id + schema: + type: integer + format: integer + minimum: 1 + requestBody: + description: "A resource" + required: true + content: + application/json: + schema: + type: object + properties: + type: + type: string + enum: + - "accompanying_period_resource" + #id: + # type: integer + comment: + type: string + required: + - type + examples: + Set the resource comment: + value: + type: accompanying_period_resource + #id: 0 + comment: my judicious comment + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + 422: + description: "object with validation errors" + /1.0/person/household.json: get: tags: