From 066b4b5a22a89fe3b38d37f09153090091928cd5 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 13 May 2014 21:57:44 +0200 Subject: move to new controller layout --- controller/entityapiserializer.php | 44 +++++++++++++++ controller/feedapicontroller.php | 62 +++++++++------------- controller/feedcontroller.php | 103 +++++++++++++++--------------------- controller/folderapicontroller.php | 69 +++++++++--------------- controller/foldercontroller.php | 57 ++++++++------------ controller/itemapicontroller.php | 44 +++------------ controller/itemcontroller.php | 86 +++++++++++++++--------------- controller/pagecontroller.php | 8 +-- controller/utilityapicontroller.php | 1 + 9 files changed, 214 insertions(+), 260 deletions(-) create mode 100644 controller/entityapiserializer.php (limited to 'controller') diff --git a/controller/entityapiserializer.php b/controller/entityapiserializer.php new file mode 100644 index 000000000..ef5e20fbe --- /dev/null +++ b/controller/entityapiserializer.php @@ -0,0 +1,44 @@ + + * @author Bernhard Posselt + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Controller; + +use \OCP\AppFramework\Http\IResponseSerializer; + +class EntityApiSeralizer implements IResponseSerializer { + + + public function __construct($level) { + $this->level = $level; + } + + + /** + * Wrap a list of entities in an array with $level as index and serialize + * them using the toAPI method + */ + public function serialize($data) { + if(!is_array($data)) { + $data = array($data); + } + + $response = array( + $this->level => array(); + ); + + foreach($data as $entity) { + $response[$this->level][] = $entity->toAPI() + } + } + +} \ No newline at end of file diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php index 883732c87..b326a1825 100644 --- a/controller/feedapicontroller.php +++ b/controller/feedapicontroller.php @@ -28,6 +28,8 @@ use \OCA\News\BusinessLayer\BusinessLayerConflictException; class FeedApiController extends ApiController { + use JSONHttpError; + private $itemBusinessLayer; private $feedBusinessLayer; private $folderBusinessLayer; @@ -66,6 +68,7 @@ class FeedApiController extends ApiController { ); $feeds = $this->feedBusinessLayer->findAll($this->userId); + foreach ($feeds as $feed) { array_push($result['feeds'], $feed->toAPI()); } @@ -112,19 +115,9 @@ class FeedApiController extends ApiController { return $result; } catch(BusinessLayerConflictException $ex) { - - return new JSONResponse( - array('message' => $ex->getMessage()), - Http::STATUS_CONFLICT - ); - + return $this->error($ex, Http::STATUS_CONFLICT); } catch(BusinessLayerException $ex) { - - return new JSONResponse( - array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND - ); - + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -140,10 +133,7 @@ class FeedApiController extends ApiController { try { $this->feedBusinessLayer->delete($feedId, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse( - array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND - ); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -152,11 +142,11 @@ class FeedApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $feedId + * @param int $newestItemId */ - public function read() { - $feedId = (int) $this->params('feedId'); - $newestItemId = (int) $this->params('newestItemId'); - + public function read($feedId, $newestItemId) { $this->itemBusinessLayer->readFeed($feedId, $newestItemId, $this->userId); } @@ -165,16 +155,15 @@ class FeedApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $feedId + * @param int $folderId */ - public function move() { - $feedId = (int) $this->params('feedId'); - $folderId = (int) $this->params('folderId'); - + public function move($feedId, $folderId) { try { $this->feedBusinessLayer->move($feedId, $folderId, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -183,16 +172,15 @@ class FeedApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $feedId + * @param string $feedTitle */ - public function rename() { - $feedId = (int) $this->params('feedId'); - $feedTitle = $this->params('feedTitle'); - + public function rename($feedId, $feedTitle) { try { $this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -212,17 +200,17 @@ class FeedApiController extends ApiController { )); } - return new JSONResponse($result); + return $result; } /** * @NoCSRFRequired + * + * @param string $userId + * @param int $feedId */ - public function update() { - $userId = $this->params('userId'); - $feedId = (int) $this->params('feedId'); - + public function update($userId, $feedId) { try { $this->feedBusinessLayer->update($feedId, $userId); // ignore update failure (feed could not be reachable etc, we dont care) diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index 02e523dff..5489f555c 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.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\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; @@ -29,6 +28,8 @@ use \OCA\News\Db\FeedType; class FeedController extends Controller { + use JSONHttpError; + private $feedBusinessLayer; private $folderBusinessLayer; private $itemBusinessLayer; @@ -72,7 +73,7 @@ class FeedController extends Controller { // simply ignore it and do not add the newestItemId } catch (BusinessLayerException $ex) {} - return new JSONResponse($params); + return $params; } @@ -108,24 +109,22 @@ class FeedController extends Controller { $feedType = FeedType::SUBSCRIPTIONS; } - $params = array( + return array( 'activeFeed' => array( 'id' => $feedId, 'type' => $feedType ) ); - - return new JSONResponse($params); } /** * @NoAdminRequired + * + * @param string $url + * @param int $parentFolderId */ - public function create(){ - $url = $this->params('url'); - $parentFolderId = (int) $this->params('parentFolderId'); - + public function create($url, $parentFolderId){ try { // we need to purge deleted feeds if a feed is created to // prevent already exists exceptions @@ -144,47 +143,40 @@ class FeedController extends Controller { // simply ignore it and do not add the newestItemId } catch (BusinessLayerException $ex) {} - return new JSONResponse($params); + return $params; } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_CONFLICT); - + return $this->error($ex, Http::STATUS_CONFLICT); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_UNPROCESSABLE_ENTITY); + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } } /** * @NoAdminRequired + * + * @param int $feedId */ - public function delete(){ - $feedId = (int) $this->params('feedId'); - + public function delete($feedId){ try { $this->feedBusinessLayer->markDeleted($feedId, $this->userId); } 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 */ - public function update(){ + public function update($feedId){ try { - $feedId = (int) $this->params('feedId'); - $feed = $this->feedBusinessLayer->update($feedId, $this->userId); - $params = array( + return array( 'feeds' => array( // only pass unreadcount to not accidentally readd // the feed again @@ -195,75 +187,69 @@ class FeedController extends Controller { ) ); - return new JSONResponse($params); - } 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 int $parentFolderId */ - public function move(){ - $feedId = (int) $this->params('feedId'); - $parentFolderId = (int) $this->params('parentFolderId'); - + public function move($feedId, $parentFolderId){ try { $this->feedBusinessLayer->move($feedId, $parentFolderId, $this->userId); } 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 $feedTitle */ public function rename() { - $feedId = (int) $this->params('feedId'); - $feedTitle = $this->params('feedTitle'); - try { $this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } + /** * @NoAdminRequired + * + * @param array $json */ - public function import() { - $json = $this->params('json'); - + public function import($json) { $feed = $this->feedBusinessLayer->importArticles($json, $this->userId); $params = array(); + if($feed) { $params['feeds'] = array($feed); } - return new JSONResponse($params); + return $params; } /** * @NoAdminRequired + * + * @param int $feedId + * @param int $highestItemId */ - public function read(){ - $feedId = (int) $this->params('feedId'); - $highestItemId = (int) $this->params('highestItemId'); - + public function read($feedId, $highestItemId){ $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $this->userId); - $params = array( + return array( 'feeds' => array( array( 'id' => $feedId, @@ -271,22 +257,19 @@ class FeedController extends Controller { ) ) ); - return new JSONResponse($params); } /** * @NoAdminRequired + * + * @param int $feedId */ public function restore(){ - $feedId = (int) $this->params('feedId'); - try { $this->feedBusinessLayer->unmarkDeleted($feedId, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php index 40ffc1389..4e9f3e00c 100644 --- a/controller/folderapicontroller.php +++ b/controller/folderapicontroller.php @@ -27,6 +27,8 @@ use \OCA\News\BusinessLayer\BusinessLayerValidationException; class FolderApiController extends ApiController { + use JSONHttpError; + private $folderBusinessLayer; private $itemBusinessLayer; private $userId; @@ -49,15 +51,9 @@ class FolderApiController extends ApiController { * @CORS */ public function index() { - $result = array( - 'folders' => array() - ); - - foreach ($this->folderBusinessLayer->findAll($this->userId) as $folder) { - array_push($result['folders'], $folder->toAPI()); - } + $this->registerSerializer(new EntityApiSerializer('folders')); - return new JSONResponse($result); + return $this->folderBusinessLayer->findAll($this->userId); } @@ -65,27 +61,21 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param string $name */ - public function create() { - $folderName = $this->params('name'); - $result = array( - 'folders' => array() - ); - + public function create($name) { try { $this->folderBusinessLayer->purgeDeleted($this->userId, false); $folder = $this->folderBusinessLayer->create($folderName, $this->userId); - array_push($result['folders'], $folder->toAPI()); + + $this->registerSerializer(new EntityApiSerializer('folders')); + return $folder; - return new JSONResponse($result); - } catch(BusinessLayerValidationException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_UNPROCESSABLE_ENTITY); - + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_CONFLICT); + return $this->error($ex, Http::STATUS_CONFLICT); } } @@ -94,15 +84,14 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $folderId */ - public function delete() { - $folderId = (int) $this->params('folderId'); - + public function delete($folderId) { try { $this->folderBusinessLayer->delete($folderId, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -111,25 +100,19 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * @param int $folderId + * @param string $name */ - public function update() { - $folderId = (int) $this->params('folderId'); - $folderName = $this->params('name'); - + public function update($folderId, $name) { try { $this->folderBusinessLayer->rename($folderId, $folderName, $this->userId); } catch(BusinessLayerValidationException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_UNPROCESSABLE_ENTITY); - + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_CONFLICT); - + return $this->error($ex, Http::STATUS_CONFLICT); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -138,11 +121,11 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $folderId + * @param int $newestItemId */ - public function read() { - $folderId = (int) $this->params('folderId'); - $newestItemId = (int) $this->params('newestItemId'); - + public function read($folderId, $newestItemId) { $this->itemBusinessLayer->readFolder($folderId, $newestItemId, $this->userId); } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index 76476dd7a..9b0db2be7 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -16,7 +16,6 @@ namespace OCA\News\Controller; use \OCP\IRequest; use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; -use \OCP\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; @@ -25,6 +24,7 @@ use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\BusinessLayerConflictException; use \OCA\News\BusinessLayer\BusinessLayerValidationException; + class FolderController extends Controller { use JSONHttpError; @@ -53,10 +53,9 @@ class FolderController extends Controller { */ public function index(){ $folders = $this->folderBusinessLayer->findAll($this->userId); - $result = array( + return array( 'folders' => $folders ); - return $result; } @@ -105,10 +104,9 @@ class FolderController extends Controller { $this->folderBusinessLayer->purgeDeleted($this->userId, false); $folder = $this->folderBusinessLayer->create($folderName, $this->userId); - $params = array( + return array( 'folders' => array($folder) ); - return $params; } catch(BusinessLayerConflictException $ex) { return $this->error($ex, Http::STATUS_CONFLICT); @@ -135,67 +133,54 @@ class FolderController extends Controller { /** * @NoAdminRequired + * + * @param string $folderName + * @param int $folderId */ - public function rename(){ - $folderName = $this->params('folderName'); - $folderId = (int) $this->params('folderId'); - + public function rename($folderName, $folderId){ try { $folder = $this->folderBusinessLayer->rename($folderId, $folderName, $this->userId); - $params = array( + return array( 'folders' => array($folder) ); - return new JSONResponse($params); - + } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_CONFLICT); - + return $this->error($ex, Http::STATUS_CONFLICT); } catch(BusinessLayerValidationException $ex) { - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_UNPROCESSABLE_ENTITY); - + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } 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 $folderId + * @param int $highestItemId */ - public function read(){ - $folderId = (int) $this->params('folderId'); - $highestItemId = (int) $this->params('highestItemId'); - + public function read($folderId, $highestItemId){ $this->itemBusinessLayer->readFolder($folderId, $highestItemId, $this->userId); - $params = array( + return array( 'feeds' => $this->feedBusinessLayer->findAll($this->userId) ); - return new JSONResponse($params); } /** * @NoAdminRequired + * + * @param int $folderId */ - public function restore(){ - $folderId = (int) $this->params('folderId'); - + public function restore($folderId){ try { $this->folderBusinessLayer->unmarkDeleted($folderId, $this->userId); } catch (BusinessLayerException $ex){ - return new JSONResponse(array( - 'msg' => $ex->getMessage() - ), Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } - } diff --git a/controller/itemapicontroller.php b/controller/itemapicontroller.php index 767023877..8cd8b5578 100644 --- a/controller/itemapicontroller.php +++ b/controller/itemapicontroller.php @@ -16,7 +16,6 @@ namespace OCA\News\Controller; use \OCP\IRequest; use \OCP\AppFramework\ApiController; use \OCP\AppFramework\Http; -use \OCP\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -50,24 +49,10 @@ class ItemApiController extends ApiController { * @param int $offset */ public function index($type, $id, $getRead, $batchSize=20, $offset=0) { - $result = array( - 'items' => array() - ); - - $items = $this->itemBusinessLayer->findAll( - $id, - $type, - $batchSize, - $offset, - $showAll, - $this->userId - ); - - foreach ($items as $item) { - array_push($result['items'], $item->toAPI()); - } + $this->registerSerializer(new EntityApiSerializer('items')); - return $result; + return $this->itemBusinessLayer->findAll($id, $type, $batchSize, $offset, + $showAll, $this->userId); } @@ -81,23 +66,10 @@ class ItemApiController extends ApiController { * @param int $lastModified */ public function updated($type, $id, $lastModified=0) { - $result = array( - 'items' => array() - ); - - $items = $this->itemBusinessLayer->findAllNew( - $id, - $type, - $lastModified, - true, - $this->userId - ); - - foreach ($items as $item) { - array_push($result['items'], $item->toAPI()); - } + $this->registerSerializer(new EntityApiSerializer('items')); - $result; + return $this->itemBusinessLayer->findAllNew($id, $type, $lastModified, + true, $this->userId); } @@ -219,8 +191,8 @@ class ItemApiController extends ApiController { private function setMultipleStarred($isStarred, $items) { foreach($items as $item) { try { - $this->itemBusinessLayer->star($item['feedId'], - $item['guidHash'], $isStarred, $this->userId); + $this->itemBusinessLayer->star($item['feedId'], $item['guidHash'], + $isStarred, $this->userId); } catch(BusinessLayerException $ex) { continue; } 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); } diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php index 5a9c592f5..b621a8ae3 100644 --- a/controller/pagecontroller.php +++ b/controller/pagecontroller.php @@ -19,6 +19,7 @@ use \OCP\IL10N; use \OCP\AppFramework\Http\JSONResponse; use \OCP\AppFramework\Controller; + class PageController extends Controller { private $settings; @@ -56,20 +57,19 @@ class PageController extends Controller { 'compact'); $language = $this->l10n->findLanguage(); - $settings = array( + return array( 'showAll' => $showAll === '1', 'compact' => $compact === '1', 'language' => $language ); - - return $settings; } /** * @NoAdminRequired * - * + * @param bool $showAll + * @param bool $compact */ public function updateSettings($showAll, $compact) { if($showAll !== null) { diff --git a/controller/utilityapicontroller.php b/controller/utilityapicontroller.php index cb36b97b9..ea94d33ea 100644 --- a/controller/utilityapicontroller.php +++ b/controller/utilityapicontroller.php @@ -22,6 +22,7 @@ use \OCP\AppFramework\Http\Response; use \OCA\News\Utility\Updater; + class UtilityApiController extends ApiController { private $updater; -- cgit v1.2.3