add a patch resource api endpoint (wip)

This commit is contained in:
Mathieu Jaumotte 2022-01-04 19:37:27 +01:00
parent af2eca0d03
commit 4f1540c541
5 changed files with 94 additions and 2 deletions

View File

@ -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',

View File

@ -47,7 +47,7 @@ class Resource
* @ORM\Column(type="text", nullable=true)
* @Groups({"read", "write"})
*/
private string $comment = '';
private ?string $comment = '';
/**
* @ORM\Id

View File

@ -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
*/

View File

@ -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);

View File

@ -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: