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-22 19:55:42 +0300
committerdartcafe <github@dartcafe.de>2020-06-22 19:55:42 +0300
commit863d50ecfa2963664cb16892d31af65ad3289b5e (patch)
treea7e602e4bba24c103d4fd071b29e6e4c1cb314d0 /lib/Controller
parent0d632d59b202f55da389db28b870b8c64416c00f (diff)
code maintenance
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/CommentApiController.php19
-rw-r--r--lib/Controller/CommentController.php27
-rw-r--r--lib/Controller/OptionApiController.php18
-rw-r--r--lib/Controller/OptionController.php2
-rw-r--r--lib/Controller/PollApiController.php34
-rw-r--r--lib/Controller/PollController.php59
-rw-r--r--lib/Controller/ShareApiController.php15
-rw-r--r--lib/Controller/ShareController.php47
-rw-r--r--lib/Controller/SubscriptionApiController.php18
-rw-r--r--lib/Controller/SubscriptionController.php7
-rw-r--r--lib/Controller/VoteApiController.php9
-rw-r--r--lib/Controller/VoteController.php21
12 files changed, 109 insertions, 167 deletions
diff --git a/lib/Controller/CommentApiController.php b/lib/Controller/CommentApiController.php
index 9d93b83b..9d6fc1a8 100644
--- a/lib/Controller/CommentApiController.php
+++ b/lib/Controller/CommentApiController.php
@@ -40,8 +40,7 @@ use OCA\Polls\Service\CommentService;
class CommentApiController extends ApiController {
- private $optionService;
- private $urlGenerator;
+ private $commentService;
/**
* CommentApiController constructor.
* @param string $appName
@@ -52,7 +51,6 @@ class CommentApiController extends ApiController {
public function __construct(
string $appName,
IRequest $request,
- IURLGenerator $urlGenerator,
CommentService $commentService
) {
parent::__construct($appName,
@@ -61,7 +59,6 @@ class CommentApiController extends ApiController {
'Authorization, Content-Type, Accept',
1728000);
$this->commentService = $commentService;
- $this->urlGenerator = $urlGenerator;
}
/**
@@ -77,9 +74,9 @@ class CommentApiController extends ApiController {
try {
return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -94,11 +91,11 @@ class CommentApiController extends ApiController {
*/
public function add($pollId, $message) {
try {
- return new DataResponse($this->commentService->add($message, $pollId), Http::STATUS_CREATED);
+ return new DataResponse($this->commentService->add($pollId, $message), Http::STATUS_CREATED);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -115,9 +112,9 @@ class CommentApiController extends ApiController {
$this->commentService->delete($commentId);
return new DataResponse($commentId, Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Comment does not exist', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Comment does not exist'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php
index e940bfb7..6f240f05 100644
--- a/lib/Controller/CommentController.php
+++ b/lib/Controller/CommentController.php
@@ -24,6 +24,7 @@
namespace OCA\Polls\Controller;
use Exception;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IRequest;
use OCP\ILogger;
@@ -31,6 +32,8 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCA\Polls\Exceptions\NotAuthorizedException;
+
use OCA\Polls\Service\CommentService;
@@ -67,18 +70,18 @@ class CommentController extends Controller {
return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK);
}
- /**
- * Read all comments of a poll based on a share token and return list as array
- * @NoAdminRequired
- * @NoCSRFRequired
- * @PublicPage
- * @param string $token
- * @return DataResponse
- */
- public function getByToken($token) {
- return new DataResponse($this->commentService->get(0, $token), Http::STATUS_OK);
- }
-
+ // /**
+ // * Read all comments of a poll based on a share token and return list as array
+ // * @NoAdminRequired
+ // * @NoCSRFRequired
+ // * @PublicPage
+ // * @param string $token
+ // * @return DataResponse
+ // */
+ // public function getByToken($token) {
+ // return new DataResponse($this->commentService->get(0, $token), Http::STATUS_OK);
+ // }
+ //
/**
* Write a new comment to the db and returns the new comment as array
* @NoAdminRequired
diff --git a/lib/Controller/OptionApiController.php b/lib/Controller/OptionApiController.php
index f23fd350..5809510d 100644
--- a/lib/Controller/OptionApiController.php
+++ b/lib/Controller/OptionApiController.php
@@ -72,9 +72,9 @@ class OptionApiController extends ApiController {
try {
return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -99,11 +99,11 @@ class OptionApiController extends ApiController {
try {
return new DataResponse($this->optionService->add($option), Http::STATUS_CREATED);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
} catch (UniqueConstraintViolationException $e) {
- return new DataResponse('Option exists', Http::STATUS_CONFLICT);
+ return new DataResponse(['error' => 'Option exists'], Http::STATUS_CONFLICT);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -113,14 +113,14 @@ class OptionApiController extends ApiController {
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
- * @param Option $option
+ * @param array $option
* @return DataResponse
*/
public function update($option) {
try {
return new DataResponse($this->optionService->update($option), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -136,9 +136,9 @@ class OptionApiController extends ApiController {
try {
return new DataResponse($this->optionService->delete($optionId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Option does not exist', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Option does not exist'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
}
diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php
index 2b488c17..ae58c135 100644
--- a/lib/Controller/OptionController.php
+++ b/lib/Controller/OptionController.php
@@ -83,7 +83,7 @@ class OptionController extends Controller {
* Add a new Option to poll
* @NoAdminRequired
* @NoCSRFRequired
- * @param Option $option
+ * @param array $option
* @return DataResponse
*/
public function add($option) {
diff --git a/lib/Controller/PollApiController.php b/lib/Controller/PollApiController.php
index 98d8ef8f..3dcca2dd 100644
--- a/lib/Controller/PollApiController.php
+++ b/lib/Controller/PollApiController.php
@@ -79,7 +79,7 @@
} catch (DoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -95,9 +95,9 @@
try {
return new DataResponse($this->pollService->get($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -113,11 +113,11 @@
try {
return new DataResponse($this->pollService->add($type, $title), Http::STATUS_CREATED);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidPollTypeException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (EmptyTitleException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -133,15 +133,15 @@
try {
return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidAccessException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidShowResultsException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (EmptyTitleException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -157,9 +157,9 @@
try {
return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -175,9 +175,9 @@
try {
return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -193,9 +193,9 @@
try {
return new DataResponse($this->pollService->clone($pollId), Http::STATUS_CREATED);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index c30c8c32..aa4a5899 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -77,7 +77,7 @@ use OCA\Polls\Service\PollService;
} catch (DoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -94,9 +94,9 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->get($pollId, $token), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -112,9 +112,9 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -130,9 +130,9 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -149,11 +149,11 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidPollTypeException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (EmptyTitleException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -169,40 +169,15 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidAccessException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidShowResultsException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (EmptyTitleException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
- }
- }
-
- /**
- * write
- * @NoAdminRequired
- * @NoCSRFRequired
- * @depicated
- * @param Array $poll
- * @return DataResponse
- */
-
- public function write($poll) {
- try {
- return new DataResponse($this->pollService->write($poll), Http::STATUS_OK);
- } catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
- } catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
- } catch (InvalidAccessException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
- } catch (InvalidShowResultsException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
- } catch (EmptyTitleException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -217,9 +192,9 @@ use OCA\Polls\Service\PollService;
try {
return new DataResponse($this->pollService->clone($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Poll not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php
index 968ff115..4f147fad 100644
--- a/lib/Controller/ShareApiController.php
+++ b/lib/Controller/ShareApiController.php
@@ -45,7 +45,6 @@ class ShareApiController extends ApiController {
* @param string $appName
* @param string $userId
* @param IRequest $request
- * @param ILogger $logger
* @param ShareService $shareService
*/
public function __construct(
@@ -74,9 +73,9 @@ class ShareApiController extends ApiController {
try {
return new DataResponse($this->shareService->list($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('No shares for poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'No shares for poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -93,9 +92,9 @@ class ShareApiController extends ApiController {
try {
return new DataResponse($this->shareService->get($token), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Token ' . $token . ' not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Token ' . $token . ' not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -114,9 +113,9 @@ class ShareApiController extends ApiController {
try {
return new DataResponse($this->shareService->add($pollId, $type, $userId, $userEmail), Http::STATUS_CREATED);
} catch (\Exception $e) {
- return new DataResponse($e, Http::STATUS_CONFLICT);
+ return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -134,7 +133,7 @@ class ShareApiController extends ApiController {
try {
return new DataResponse($this->shareService->remove($token), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (Exception $e) {
return new DataResponse($e, Http::STATUS_NOT_FOUND);
}
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index da80acb5..16d9bca3 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -68,43 +68,6 @@ class ShareController extends Controller {
}
/**
- * getByToken
- * Get poll
- * @NoAdminRequired
- * @NoCSRFRequired
- * @PublicPage
- * @param string $token
- * @return DataResponse
- */
- public function get($token) {
- try {
- return new DataResponse($this->shareService->get($token), Http::STATUS_OK);
- } catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
- } catch (DoesNotExistException $e) {
- return new DataResponse('Token ' . $token . ' not found', Http::STATUS_NOT_FOUND);
- }
- }
-
- /**
- * get
- * Read all shares of a poll based on the poll id and return list as array
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param integer $pollId
- * @return DataResponse
- */
- public function getShares($pollId) {
- try {
- return new DataResponse($this->shareService->findByPoll($pollId), Http::STATUS_OK);
- } catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
- } catch (DoesNotExistException $e) {
- return new DataResponse('No shares for poll with id ' . $pollId . ' not found', Http::STATUS_NOT_FOUND);
- }
- }
-
- /**
* Write a new share to the db and returns the new share as array
* @NoAdminRequired
* @NoCSRFRequired
@@ -112,7 +75,7 @@ class ShareController extends Controller {
* @param Array $share
* @return DataResponse
*/
- public function write($pollId, $share) {
+ public function add($pollId, $share) {
try {
$return = $this->shareService->write(
$pollId,
@@ -122,7 +85,7 @@ class ShareController extends Controller {
);
return new DataResponse($return, Http::STATUS_CREATED);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (\Exception $e) {
return new DataResponse($e, Http::STATUS_CONFLICT);
}
@@ -144,7 +107,7 @@ class ShareController extends Controller {
try {
return new DataResponse($this->shareService->createPersonalShare($token, $userName), Http::STATUS_CREATED);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidUsername $e) {
return new DataResponse($userName . ' is not valid', Http::STATUS_CONFLICT);
} catch (DoesNotExistException $e) {
@@ -162,14 +125,14 @@ class ShareController extends Controller {
* @return DataResponse
*/
- public function remove($share) {
+ public function delete($share) {
try {
return new DataResponse(array(
'action' => 'deleted',
'shareId' => $this->shareService->remove($share['token'])->getId()
), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (Exception $e) {
return new DataResponse($e, Http::STATUS_NOT_FOUND);
}
diff --git a/lib/Controller/SubscriptionApiController.php b/lib/Controller/SubscriptionApiController.php
index e8c1acfa..3a23d403 100644
--- a/lib/Controller/SubscriptionApiController.php
+++ b/lib/Controller/SubscriptionApiController.php
@@ -25,6 +25,7 @@ namespace OCA\Polls\Controller;
use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\Polls\Exceptions\NotAuthorizedException;
use OCP\IRequest;
use OCP\ILogger;
@@ -77,11 +78,12 @@ class SubscriptionApiController extends ApiController {
*/
public function get($pollId) {
try {
- return new DataResponse($this->subscriptionService->get($pollId), Http::STATUS_OK);
+ $this->subscriptionService->get($pollId);
+ return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Not subscribed', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['status' => 'Not subscribed to poll ' . $pollId], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -93,10 +95,10 @@ class SubscriptionApiController extends ApiController {
*/
public function subscribe($pollId) {
try {
- return $this->subscriptionService->set($pollId, true);
- return new DataResponse('Subscribed', Http::STATUS_OK);
+ $this->subscriptionService->set($pollId, true);
+ return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
/**
@@ -108,9 +110,9 @@ class SubscriptionApiController extends ApiController {
public function unsubscribe($pollId) {
try {
$this->subscriptionService->set($pollId, false);
- return new DataResponse('Unsubscribed', Http::STATUS_OK);
+ return new DataResponse(['status' => 'Unsubscribed from poll ' . $pollId], Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
}
diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php
index f3cc655a..194b97e6 100644
--- a/lib/Controller/SubscriptionController.php
+++ b/lib/Controller/SubscriptionController.php
@@ -25,6 +25,7 @@ namespace OCA\Polls\Controller;
use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\Polls\Exceptions\NotAuthorizedException;
use OCP\IRequest;
use OCP\ILogger;
@@ -73,9 +74,9 @@ class SubscriptionController extends Controller {
try {
return new DataResponse($this->subscriptionService->get($pollId), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('Not subscribed', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Not subscribed'], Http::STATUS_NOT_FOUND);
}
}
@@ -88,7 +89,7 @@ class SubscriptionController extends Controller {
try {
return new DataResponse($this->subscriptionService->set($pollId, $subscribed), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
}
diff --git a/lib/Controller/VoteApiController.php b/lib/Controller/VoteApiController.php
index 8f5b77ac..03caea0f 100644
--- a/lib/Controller/VoteApiController.php
+++ b/lib/Controller/VoteApiController.php
@@ -25,6 +25,7 @@ namespace OCA\Polls\Controller;
use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\Polls\Exceptions\NotAuthorizedException;
use OCP\IRequest;
use OCP\ILogger;
@@ -74,9 +75,9 @@ class VoteApiController extends ApiController {
try {
return new DataResponse($this->voteService->list($pollId), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('No votes', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
@@ -95,9 +96,9 @@ class VoteApiController extends ApiController {
try {
return new DataResponse($this->voteService->set($pollId, $pollOptionText, $setTo), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
- return new DataResponse('Option not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e->getMessage(), $e->getStatus());
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
}
diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php
index 64dc8501..f666c004 100644
--- a/lib/Controller/VoteController.php
+++ b/lib/Controller/VoteController.php
@@ -25,6 +25,7 @@ namespace OCA\Polls\Controller;
// use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\Polls\Exceptions\NotAuthorizedException;
use OCP\ILogger;
use OCP\IRequest;
@@ -71,9 +72,9 @@ class VoteController extends Controller {
try {
return new DataResponse($this->voteService->list($pollId), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('No votes', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
}
}
@@ -91,9 +92,9 @@ class VoteController extends Controller {
try {
return new DataResponse($this->voteService->set($pollId, $option['pollOptionText'], $setTo), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('Option not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND);
}
}
@@ -111,9 +112,9 @@ class VoteController extends Controller {
try {
return new DataResponse($this->voteService->delete($pollId, $userId), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => ''], Http::STATUS_NOT_FOUND);
}
}
@@ -135,9 +136,9 @@ class VoteController extends Controller {
try {
return new DataResponse($this->voteService->set(0, $option['pollOptionText'], $setTo, $token), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('Option not found', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND);
}
}
@@ -155,9 +156,9 @@ class VoteController extends Controller {
try {
return new DataResponse($this->voteService->list(null, $token), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse('Unauthorized', Http::STATUS_FORBIDDEN);
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (DoesNotExistException $e) {
- return new DataResponse('No votes', Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
}
}