Skip to content

Commit 7cf874a

Browse files
committed
feat(Api): add v2 OCS Api to get table/view rows
- also changes Api Route definition to attribute Signed-off-by: Arthur Schiwon <[email protected]>
1 parent 2505f3d commit 7cf874a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

appinfo/routes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,5 @@
153153
['name' => 'Context#destroy', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'DELETE'],
154154
['name' => 'Context#transfer', 'url' => '/api/2/contexts/{contextId}/transfer', 'verb' => 'PUT'],
155155
['name' => 'Context#updateContentOrder', 'url' => '/api/2/contexts/{contextId}/pages/{pageId}', 'verb' => 'PUT'],
156-
157-
['name' => 'RowOCS#createRow', 'url' => '/api/2/{nodeCollection}/{nodeId}/rows', 'verb' => 'POST', 'requirements' => ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)']],
158156
]
159157
];

lib/Controller/RowOCSController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCA\Tables\ResponseDefinitions;
1919
use OCA\Tables\Service\RowService;
2020
use OCP\AppFramework\Http;
21+
use OCP\AppFramework\Http\Attribute\ApiRoute;
2122
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2223
use OCP\AppFramework\Http\DataResponse;
2324
use OCP\IL10N;
@@ -42,10 +43,14 @@ public function __construct(
4243
/**
4344
* [api v2] Create a new row in a table or a view
4445
*
45-
* @param 'tables'|'views' $nodeCollection Indicates whether to create a row on a table or view
46+
* @param 'tables'|'views' $nodeCollection Indicates whether to create a
47+
* row on a table or view
4648
* @param int $nodeId The identifier of the targeted table or view
47-
* @param string|array<string, mixed> $data An array containing the column identifiers and their values
48-
* @return DataResponse<Http::STATUS_OK, TablesRow, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
49+
* @param string|array<string, mixed> $data An array containing the column
50+
* identifiers and their values
51+
* @return DataResponse<Http::STATUS_OK, TablesRow,
52+
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR,
53+
* array{message: string}, array{}>
4954
*
5055
* 200: Row returned
5156
* 400: Invalid request parameters
@@ -55,6 +60,7 @@ public function __construct(
5560
*/
5661
#[NoAdminRequired]
5762
#[RequirePermission(permission: Application::PERMISSION_CREATE, typeParam: 'nodeCollection')]
63+
#[ApiRoute(verb: 'POST', url: '/api/2/{nodeCollection}/{nodeId}/rows', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
5864
public function createRow(string $nodeCollection, int $nodeId, mixed $data): DataResponse {
5965
if (is_string($data)) {
6066
$data = json_decode($data, true);
@@ -86,4 +92,11 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
8692
return $this->handleError($e);
8793
}
8894
}
95+
96+
#[NoAdminRequired]
97+
#[RequirePermission(permission: Application::PERMISSION_READ, typeParam: 'nodeCollection')]
98+
#[ApiRoute(verb: 'GET', url: '/api/2/{nodeCollection}/{nodeId}/rows', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
99+
public function getRows(int $nodeId, ?int $limit, ?int $offset, ?array $filter, ?array $sort): DataResponse {
100+
return new DataResponse([]);
101+
}
89102
}

0 commit comments

Comments
 (0)