Skip to content

Commit

Permalink
Update and cleanup API
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Hempel <Philipp.Hempel1@web.de>
  • Loading branch information
Hephi2 committed Aug 9, 2023
1 parent e83eba3 commit 9b64210
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 55 deletions.
24 changes: 17 additions & 7 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// -> tables
['name' => 'api1#index', 'url' => '/api/1/tables', 'verb' => 'GET'],
['name' => 'api1#createTable', 'url' => '/api/1/tables', 'verb' => 'POST'],
['name' => 'api1#updateTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'PUT'],
['name' => 'api1#getTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'GET'],
['name' => 'api1#deleteTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'DELETE'],
// -> views
Expand All @@ -26,26 +27,35 @@
// -> share
['name' => 'api1#getShare', 'url' => '/api/1/shares/{shareId}', 'verb' => 'GET'],
['name' => 'api1#indexViewShares', 'url' => '/api/1/views/{viewId}/shares', 'verb' => 'GET'],
['name' => 'api1#indexTableManageShares', 'url' => '/api/1/tables/{tableId}/shares', 'verb' => 'GET'],
['name' => 'api1#indexTableShares', 'url' => '/api/1/tables/{tableId}/shares', 'verb' => 'GET'],
['name' => 'api1#createShare', 'url' => '/api/1/shares', 'verb' => 'POST'],
['name' => 'api1#deleteShare', 'url' => '/api/1/shares/{shareId}', 'verb' => 'DELETE'],
['name' => 'api1#updateSharePermissions', 'url' => '/api/1/shares/{shareId}', 'verb' => 'PUT'],
// -> columns
['name' => 'api1#indexTableColumns', 'url' => '/api/1/tables/{tableId}/columns', 'verb' => 'GET'],
['name' => 'api1#indexViewColumns', 'url' => '/api/1/views/{viewId}/columns', 'verb' => 'GET'],
['name' => 'api1#createColumn', 'url' => '/api/1/views/{viewId}/columns', 'verb' => 'POST'],
['name' => 'api1#createColumn', 'url' => '/api/1/columns', 'verb' => 'POST'],
['name' => 'api1#updateColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'PUT'],
['name' => 'api1#getColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'GET'],
['name' => 'api1#deleteColumn', 'url' => '/api/1/columns/{columnId}', 'verb' => 'DELETE'],
// -> rows
['name' => 'api1#indexTableRowsSimple', 'url' => '/api/1/tables/{tableId}/rows/simple', 'verb' => 'GET'],
['name' => 'api1#indexTableRows', 'url' => '/api/1/tables/{tableId}/rows', 'verb' => 'GET'],
['name' => 'api1#indexViewRows', 'url' => '/api/1/views/{viewId}/rows', 'verb' => 'GET'],
['name' => 'api1#createRow', 'url' => '/api/1/views/{viewId}/rows', 'verb' => 'POST'],
['name' => 'api1#createRowInView', 'url' => '/api/1/views/{viewId}/rows', 'verb' => 'POST'],
['name' => 'row#createRowInTable', 'url' => '/api/1/tables/{tableId}/rows', 'verb' => 'POST'],

['name' => 'api1#getRow', 'url' => '/api/1/rows/{rowId}', 'verb' => 'GET'],
['name' => 'api1#updateRow', 'url' => '/api/1/views/{viewId}/rows/{rowId}', 'verb' => 'PUT'],
['name' => 'api1#deleteRow', 'url' => '/api/1/views/{viewId}/rows/{rowId}', 'verb' => 'DELETE'],
['name' => 'api1#deleteRowByView', 'url' => '/api/1/views/{viewId}/rows/{rowId}', 'verb' => 'DELETE'],
['name' => 'api1#updateRow', 'url' => '/api/1/rows/{rowId}', 'verb' => 'PUT'],
['name' => 'api1#deleteRow', 'url' => '/api/1/rows/{rowId}', 'verb' => 'DELETE'],
// -> import
['name' => 'api1#createImport', 'url' => '/api/1/import/views/{viewId}', 'verb' => 'POST'],
['name' => 'api1#importInTable', 'url' => '/api/1/import/table/{tablesId}', 'verb' => 'POST'],
['name' => 'api1#importInView', 'url' => '/api/1/import/views/{viewId}', 'verb' => 'POST'],

// Deprecated API calls
['name' => 'api1#createTableShare', 'url' => '/api/1/tables/{tableId}/shares', 'verb' => 'POST'], // use createShare instead
['name' => 'api1#createTableColumn', 'url' => '/api/1/tables/{tableId}/columns', 'verb' => 'POST'], // Use create column instead


// table
Expand Down Expand Up @@ -80,7 +90,7 @@
['name' => 'row#update', 'url' => '/row/{id}/column/{columnId}', 'verb' => 'PUT'],
['name' => 'row#updateSet', 'url' => '/row/{id}', 'verb' => 'PUT'],
['name' => 'row#destroyByView', 'url' => '/view/{viewId}/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#destroy', 'url' => '/table/{tableId}/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#destroy', 'url' => '/row/{id}', 'verb' => 'DELETE'],

// shares
['name' => 'share#index', 'url' => '/share/table/{tableId}', 'verb' => 'GET'],
Expand Down
13 changes: 4 additions & 9 deletions lib/Api/V1Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ public function __construct(ColumnService $columnService, RowService $rowService
}

/**
* @param int $viewId
* @param int $tableId
* @param int|null $limit
* @param int|null $offset
* @param string $userId
* @return array
* @throws InternalError
* @throws PermissionError
* @throws NotFoundError
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function getData(int $viewId, ?int $limit, ?int $offset, string $userId):
array {
$columns = $this->columnService->findAllByView($viewId);
public function getData(int $tableId, ?int $limit, ?int $offset): array {
$columns = $this->columnService->findAllByTable($tableId);

$rows = $this->rowService->findAllByView($viewId, $userId, $limit, $offset);
$rows = $this->rowService->findAllByTable($tableId, $limit, $offset);

$data = [];

Expand Down
186 changes: 171 additions & 15 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ public function getTable(int $tableId): DataResponse {
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function updateTable(int $id, string $title = null, string $emoji = null): DataResponse {
return $this->handleError(function () use ($id, $title, $emoji) {
return $this->service->update($id, $title, $emoji, $this->userId);
});
}

/**
* @NoAdminRequired
* @CORS
Expand Down Expand Up @@ -199,7 +210,7 @@ public function indexViewShares(int $viewId): DataResponse {
* @CORS
* @NoCSRFRequired
*/
public function indexTableManageShares(int $tableId): DataResponse {
public function indexTableShares(int $tableId): DataResponse {
return $this->handleError(function () use ($tableId) {
return $this->shareService->findAll('table', $tableId);
});
Expand Down Expand Up @@ -245,9 +256,9 @@ public function updateSharePermissions(int $shareId, string $permissionType, boo
* @CORS
* @NoCSRFRequired
*/
public function indexTableColumns(int $tableId): DataResponse {
return $this->handleError(function () use ($tableId) {
return $this->columnService->findAllByTable($tableId);
public function indexTableColumns(int $tableId, ?int $viewId): DataResponse {
return $this->handleError(function () use ($tableId, $viewId) {
return $this->columnService->findAllByTable($tableId, $viewId);
});
}

Expand All @@ -268,7 +279,8 @@ public function indexViewColumns(int $viewId): DataResponse {
* @NoCSRFRequired
*/
public function createColumn(
int $viewId,
?int $tableId,
?int $viewId,
string $title,
string $type,
?string $subtype,
Expand All @@ -293,6 +305,7 @@ public function createColumn(
?array $selectedViewIds = []
): DataResponse {
return $this->handleError(function () use (
$tableId,
$viewId,
$type,
$subtype,
Expand All @@ -319,6 +332,7 @@ public function createColumn(
) {
return $this->columnService->create(
$this->userId,
$tableId,
$viewId,
$type,
$subtype,
Expand Down Expand Up @@ -458,6 +472,17 @@ public function indexTableRowsSimple(int $tableId, ?int $limit, ?int $offset): D
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function indexTableRows(int $tableId, ?int $limit, ?int $offset): DataResponse {
return $this->handleError(function () use ($tableId, $limit, $offset) {
return $this->rowService->findAllByTable($tableId, $limit, $offset);
});
}

/**
* @NoAdminRequired
* @CORS
Expand All @@ -474,7 +499,9 @@ public function indexViewRows(int $viewId, ?int $limit, ?int $offset): DataRespo
* @CORS
* @NoCSRFRequired
*/
public function createRow(int $viewId, array $data): DataResponse {
public function createRowInView(
int $viewId,
array $data): DataResponse {
$dataNew = [];
foreach ($data as $key => $value) {
$dataNew[] = [
Expand All @@ -483,8 +510,29 @@ public function createRow(int $viewId, array $data): DataResponse {
];
}

return $this->handleError(function () use ($dataNew, $viewId) {
return $this->rowService->create($viewId, $dataNew);
return $this->handleError(function () use ( $viewId, $dataNew) {
return $this->rowService->create(null, $viewId, $dataNew);
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function createRowInTable(
int $tableId,
array $data): DataResponse {
$dataNew = [];
foreach ($data as $key => $value) {
$dataNew[] = [
'columnId' => (int) $key,
'value' => $value
];
}

return $this->handleError(function () use ($tableId, $dataNew) {
return $this->rowService->create($tableId, null, $dataNew);
});
}

Expand All @@ -504,7 +552,9 @@ public function getRow(int $rowId): DataResponse {
* @CORS
* @NoCSRFRequired
*/
public function updateRow(int $rowId, int $viewId, array $data): DataResponse {
public function updateRow(int $rowId,
?int $viewId,
array $data): DataResponse {
$dataNew = [];
foreach ($data as $key => $value) {
$dataNew[] = [
Expand All @@ -522,7 +572,18 @@ public function updateRow(int $rowId, int $viewId, array $data): DataResponse {
* @CORS
* @NoCSRFRequired
*/
public function deleteRow(int $rowId, int $viewId): DataResponse {
public function deleteRow(int $rowId): DataResponse {
return $this->handleError(function () use ($rowId) {
return $this->rowService->delete($rowId, null, $this->userId);
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function deleteRowByView(int $rowId, int $viewId): DataResponse {
return $this->handleError(function () use ($rowId, $viewId) {
return $this->rowService->delete($rowId, $viewId, $this->userId);
});
Expand All @@ -533,9 +594,20 @@ public function deleteRow(int $rowId, int $viewId): DataResponse {
* @CORS
* @NoCSRFRequired
*/
public function createImport(int $viewId, string $path, bool $createMissingColumns = true): DataResponse {
public function importInTable(int $tableId, string $path, bool $createMissingColumns = true): DataResponse {
return $this->handleError(function () use ($tableId, $path, $createMissingColumns) {
return $this->importService->import($tableId, null, $path, $createMissingColumns);
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function importInView(int $viewId, string $path, bool $createMissingColumns = true): DataResponse {
return $this->handleError(function () use ($viewId, $path, $createMissingColumns) {
return $this->importService->import($viewId, $path, $createMissingColumns);
return $this->importService->import(null, $viewId, $path, $createMissingColumns);
});
}

Expand All @@ -546,10 +618,94 @@ public function createImport(int $viewId, string $path, bool $createMissingColum
* @CORS
* @NoCSRFRequired
*/
public function updateTable(int $tableId, ?string $title, ?string $emoji): DataResponse {
return $this->handleError(function () use ($tableId, $title, $emoji) {
return $this->tableService->update($tableId, $title, $emoji);
public function createTableShare(int $tableId, string $receiver, string $receiverType, bool $permissionRead, bool $permissionCreate, bool $permissionUpdate, bool $permissionDelete, bool $permissionManage): DataResponse {
return $this->handleError(function () use ($tableId, $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage) {
return $this->shareService->create($tableId, 'table', $receiver, $receiverType, $permissionRead, $permissionCreate, $permissionUpdate, $permissionDelete, $permissionManage);
});
}

/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function createTableColumn(
int $tableId,
string $title,
string $type,
?string $subtype,
bool $mandatory,
?string $description,

?string $numberPrefix,
?string $numberSuffix,
?float $numberDefault,
?float $numberMin,
?float $numberMax,
?int $numberDecimals,

?string $textDefault,
?string $textAllowedPattern,
?int $textMaxLength,

?string $selectionOptions = '',
?string $selectionDefault = '',

?string $datetimeDefault = '',
?array $selectedViewIds = []
): DataResponse {
return $this->handleError(function () use (
$tableId,
$type,
$subtype,
$title,
$mandatory,
$description,

$textDefault,
$textAllowedPattern,
$textMaxLength,

$numberPrefix,
$numberSuffix,
$numberDefault,
$numberMin,
$numberMax,
$numberDecimals,

$selectionOptions,
$selectionDefault,

$datetimeDefault,
$selectedViewIds
) {
return $this->columnService->create(
$this->userId,
$tableId,
null,
$type,
$subtype,
$title,
$mandatory,
$description,

$textDefault,
$textAllowedPattern,
$textMaxLength,

$numberPrefix,
$numberSuffix,
$numberDefault,
$numberMin,
$numberMax,
$numberDecimals,

$selectionOptions,
$selectionDefault,

$datetimeDefault,
$selectedViewIds
);
});
}
}
Loading

0 comments on commit 9b64210

Please sign in to comment.