Skip to content

Commit

Permalink
Merge pull request #170 from ConductionNL/feature/CONNECTOR-181/Allow…
Browse files Browse the repository at this point in the history
…-Patch

Support PATCH method
  • Loading branch information
rjzondervan authored Jan 14, 2025
2 parents e2448e2 + 8528cf0 commit 9f70a48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// Running endpoints - allow any path after /api/endpoints/
['name' => 'endpoints#handlePath', 'postfix' => 'read', 'url' => '/api/endpoint/{_path}', 'verb' => 'GET', 'requirements' => ['_path' => '.+']],
['name' => 'endpoints#handlePath', 'postfix' => 'update', 'url' => '/api/endpoint/{_path}', 'verb' => 'PUT', 'requirements' => ['_path' => '.+']],
['name' => 'endpoints#handlePath', 'postfix' => 'partialupdate', 'url' => '/api/endpoint/{_path}', 'verb' => 'PATCH', 'requirements' => ['_path' => '.+']],
['name' => 'endpoints#handlePath', 'postfix' => 'create', 'url' => '/api/endpoint/{_path}', 'verb' => 'POST', 'requirements' => ['_path' => '.+']],
['name' => 'endpoints#handlePath', 'postfix' => 'destroy', 'url' => '/api/endpoint/{_path}', 'verb' => 'DELETE', 'requirements' => ['_path' => '.+']],
// Import & Export
Expand Down
8 changes: 7 additions & 1 deletion lib/Service/EndpointService.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri
}

$pathParams = $this->getPathParameters($endpoint->getEndpointArray(), $path);
if (isset($pathParams['id']) === true) {
$parameters['id'] = $pathParams['id'];
}

unset($parameters['_route'], $parameters['_path']);

Expand All @@ -323,8 +326,11 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri
$this->replaceInternalReferences(mapper: $mapper, serializedObject: $mapper->createFromArray(object: $parameters))
),
'PUT' => new JSONResponse(
$this->replaceInternalReferences(mapper: $mapper, serializedObject: $mapper->updateFromArray($request->getParams()['id'], $request->getParams(), true, true))
$this->replaceInternalReferences(mapper: $mapper, serializedObject: $mapper->updateFromArray($parameters['id'], $request->getParams(), true, false))
),
'PATCH' => new JSONResponse(
$this->replaceInternalReferences(mapper: $mapper, serializedObject: $mapper->updateFromArray($parameters['id'], $request->getParams(), true, true))
),
'DELETE' => new JSONResponse(
$mapper->delete($request->getParams())
),
Expand Down

0 comments on commit 9f70a48

Please sign in to comment.