Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-06-16 14:12:02 +0300
committerdartcafe <github@dartcafe.de>2020-06-16 14:12:02 +0300
commit076f8b3785f5728d7e61e5b9ac1233bda7e9fe3d (patch)
tree5b1ae4ce90891c565b20542a76a877625dbd4d7a /lib/Controller/SubscriptionController.php
parentfe8bc1b4aa307e0d956994c0fdfef51a93f549b2 (diff)
Added subscription to API
Diffstat (limited to 'lib/Controller/SubscriptionController.php')
-rw-r--r--lib/Controller/SubscriptionController.php28
1 files changed, 8 insertions, 20 deletions
diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php
index 8a5bf445..d201fa6e 100644
--- a/lib/Controller/SubscriptionController.php
+++ b/lib/Controller/SubscriptionController.php
@@ -25,7 +25,6 @@ namespace OCA\Polls\Controller;
use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
-use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IRequest;
use OCP\ILogger;
@@ -73,19 +72,13 @@ class SubscriptionController extends Controller {
* @return DataResponse
*/
public function get($pollId) {
-
- if (!\OC::$server->getUserSession()->isLoggedIn()) {
- return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
- }
-
try {
- $this->mapper->findByUserAndPoll($pollId, $this->userId);
- } catch (MultipleObjectsReturnedException $e) {
- // should not happen, but who knows
+ return new DataResponse($this->subscriptionService->get($pollId), Http::STATUS_OK);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
} catch (DoesNotExistException $e) {
- return new DataResponse(null, Http::STATUS_NOT_FOUND);
+ return new DataResponse('Not subscribed', Http::STATUS_NOT_FOUND);
}
- return new DataResponse(null, Http::STATUS_OK);
}
/**
@@ -94,15 +87,10 @@ class SubscriptionController extends Controller {
* @param integer $pollId
*/
public function set($pollId, $subscribed) {
- if ($subscribed) {
- $subscription = new Subscription();
- $subscription->setPollId($pollId);
- $subscription->setUserId($this->userId);
- $this->mapper->insert($subscription);
- return true;
- } else {
- $this->mapper->unsubscribe($pollId, $this->userId);
- return false;
+ try {
+ return new DataResponse($this->subscriptionService->set($pollId, $subscribed), Http::STATUS_OK);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
}
}
}