From dbd18a20993221baf9e851fbd8eba1a48c411b3d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sun, 6 Apr 2014 15:26:45 +0200 Subject: get rid of deprecated getParams and renderJSON method to ease transition to built in appframework --- controller/feedcontroller.php | 53 +++++++++++++++++++--------- controller/foldercontroller.php | 66 ++++++++++++++++++++++++++--------- controller/itemcontroller.php | 32 +++++++++++------ controller/usersettingscontroller.php | 14 ++++---- 4 files changed, 114 insertions(+), 51 deletions(-) (limited to 'controller') diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index e9561cf32..b0b856b79 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -28,11 +28,14 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\BusinessLayer\BusinessLayerConflictException; use \OCA\News\Db\FeedType; @@ -74,7 +77,7 @@ class FeedController extends Controller { $this->itemBusinessLayer->getNewestItemId($userId); } catch (BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -118,7 +121,7 @@ class FeedController extends Controller { ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -147,9 +150,17 @@ class FeedController extends Controller { $this->itemBusinessLayer->getNewestItemId($userId); } catch (BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); } } @@ -165,9 +176,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->markDeleted($feedId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -195,10 +208,12 @@ class FeedController extends Controller { ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -215,9 +230,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->move($feedId, $parentFolderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -233,9 +250,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->rename($feedId, $feedTitle, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -255,7 +274,7 @@ class FeedController extends Controller { $params['feeds'] = array($feed); } - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -279,7 +298,7 @@ class FeedController extends Controller { ) ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -294,9 +313,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->unmarkDeleted($feedId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index 546ce60b6..09d226920 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -28,12 +28,15 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; - +use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\BusinessLayer\BusinessLayerValidationException; class FolderController extends Controller { @@ -62,7 +65,7 @@ class FolderController extends Controller { $result = array( 'folders' => $folders ); - return $this->renderJSON($result); + return new JSONResponse($result); } @@ -82,9 +85,11 @@ class FolderController extends Controller { public function open(){ try { $this->setOpened(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -97,9 +102,11 @@ class FolderController extends Controller { public function collapse(){ try { $this->setOpened(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -123,10 +130,19 @@ class FolderController extends Controller { $params = array( 'folders' => array($folder) ); - return $this->renderJSON($params); + return new JSONResponse($params); - } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + + } catch(BusinessLayerValidationException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); } } @@ -143,9 +159,11 @@ class FolderController extends Controller { try { $this->folderBusinessLayer->markDeleted($folderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -166,10 +184,22 @@ class FolderController extends Controller { $params = array( 'folders' => array($folder) ); - return $this->renderJSON($params); - + return new JSONResponse($params); + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + + } catch(BusinessLayerValidationException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); + } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -188,7 +218,7 @@ class FolderController extends Controller { $params = array( 'feeds' => $this->feedBusinessLayer->findAll($userId) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -203,9 +233,11 @@ class FolderController extends Controller { try { $this->folderBusinessLayer->unmarkDeleted($folderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index a3f632e39..637c5fd49 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -28,6 +28,8 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -85,7 +87,7 @@ class ItemController extends Controller { // in that case just return an empty array } catch(BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -114,7 +116,7 @@ class ItemController extends Controller { // in that case just return an empty array } catch(BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -135,9 +137,11 @@ class ItemController extends Controller { public function star(){ try { $this->setStarred(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -150,9 +154,11 @@ class ItemController extends Controller { public function unstar(){ try { $this->setStarred(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -173,9 +179,11 @@ class ItemController extends Controller { public function read(){ try { $this->setRead(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -188,9 +196,11 @@ class ItemController extends Controller { public function unread(){ try { $this->setRead(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -209,7 +219,7 @@ class ItemController extends Controller { $params = array( 'feeds' => $this->feedBusinessLayer->findAll($userId) ); - return $this->renderJSON($params); + return new JSONResponse($params); } diff --git a/controller/usersettingscontroller.php b/controller/usersettingscontroller.php index 9dd14fbf2..a34d5397e 100644 --- a/controller/usersettingscontroller.php +++ b/controller/usersettingscontroller.php @@ -28,7 +28,7 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; - +use \OCA\AppFramework\Http\JSONResponse; class UserSettingsController extends Controller { @@ -49,7 +49,7 @@ class UserSettingsController extends Controller { 'showAll' => $showAll === '1' ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -61,7 +61,7 @@ class UserSettingsController extends Controller { public function show(){ $this->api->setUserValue('showAll', true); - return $this->renderJSON(); + return new JSONResponse(); } @@ -73,7 +73,7 @@ class UserSettingsController extends Controller { public function hide(){ $this->api->setUserValue('showAll', false); - return $this->renderJSON(); + return new JSONResponse(); } @@ -88,7 +88,7 @@ class UserSettingsController extends Controller { $params = array( 'language' => $language ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -102,7 +102,7 @@ class UserSettingsController extends Controller { $params = array( 'compact' => $compact === '1' ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -115,7 +115,7 @@ class UserSettingsController extends Controller { $isCompact = $this->params('compact'); $this->api->setUserValue('compact', $isCompact); - return $this->renderJSON(); + return new JSONResponse(); } -- cgit v1.2.3