Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Controller/EndpointsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ public function handlePath(string $_path): Response
);
}

// If no matching endpoints found, return 404
if (count($matchingEndpoints) > 1) {
return new JSONResponse(
data: ['error' => 'Multiple endpoints found for path and method: ' . $_path . ' ' . $this->request->getMethod()],
statusCode: 409
);
}

// Get the first matching endpoint since we have already filtered by method
$endpoint = reset($matchingEndpoints);

Expand Down
61 changes: 43 additions & 18 deletions lib/Service/EndpointService.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,24 +541,49 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri

// Route to appropriate ObjectService method based on HTTP method
try {
return match ($method) {
'GET' => new JSONResponse(
$this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status), statusCode: $status, headers: $headers
),
'POST' => new JSONResponse(
$this->replaceInternalReferences(mapper: $mapper, serializedObject: $mapper->createFromArray(object: $parameters))
),
'PUT' => new JSONResponse(
$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())
),
default => throw new Exception('Unsupported HTTP method')
};
switch ($method) {
case 'GET':
return new JSONResponse(
$this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status),
statusCode: $status,
headers: $headers
);
case 'POST':
return new JSONResponse(
$this->replaceInternalReferences(
mapper: $mapper,
serializedObject: $mapper->createFromArray(object: $parameters)
)
);
case 'PUT':
return new JSONResponse(
$this->replaceInternalReferences(
mapper: $mapper,
serializedObject: $mapper->updateFromArray($parameters['id'], $request->getParams(), true, false)
)
);
case 'PATCH':
return new JSONResponse(
$this->replaceInternalReferences(
mapper: $mapper,
serializedObject: $mapper->updateFromArray($parameters['id'], $request->getParams(), true, true)
)
);
case 'DELETE':
if (isset($parameters['id']) === false) {
return new JSONResponse(data: ['error' => 'No id given to delete'], statusCode: 400);
}

if ($mapper->delete(['id' => $parameters['id']]) !== true) {
return new JSONResponse(data: ['error' => sprintf('Something went wrong deleting object: %s', $parameters['id'])], statusCode: 500);
}

return new JSONResponse(statusCode: 200);

default:
throw new Exception('Unsupported HTTP method');
}

} catch (Exception $exception) {
if (in_array(get_class($exception), ['OCA\OpenRegister\Exception\ValidationException', 'OCA\OpenRegister\Exception\CustomValidationException']) === true) {
return $mapper->handleValidationException(exception: $exception);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,13 @@ private function updateTargetOpenRegister(SynchronizationContract $synchronizati
// Save the object to the target
switch ($action) {
case 'save':
$target = $objectService->saveObject($register, $schema, $targetObject);
$target = $objectService->saveObject(register: $register, schema: $schema, object: $targetObject);
// Get the id form the target object
$synchronizationContract->setTargetId($target->getUuid());

// Handle sub-objects synchronization if sourceConfig is defined
if (isset($sourceConfig['subObjects']) === true) {
$targetObject = $objectService->extendEntity($target->jsonSerialize(), ['all']);
$targetObject = $objectService->renderEntity($target->jsonSerialize(), ['all']);
$this->updateContractsForSubObjects(subObjectsConfig: $sourceConfig['subObjects'], synchronizationId: $synchronization->getId(), targetObject: $targetObject);
}

Expand Down