forked from nextcloud/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,057 additions
and
1,013 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
<?php | ||
/** | ||
* Nextcloud - Notes | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Bernhard Posselt <[email protected]> | ||
* @copyright Bernhard Posselt 2012, 2014 | ||
*/ | ||
|
||
return ['routes' => [ | ||
// page | ||
////////// P A G E ////////// | ||
[ | ||
'name' => 'page#index', | ||
'url' => '/', | ||
|
@@ -30,7 +20,8 @@ | |
'requirements' => ['id' => '\d+'], | ||
], | ||
|
||
// notes | ||
|
||
////////// N O T E S ////////// | ||
[ | ||
'name' => 'notes#index', | ||
'url' => '/notes', | ||
|
@@ -59,22 +50,13 @@ | |
'requirements' => ['id' => '\d+'], | ||
], | ||
[ | ||
'name' => 'notes#category', | ||
'url' => '/notes/{id}/category', | ||
'verb' => 'PUT', | ||
'requirements' => ['id' => '\d+'], | ||
], | ||
[ | ||
'name' => 'notes#title', | ||
'url' => '/notes/{id}/title', | ||
'verb' => 'PUT', | ||
'requirements' => ['id' => '\d+'], | ||
], | ||
[ | ||
'name' => 'notes#favorite', | ||
'url' => '/notes/{id}/favorite', | ||
'name' => 'notes#updateProperty', | ||
'url' => '/notes/{id}/{property}', | ||
'verb' => 'PUT', | ||
'requirements' => ['id' => '\d+'], | ||
'requirements' => [ | ||
'id' => '\d+', | ||
'property' => '(modified|title|category|favorite)', | ||
], | ||
], | ||
[ | ||
'name' => 'notes#destroy', | ||
|
@@ -83,43 +65,88 @@ | |
'requirements' => ['id' => '\d+'], | ||
], | ||
|
||
// api | ||
|
||
////////// S E T T I N G S ////////// | ||
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'PUT'], | ||
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'], | ||
|
||
|
||
////////// A P I ////////// | ||
[ | ||
'name' => 'notes_api#index', | ||
'url' => '/api/v0.2/notes', | ||
'url' => '/api/{apiVersion}/notes', | ||
'verb' => 'GET', | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2|v1)', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#get', | ||
'url' => '/api/v0.2/notes/{id}', | ||
'url' => '/api/{apiVersion}/notes/{id}', | ||
'verb' => 'GET', | ||
'requirements' => ['id' => '\d+'], | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2|v1)', | ||
'id' => '\d+', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#createAutoTitle', | ||
'url' => '/api/{apiVersion}/notes', | ||
'verb' => 'POST', | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2)', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#create', | ||
'url' => '/api/v0.2/notes', | ||
'url' => '/api/{apiVersion}/notes', | ||
'verb' => 'POST', | ||
'requirements' => [ | ||
'apiVersion' => '(v1)', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#updateAutoTitle', | ||
'url' => '/api/{apiVersion}/notes/{id}', | ||
'verb' => 'PUT', | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2)', | ||
'id' => '\d+', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#update', | ||
'url' => '/api/v0.2/notes/{id}', | ||
'url' => '/api/{apiVersion}/notes/{id}', | ||
'verb' => 'PUT', | ||
'requirements' => ['id' => '\d+'], | ||
'requirements' => [ | ||
'apiVersion' => '(v1)', | ||
'id' => '\d+', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#destroy', | ||
'url' => '/api/v0.2/notes/{id}', | ||
'url' => '/api/{apiVersion}/notes/{id}', | ||
'verb' => 'DELETE', | ||
'requirements' => ['id' => '\d+'], | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2|v1)', | ||
'id' => '\d+', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#fail', | ||
'url' => '/api/{catchAll}', | ||
'verb' => 'GET', | ||
'requirements' => [ | ||
'catchAll' => '.*', | ||
], | ||
], | ||
[ | ||
'name' => 'notes_api#preflighted_cors', | ||
'url' => '/api/v0.2/{path}', | ||
'url' => '/api/{apiVersion}/{path}', | ||
'verb' => 'OPTIONS', | ||
'requirements' => ['path' => '.+'], | ||
'requirements' => [ | ||
'apiVersion' => '(v0.2|v1)', | ||
'path' => '.+', | ||
], | ||
], | ||
|
||
// settings | ||
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'PUT'], | ||
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'], | ||
]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OCA\Notes\Controller; | ||
|
||
use OCA\Notes\Application; | ||
use OCA\Notes\Service\InsufficientStorageException; | ||
use OCA\Notes\Service\NoteDoesNotExistException; | ||
|
||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\ILogger; | ||
|
||
class Helper { | ||
|
||
private $logger; | ||
private $appName; | ||
|
||
public function __construct( | ||
ILogger $logger, | ||
string $appName | ||
) { | ||
$this->logger = $logger; | ||
$this->appName = $appName; | ||
} | ||
|
||
public function handleErrorResponse(callable $respond) : DataResponse { | ||
try { | ||
$data = $respond(); | ||
$response = $data instanceof DataResponse ? $data : new DataResponse($data); | ||
} catch (NoteDoesNotExistException $e) { | ||
$this->logger->logException($e, [ 'app' => $this->appName ]); | ||
$response = new DataResponse([], Http::STATUS_NOT_FOUND); | ||
} catch (InsufficientStorageException $e) { | ||
$this->logger->logException($e, [ 'app' => $this->appName ]); | ||
$response = new DataResponse([], Http::STATUS_INSUFFICIENT_STORAGE); | ||
} catch (\Throwable $e) { | ||
$this->logger->logException($e, [ 'app' => $this->appName ]); | ||
$response = new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); | ||
} | ||
$response->addHeader('X-Notes-API-Versions', implode(', ', Application::$API_VERSIONS)); | ||
return $response; | ||
} | ||
} |
Oops, something went wrong.