diff --git a/src/Controller/Entrepot/DatasheetController.php b/src/Controller/Entrepot/DatasheetController.php index 32838ea7..f4fe61fd 100644 --- a/src/Controller/Entrepot/DatasheetController.php +++ b/src/Controller/Entrepot/DatasheetController.php @@ -44,7 +44,7 @@ public function getDatasheetList(string $datastoreId): JsonResponse { $uploads = $this->uploadApiService->getAll($datastoreId, [ 'sort' => 'lastEvent,desc', - 'fields' => ['tags'], + 'fields' => 'tags', ]); $uploadDatasheetNames = array_map(function ($upload) { @@ -55,7 +55,7 @@ public function getDatasheetList(string $datastoreId): JsonResponse $storedDataList = $this->storedDataApiService->getAll($datastoreId, [ 'sort' => 'lastEvent,desc', - 'fields' => ['tags'], + 'fields' => 'tags', ]); $storedDataDatasheetNames = array_map(function ($storedData) { diff --git a/src/Services/EntrepotApi/StoredDataApiService.php b/src/Services/EntrepotApi/StoredDataApiService.php index 2758b9a8..15382537 100644 --- a/src/Services/EntrepotApi/StoredDataApiService.php +++ b/src/Services/EntrepotApi/StoredDataApiService.php @@ -33,14 +33,11 @@ public function getAll(string $datastoreId, array $query = []): array $query['sort'] = 'lastEvent,desc'; } - /* - * pour transformer "sort=lastEvent,desc&fields[0]=field1&fields[1]=field2" en "sort=lastEvent,desc&fields=field1&fields=field2" - * l'API entrepôt ignore le premier format - */ - $queryString = urldecode(http_build_query($query)); - $queryString = preg_replace('/\[\d+\]/', '', $queryString); - - return $this->requestAll("datastores/$datastoreId/stored_data?{$queryString}"); + if (array_key_exists('fields', $query) && is_array($query['fields']) && !empty($query['fields'])) { + $query['fields'] = implode(',', $query['fields']); + } + + return $this->requestAll("datastores/$datastoreId/stored_data", $query); } /** diff --git a/src/Services/EntrepotApi/UploadApiService.php b/src/Services/EntrepotApi/UploadApiService.php index fcb988f8..20431084 100644 --- a/src/Services/EntrepotApi/UploadApiService.php +++ b/src/Services/EntrepotApi/UploadApiService.php @@ -18,14 +18,11 @@ public function getAll(string $datastoreId, array $query = []): array $query['sort'] = 'lastEvent,desc'; } - /* - * pour transformer "sort=lastEvent,desc&fields[0]=field1&fields[1]=field2" en "sort=lastEvent,desc&fields=field1&fields=field2" - * l'API entrepôt ignore le premier format - */ - $queryString = urldecode(http_build_query($query)); - $queryString = preg_replace('/\[\d+\]/', '', $queryString); - - return $this->requestAll("datastores/$datastoreId/uploads?{$queryString}"); + if (array_key_exists('fields', $query) && is_array($query['fields']) && !empty($query['fields'])) { + $query['fields'] = implode(',', $query['fields']); + } + + return $this->requestAll("datastores/$datastoreId/uploads", $query); } /**