diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-05 16:00:58 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-09-05 16:28:45 +0300 |
commit | 09e8c84e2b70c3bf07ea14a3d1a6a2b2c9ff51bb (patch) | |
tree | b50b831e532b0ae568f491e017e4d88b4617d01b | |
parent | 32fa28dddbb480d0a5d86612c80178ec4ef34a8a (diff) |
Use the new OCS controller
-rw-r--r-- | appinfo/routes.php | 27 | ||||
-rw-r--r-- | lib/Controller/EndpointController.php | 52 | ||||
-rw-r--r-- | tests/Integration/features/bootstrap/FeatureContext.php | 4 |
3 files changed, 33 insertions, 50 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index b63aefd..fca8e84 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -19,23 +19,10 @@ * */ -$application = new \OCA\Notifications\AppInfo\Application(); - -\OCP\API::register( - 'get', - '/apps/notifications/api/v1/notifications', - [$application->getContainer()->query('EndpointController'), 'listNotifications'], - 'notifications' -); -\OCP\API::register( - 'get', - '/apps/notifications/api/v1/notifications/{id}', - [$application->getContainer()->query('EndpointController'), 'getNotification'], - 'notifications' -); -\OCP\API::register( - 'delete', - '/apps/notifications/api/v1/notifications/{id}', - [$application->getContainer()->query('EndpointController'), 'deleteNotification'], - 'notifications' -); +return [ + 'ocs' => [ + ['name' => 'Endpoint#listNotifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'], + ['name' => 'Endpoint#getNotification', 'url' => '/api/v1/notifications/{id}', 'verb' => 'GET'], + ['name' => 'Endpoint#deleteNotification', 'url' => '/api/v1/notifications/{id}', 'verb' => 'DELETE'], + ], +]; diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 0f7e3a0..596d9b5 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -23,7 +23,8 @@ namespace OCA\Notifications\Controller; use OCA\Notifications\Handler; use OCP\AppFramework\Http; -use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IRequest; use OCP\IUser; @@ -32,7 +33,7 @@ use OCP\Notification\IAction; use OCP\Notification\IManager; use OCP\Notification\INotification; -class EndpointController extends Controller { +class EndpointController extends OCSController { /** @var Handler */ private $handler; @@ -66,13 +67,13 @@ class EndpointController extends Controller { * @NoAdminRequired * @NoCSRFRequired * - * @return \OC_OCS_Result + * @return DataResponse */ public function listNotifications() { // When there are no apps registered that use the notifications // We stop polling for them. if (!$this->manager->hasNotifiers()) { - return new \OC_OCS_Result(null, Http::STATUS_NO_CONTENT); + return new DataResponse(null, Http::STATUS_NO_CONTENT); } $filter = $this->manager->createNotification(); @@ -96,35 +97,29 @@ class EndpointController extends Controller { $data[] = $this->notificationToArray($notificationId, $notification); } - return new \OC_OCS_Result( - $data, - 100, // HTTP::STATUS_OK, TODO: <status>failure</status><statuscode>200</statuscode> - null, - ['ETag' => $this->generateEtag($notificationIds)] - ); + return new DataResponse($data, Http::STATUS_OK, ['ETag' => $this->generateEtag($notificationIds)]); } /** * @NoAdminRequired * @NoCSRFRequired * - * @param array $parameters - * @return \OC_OCS_Result + * @param int $id + * @return DataResponse */ - public function getNotification(array $parameters) { + public function getNotification($id = 0) { if (!$this->manager->hasNotifiers()) { - return new \OC_OCS_Result(null, Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } - if (!isset($parameters['id'])) { - return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); + if (!is_int($id) || $id === 0) { + return new DataResponse(null, Http::STATUS_NOT_FOUND); } - $id = (int) $parameters['id']; $notification = $this->handler->getById($id, $this->getCurrentUser()); if (!($notification instanceof INotification)) { - return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } $language = $this->config->getUserValue($this->getCurrentUser(), 'core', 'lang', null); @@ -133,29 +128,26 @@ class EndpointController extends Controller { $notification = $this->manager->prepare($notification, $language); } catch (\InvalidArgumentException $e) { // The app was disabled - return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } - return new \OC_OCS_Result( - $this->notificationToArray($id, $notification), - 100 // HTTP::STATUS_OK TODO: <status>failure</status><statuscode>200</statuscode> - ); + return new DataResponse($this->notificationToArray($id, $notification)); } /** * @NoAdminRequired * - * @param array $parameters - * @return \OC_OCS_Result + * @param int $id + * @return DataResponse */ - public function deleteNotification(array $parameters) { - if (!isset($parameters['id'])) { - return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); + public function deleteNotification($id = 0) { + if (!is_int($id) || $id === 0) { + return new DataResponse(null, Http::STATUS_NOT_FOUND); } - $id = (int) $parameters['id']; + $id = (int) $id; $this->handler->deleteById($id, $this->getCurrentUser()); - return new \OC_OCS_Result(); + return new DataResponse(); } /** diff --git a/tests/Integration/features/bootstrap/FeatureContext.php b/tests/Integration/features/bootstrap/FeatureContext.php index 1e7ec4b..bac6440 100644 --- a/tests/Integration/features/bootstrap/FeatureContext.php +++ b/tests/Integration/features/bootstrap/FeatureContext.php @@ -319,6 +319,10 @@ class FeatureContext implements Context, SnippetAcceptingContext { $options['body'] = $fd; } + $options['headers'] = [ + 'OCS-APIREQUEST' => 'true', + ]; + try { $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); } catch (\GuzzleHttp\Exception\ClientException $ex) { |