Skip to content

Commit

Permalink
feat(Api): add v2 OCS Api to get table/view rows
Browse files Browse the repository at this point in the history
- also changes Api Route definition to attribute

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jan 28, 2025
1 parent 2505f3d commit 7cf874a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 0 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,5 @@
['name' => 'Context#destroy', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'DELETE'],
['name' => 'Context#transfer', 'url' => '/api/2/contexts/{contextId}/transfer', 'verb' => 'PUT'],
['name' => 'Context#updateContentOrder', 'url' => '/api/2/contexts/{contextId}/pages/{pageId}', 'verb' => 'PUT'],

['name' => 'RowOCS#createRow', 'url' => '/api/2/{nodeCollection}/{nodeId}/rows', 'verb' => 'POST', 'requirements' => ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)']],
]
];
19 changes: 16 additions & 3 deletions lib/Controller/RowOCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\RowService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
Expand All @@ -42,10 +43,14 @@ public function __construct(
/**
* [api v2] Create a new row in a table or a view
*
* @param 'tables'|'views' $nodeCollection Indicates whether to create a row on a table or view
* @param 'tables'|'views' $nodeCollection Indicates whether to create a
* row on a table or view
* @param int $nodeId The identifier of the targeted table or view
* @param string|array<string, mixed> $data An array containing the column identifiers and their values
* @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{}>
* @param string|array<string, mixed> $data An array containing the column
* identifiers and their values
* @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{}>
*
* 200: Row returned
* 400: Invalid request parameters
Expand All @@ -55,6 +60,7 @@ public function __construct(
*/
#[NoAdminRequired]
#[RequirePermission(permission: Application::PERMISSION_CREATE, typeParam: 'nodeCollection')]
#[ApiRoute(verb: 'POST', url: '/api/2/{nodeCollection}/{nodeId}/rows', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
public function createRow(string $nodeCollection, int $nodeId, mixed $data): DataResponse {
if (is_string($data)) {
$data = json_decode($data, true);
Expand Down Expand Up @@ -86,4 +92,11 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
return $this->handleError($e);
}
}

#[NoAdminRequired]
#[RequirePermission(permission: Application::PERMISSION_READ, typeParam: 'nodeCollection')]
#[ApiRoute(verb: 'GET', url: '/api/2/{nodeCollection}/{nodeId}/rows', requirements: ['nodeCollection' => '(tables|views)', 'nodeId' => '(\d+)'])]
public function getRows(int $nodeId, ?int $limit, ?int $offset, ?array $filter, ?array $sort): DataResponse {
return new DataResponse([]);
}
}

0 comments on commit 7cf874a

Please sign in to comment.