diff options
author | René Gieling <github@dartcafe.de> | 2020-12-05 15:19:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-05 15:19:29 +0300 |
commit | 6cb597c9e8de850a8492d4c76c4781456e11e9a8 (patch) | |
tree | a4ea6c3abb3e568ee28037de3d15bfde9629a734 /lib/Controller/SubscriptionController.php | |
parent | 18ab3229485c0281405c560bad04e3c9f7ce511b (diff) |
publicController (#1272)
* move public pages to one publicController
* some more minor refactoring and optimizations
Diffstat (limited to 'lib/Controller/SubscriptionController.php')
-rw-r--r-- | lib/Controller/SubscriptionController.php | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php index 8cf11167..d6abb2c2 100644 --- a/lib/Controller/SubscriptionController.php +++ b/lib/Controller/SubscriptionController.php @@ -23,12 +23,8 @@ namespace OCA\Polls\Controller; -use OCP\AppFramework\Db\DoesNotExistException; -use OCA\Polls\Exceptions\Exception; - use OCP\IRequest; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCA\Polls\Service\SubscriptionService; @@ -38,6 +34,8 @@ class SubscriptionController extends Controller { /** @var SubscriptionService */ private $subscriptionService; + use ResponseHandle; + /** * SubscriptionController constructor. * @param string $appName @@ -56,36 +54,37 @@ class SubscriptionController extends Controller { /** * Get subscription status - * @PublicPage * @NoAdminRequired * @param int $pollId * @return DataResponse - * @throws DoesNotExistException */ - public function get($pollId, $token) { - try { - return new DataResponse(['subscribed' => $this->subscriptionService->get($pollId, $token)], Http::STATUS_OK); - } catch (Exception $e) { - return new DataResponse(['message' => $e->getMessage()], $e->getStatus()); - } catch (DoesNotExistException $e) { - return new DataResponse(['subscribed' => false], Http::STATUS_OK); - } + public function get($pollId = 0) { + return $this->response(function () use ($pollId) { + return ['subscribed' => $this->subscriptionService->get($pollId)]; + }); + } + + /** + * subscribe + * @NoAdminRequired + * @param int $pollId + * @return DataResponse + */ + public function subscribe($pollId) { + return $this->response(function () use ($pollId) { + return ['subscribed' => $this->subscriptionService->set($pollId, '', true)]; + }); } /** - * Switch subscription status - * @PublicPage + * Unsubscribe * @NoAdminRequired * @param int $pollId - * @param string $token - * @param boolean $subscribed * @return DataResponse */ - public function set($pollId, $token, $subscribed) { - try { - return new DataResponse(['subscribed' => $this->subscriptionService->set($pollId, $token, $subscribed)], Http::STATUS_OK); - } catch (Exception $e) { - return new DataResponse(['message' => $e->getMessage()], $e->getStatus()); - } + public function unsubscribe($pollId) { + return $this->response(function () use ($pollId) { + return ['subscribed' => $this->subscriptionService->set($pollId, '', false)]; + }); } } |