diff --git a/appinfo/routes.php b/appinfo/routes.php index eccb3335..705f76fc 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -70,6 +70,9 @@ ['name' => 'ApiData#preflighted_cors', 'url' => '/api/2.0/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], ['name' => 'ApiData#addDataV2', 'url' => '/api/2.0/adddata/{datasetId}', 'verb' => 'POST'], ['name' => 'ApiData#deleteDataV2', 'url' => '/api/2.0/deletedata/{datasetId}', 'verb' => 'POST'], + ['name' => 'ApiData#index', 'url' => '/api/2.0/dataset/list', 'verb' => 'GET'], + ['name' => 'ApiData#detail', 'url' => '/api/2.0/dataset/{datasetId}/detail', 'verb' => 'GET'], + ['name' => 'ApiData#data', 'url' => '/api/2.0/dataset/{datasetId}/data', 'verb' => 'GET'], // wizard ['name' => 'wizard#dismiss', 'url' => '/wizard', 'verb' => 'POST'], @@ -78,4 +81,4 @@ ['name' => 'whatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'], ['name' => 'whatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'], ] -]; \ No newline at end of file +]; diff --git a/lib/Controller/ApiDataController.php b/lib/Controller/ApiDataController.php index 5f64d26f..042f19bd 100644 --- a/lib/Controller/ApiDataController.php +++ b/lib/Controller/ApiDataController.php @@ -12,6 +12,7 @@ namespace OCA\Analytics\Controller; use OCA\Analytics\Activity\ActivityManager; +use OCA\Analytics\Db\StorageMapper; use OCA\Analytics\Service\DatasetService; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; @@ -33,6 +34,7 @@ class ApiDataController extends ApiController private $ActivityManager; private $DatasetService; private $StorageController; + private $StorageMapper; public function __construct( $appName, @@ -41,7 +43,8 @@ public function __construct( IUserSession $userSession, ActivityManager $ActivityManager, DatasetService $DatasetService, - StorageController $StorageController + StorageController $StorageController, + StorageMapper $StorageMapper ) { parent::__construct( @@ -54,6 +57,7 @@ public function __construct( $this->ActivityManager = $ActivityManager; $this->DatasetService = $DatasetService; $this->StorageController = $StorageController; + $this->StorageMapper = $StorageMapper; } /** @@ -166,6 +170,71 @@ public function deleteDataV2(int $datasetId) $message); } + /** + * list datasets + * @CORS + * @NoCSRFRequired + * @NoAdminRequired + * @return DataResponse + * @throws \Exception + */ + public function index() { + return $this->DatasetService->index(); + } + + /** + * read data of a dataset with additional information for table and series + * @CORS + * @NoCSRFRequired + * @NoAdminRequired + * @return DataResponse + * @throws \Exception + */ + public function detail(int $datasetId) + { + $datasetMetadata = $this->DatasetService->getOwnDataset($datasetId); + + if (!empty($datasetMetadata)) { + $allData = $this->StorageController->read($datasetMetadata); + $series = array_values(array_unique(array_map('array_shift', $allData['data']))); + + return new DataResponse([ + 'header' => $allData['header'], + 'dimensions' => $allData['dimensions'], + 'series' => $series, + ], HTTP::STATUS_OK); + } else { + return new DataResponse([ + 'message' => 'No metadata available for given $datasetId', + ], HTTP::STATUS_OK); + } + } + + /** + * get all data of a dataset and respect filter options + * @CORS + * @NoCSRFRequired + * @NoAdminRequired + * @return DataResponse + * @throws \Exception + */ + public function data(int $datasetId) + { + $params = $this->request->getParams(); + $datasetMetadata = $this->DatasetService->getOwnDataset($datasetId); + + if (!empty($datasetMetadata)) { + $options = json_decode($params['filteroptions'], true); + $allData = $this->StorageMapper->read($datasetMetadata['id'], $options); + + return new DataResponse($allData, HTTP::STATUS_OK); + } else { + return new DataResponse([ + 'message' => 'No data available for given $datasetId', + ], HTTP::STATUS_OK); + } + } + /** * derive if the parameter is technical or the free text description from the report * @param $data @@ -237,4 +306,4 @@ protected function requestResponse($success, $code = null, $message = null) // curl -u Admin:2sroW-SxRcK-AmdsF-RYMJ5-CKSyf -d '{"delete":[{"dimension1": "a", "dimension2": "a"}]}' -X POST -H "Content-Type: application/json" http://nc18/nextcloud/apps/analytics/api/2.0/deletedata/158 // curl -u Admin:2sroW-SxRcK-AmdsF-RYMJ5-CKSyf -d '{"del":[{"dimension1": "a", "dimension2": "a"}]}' -X POST -H "Content-Type: application/json" http://nc18/nextcloud/apps/analytics/api/2.0/deletedata/158 -} \ No newline at end of file +}