Skip to content

Commit

Permalink
Consolidate estimation and exportability warnings into a single endpoint
Browse files Browse the repository at this point in the history
Avoids having to query multiple endpoints on the client for closely related information

Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jun 3, 2022
1 parent bb1a078 commit e427f61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
1 change: 0 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
['name' => 'Api#migrators', 'url' => '/api/v{apiVersion}/migrators', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#status', 'url' => '/api/v{apiVersion}/status', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#cancel', 'url' => '/api/v{apiVersion}/cancel', 'verb' => 'PUT', 'requirements' => $requirements],
['name' => 'Api#estimate', 'url' => '/api/v{apiVersion}/export/estimate', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#exportable', 'url' => '/api/v{apiVersion}/export', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'Api#export', 'url' => '/api/v{apiVersion}/export', 'verb' => 'POST', 'requirements' => $requirements],
['name' => 'Api#import', 'url' => '/api/v{apiVersion}/import', 'verb' => 'POST', 'requirements' => $requirements],
Expand Down
25 changes: 6 additions & 19 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private function checkJobAndGetUser(): IUser {
*
* @throws OCSException
*/
public function estimate(?array $migrators): DataResponse {
public function exportable(?array $migrators): DataResponse {
$user = $this->checkJobAndGetUser();

if (!is_null($migrators)) {
Expand All @@ -230,29 +230,16 @@ public function estimate(?array $migrators): DataResponse {
throw new OCSException($e->getMessage());
}

return new DataResponse(['size' => $size], Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
*
* @throws OCSException
*/
public function exportable(?array $migrators): DataResponse {
$user = $this->checkJobAndGetUser();

if (!is_null($migrators)) {
$this->checkMigrators($migrators);
}

try {
$this->migrationService->checkExportability($user, $migrators);
} catch (NotExportableException $e) {
throw new OCSException($e->getMessage());
$warning = $e->getMessage();
}

return new DataResponse([], Http::STATUS_OK);
return new DataResponse([
'size' => $size,
'warning' => $warning ?? null,
], Http::STATUS_OK);
}

/**
Expand Down

0 comments on commit e427f61

Please sign in to comment.