diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
commit | 066b4b5a22a89fe3b38d37f09153090091928cd5 (patch) | |
tree | e01b7eaf641314259de1a54f146fa3e5d582ce02 /controller/itemcontroller.php | |
parent | fb85040af65e77e6f4b2e596e259b38b510a8b60 (diff) |
move to new controller layout
Diffstat (limited to 'controller/itemcontroller.php')
-rw-r--r-- | controller/itemcontroller.php | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index b7836fdaa..3313f583b 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -17,7 +17,6 @@ use \OCP\IRequest; use \OCP\IConfig; use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; -use \OCP\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -26,6 +25,8 @@ use \OCA\News\BusinessLayer\FeedBusinessLayer; class ItemController extends Controller { + use JSONHttpError; + private $itemBusinessLayer; private $feedBusinessLayer; private $userId; @@ -47,16 +48,16 @@ class ItemController extends Controller { /** * @NoAdminRequired + * + * @param int $type + * @param int $id + * @param int $limit + * @param int $offset */ - public function index(){ + public function index($type, $id, $limit, $offset=0) { $showAll = $this->settings->getUserValue($this->userId, $this->appName, 'showAll') === '1'; - $limit = $this->params('limit'); - $type = (int) $this->params('type'); - $id = (int) $this->params('id'); - $offset = (int) $this->params('offset', 0); - $this->settings->setUserValue($this->userId, $this->appName, 'lastViewedFeedId', $id); $this->settings->setUserValue($this->userId, $this->appName, @@ -78,6 +79,7 @@ class ItemController extends Controller { $params['items'] = $this->itemBusinessLayer->findAll($id, $type, $limit, $offset, $showAll, $this->userId); + // this gets thrown if there are no items // in that case just return an empty array } catch(BusinessLayerException $ex) {} @@ -88,15 +90,15 @@ class ItemController extends Controller { /** * @NoAdminRequired + * + * @param int $type + * @param int $id + * @param int $lastModified */ - public function newItems() { + public function newItems($type, $id, $lastModified=0) { $showAll = $this->settings->getUserValue($this->userId, $this->appName, 'showAll') === '1'; - $type = (int) $this->params('type'); - $id = (int) $this->params('id'); - $lastModified = (int) $this->params('lastModified', 0); - $params = array(); try { @@ -105,97 +107,93 @@ class ItemController extends Controller { $params['starred'] = $this->itemBusinessLayer->starredCount($this->userId); $params['items'] = $this->itemBusinessLayer->findAllNew($id, $type, $lastModified, $showAll, $this->userId); + // this gets thrown if there are no items // in that case just return an empty array } catch(BusinessLayerException $ex) {} - return new $params; + return $params; } - private function setStarred($isStarred){ - $feedId = (int) $this->params('feedId'); - $guidHash = $this->params('guidHash'); - + private function setStarred($isStarred, $feedId, $guidHash){ $this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $this->userId); } /** * @NoAdminRequired + * + * @param int $feedId + * @param string $guidHash */ - public function star(){ + public function star($feedId, $guidHash){ try { - $this->setStarred(true); + $this->setStarred(true, $feedId, $guidHash); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } /** * @NoAdminRequired + * + * @param int $feedId + * @param string $guidHash */ - public function unstar(){ + public function unstar($feedId, $guidHash){ try { - $this->setStarred(false); + $this->setStarred(false, $feedId, $guidHash); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } - private function setRead($isRead){ - $itemId = (int) $this->params('itemId'); - + private function setRead($isRead, $itemId){ $this->itemBusinessLayer->read($itemId, $isRead, $this->userId); } /** * @NoAdminRequired + * + * @param int $itemId */ - public function read(){ + public function read($itemId){ try { $this->setRead(true); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } /** * @NoAdminRequired + * + * @param int $itemId */ - public function unread(){ + public function unread($itemId){ try { $this->setRead(false); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } /** * @NoAdminRequired + * + * @param int $highestItemId */ - public function readAll(){ - $highestItemId = (int) $this->params('highestItemId'); - + public function readAll($highestItemId){ $this->itemBusinessLayer->readAll($highestItemId, $this->userId); - - $params = array( + return array( 'feeds' => $this->feedBusinessLayer->findAll($this->userId) ); - return new JSONResponse($params); } |