diff --git a/appinfo/routes.php b/appinfo/routes.php index e18a428..fe07595 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -34,17 +34,17 @@ 'verb' => 'GET' ], [ - 'name' => 'data#listCollections', + 'name' => 'UserConfiguration#listCollections', 'url' => '/list-collections', 'verb' => 'GET' ], [ - 'name' => 'data#listFormats', + 'name' => 'UserConfiguration#listFormats', 'url' => '/list-formats', 'verb' => 'GET' ], [ - 'name' => 'data#listServices', + 'name' => 'UserConfiguration#listServices', 'url' => '/list-services', 'verb' => 'GET' ], diff --git a/lib/Controller/DataController.php b/lib/Controller/DataController.php index a4e41bb..26e74e8 100644 --- a/lib/Controller/DataController.php +++ b/lib/Controller/DataController.php @@ -20,11 +20,9 @@ class DataController extends Controller { use Errors; public function __construct(IRequest $request, - DataService $DataService, - string $userId) { + DataService $DataService) { parent::__construct(Application::APP_ID, $request); $this->DataService = $DataService; - $this->userId = $userId; } /** @@ -137,75 +135,4 @@ public function phone(string $id) { } - /** - * handels collections list requests - * - * @NoAdminRequired - * - * @return DataResponse - */ - public function listCollections(string $type): DataResponse { - - // evaluate if user id is present - if ($this->userId === null) { - return new DataResponse([], Http::STATUS_BAD_REQUEST); - } - // retrieve collections - $rs = $this->DataService->listCollections($this->userId, $type); - // return response - if (isset($rs)) { - return new DataResponse($rs); - } else { - return new DataResponse($rs['error'], 401); - } - - } - - /** - * handels formats list requests - * - * @NoAdminRequired - * - * @return DataResponse - */ - public function listFormats(string $type): DataResponse { - - // evaluate if user id is present - if ($this->userId === null) { - return new DataResponse([], Http::STATUS_BAD_REQUEST); - } - // retrieve formats - $rs = $this->DataService->listFormats($type); - // return response - if (isset($rs)) { - return new DataResponse($rs); - } else { - return new DataResponse($rs['error'], 401); - } - - } - - /** - * handels services list requests - * - * @NoAdminRequired - * - * @return DataResponse - */ - public function listServices(): DataResponse { - - // evaluate if user id is present - if ($this->userId === null) { - return new DataResponse([], Http::STATUS_BAD_REQUEST); - } - // retrieve formats - $rs = $this->DataService->listServices($this->userId); - // return response - if (isset($rs)) { - return new DataResponse($rs); - } else { - return new DataResponse($rs['error'], 401); - } - - } } diff --git a/lib/Controller/UserConfigurationController.php b/lib/Controller/UserConfigurationController.php new file mode 100644 index 0000000..d503d7e --- /dev/null +++ b/lib/Controller/UserConfigurationController.php @@ -0,0 +1,99 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +namespace OCA\Data\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; + +use OCA\Data\AppInfo\Application; +use OCA\Data\Service\DataService; + +class UserConfigurationController extends Controller { + private DataService $DataService; + + use Errors; + + public function __construct(IRequest $request, + DataService $DataService, + string $userId) { + parent::__construct(Application::APP_ID, $request); + $this->DataService = $DataService; + $this->userId = $userId; + } + + /** + * handels collections list requests + * + * @NoAdminRequired + * + * @return DataResponse + */ + public function listCollections(string $type): DataResponse { + + // evaluate if user id is present + if ($this->userId === null) { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + // retrieve collections + $rs = $this->DataService->listCollections($this->userId, $type); + // return response + if (isset($rs)) { + return new DataResponse($rs); + } else { + return new DataResponse($rs['error'], 401); + } + + } + + /** + * handels formats list requests + * + * @NoAdminRequired + * + * @return DataResponse + */ + public function listFormats(string $type): DataResponse { + + // evaluate if user id is present + if ($this->userId === null) { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + // retrieve formats + $rs = $this->DataService->listFormats($type); + // return response + if (isset($rs)) { + return new DataResponse($rs); + } else { + return new DataResponse($rs['error'], 401); + } + + } + + /** + * handels services list requests + * + * @NoAdminRequired + * + * @return DataResponse + */ + public function listServices(): DataResponse { + + // evaluate if user id is present + if ($this->userId === null) { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + // retrieve formats + $rs = $this->DataService->listServices($this->userId); + // return response + if (isset($rs)) { + return new DataResponse($rs); + } else { + return new DataResponse($rs['error'], 401); + } + + } +}