Skip to content

Commit

Permalink
added return not_found status
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey18106 committed Jul 21, 2023
1 parent 125acee commit cd0cdf8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/Controller/AppConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function setAppConfigValue(string $configKey, mixed $configValue, string
public function getAppConfigValues(array $configKeys, string $format = 'json'): Response {
$appId = $this->request->getHeader('EX-APP-ID');
$result = $this->exAppConfigService->getAppConfigValues($appId, $configKeys);
return $this->buildResponse(new DataResponse($result, Http::STATUS_OK), $format);
return $this->buildResponse(new DataResponse($result, !empty($result) ? Http::STATUS_OK : Http::STATUS_NOT_FOUND), $format);
}

/**
Expand All @@ -119,9 +119,9 @@ public function getAppConfigValues(array $configKeys, string $format = 'json'):
public function deleteAppConfigValues(array $configKeys, string $format = 'json'): Response {
$appId = $this->request->getHeader('EX-APP-ID');
$result = $this->exAppConfigService->deleteAppConfigValues($configKeys, $appId);
if ($result !== -1) {
return $this->buildResponse(new DataResponse($result, Http::STATUS_OK), $format);
if ($result === -1) {
throw new OCSBadRequestException('Error deleting app config values');
}
throw new OCSBadRequestException('Error deleting app config values');
return $this->buildResponse(new DataResponse($result, $result !== 0 ? Http::STATUS_OK : Http::STATUS_NOT_FOUND), $format);
}
}
5 changes: 5 additions & 0 deletions lib/Controller/OCSApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ public function registerFileActionMenu(array $fileActionMenuParams, string $form
public function unregisterFileActionMenu(string $fileActionMenuName, string $format = 'json'): Response {
$appId = $this->request->getHeader('EX-APP-ID');
$unregisteredFileActionMenu = $this->exFilesActionsMenuService->unregisterFileActionMenu($appId, $fileActionMenuName);
if ($unregisteredFileActionMenu === null) {
return $this->buildResponse(new DataResponse([
'error' => $this->l->t('FileActionMenu not found.'),
], Http::STATUS_NOT_FOUND), $format);
}
return $this->buildResponse(new DataResponse([
'success' => $unregisteredFileActionMenu !== null,
'unregisteredFileActionMenu' => $unregisteredFileActionMenu,
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/PreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getUserConfigValues(array $configKeys, string $format = 'json'):
$userId = $this->userSession->getUser()->getUID();
$appId = $this->request->getHeader('EX-APP-ID');
$result = $this->exAppPreferenceService->getUserConfigValues($userId, $appId, $configKeys);
return $this->buildResponse(new DataResponse($result, Http::STATUS_OK), $format);
return $this->buildResponse(new DataResponse($result, !empty($result) ? Http::STATUS_OK : Http::STATUS_NOT_FOUND), $format);
}

/**
Expand All @@ -126,9 +126,9 @@ public function deleteUserConfigValues(array $configKeys, string $format = 'json
$userId = $this->userSession->getUser()->getUID();
$appId = $this->request->getHeader('EX-APP-ID');
$result = $this->exAppPreferenceService->deleteUserConfigValues($configKeys, $userId, $appId);
if ($result !== -1) {
return $this->buildResponse(new DataResponse($result, Http::STATUS_OK), $format);
if ($result === -1) {
throw new OCSBadRequestException('Failed to delete user config values');
}
throw new OCSBadRequestException('Failed to delete user config values');
return $this->buildResponse(new DataResponse($result, $result !== 0 ? Http::STATUS_OK : Http::STATUS_NOT_FOUND), $format);
}
}
8 changes: 4 additions & 4 deletions lib/Service/ExAppConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getAppConfigValues(string $appId, array $configKeys): ?array {
}

/**
* Set app_config_ex value
* Set appconfig_ex value
*
* @param string $appId
* @param string $configKey
Expand All @@ -95,15 +95,15 @@ public function setAppConfigValue(string $appId, string $configKey, mixed $confi
'configvalue' => $configValue ?? '',
'sensitive' => $sensitive,
]));
} catch (\Exception $e) {
$this->logger->error('Error while inserting app_config_ex value: ' . $e->getMessage(), ['exception' => $e]);
} catch (Exception $e) {
$this->logger->error(sprintf('Failed to insert appconfig_ex value. Error: %s', $e->getMessage()), ['exception' => $e]);
return null;
}
} else {
$appConfigEx->setConfigvalue($configValue);
$appConfigEx->setSensitive($sensitive);
if ($this->updateAppConfigValue($appConfigEx) !== 1) {
$this->logger->error('Error while updating app_config_ex value');
$this->logger->error(sprintf('Error while updating appconfig_ex %s value.', $configKey));
return null;
}
}
Expand Down

0 comments on commit cd0cdf8

Please sign in to comment.