diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-19 13:20:54 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-19 13:21:11 +0200 |
commit | 517e4ca5435106ab5304849248cbea4e9dffd4b0 (patch) | |
tree | 0f00076f012791b39c710994f695abf723546062 /controller | |
parent | bd35b98d2c130f058b182f726636ee971625823b (diff) |
split up api class for easier testing and clearer code
Diffstat (limited to 'controller')
-rw-r--r-- | controller/apicontroller.php | 13 | ||||
-rw-r--r-- | controller/exportcontroller.php | 23 | ||||
-rw-r--r-- | controller/feedapicontroller.php | 44 | ||||
-rw-r--r-- | controller/feedcontroller.php | 61 | ||||
-rw-r--r-- | controller/folderapicontroller.php | 29 | ||||
-rw-r--r-- | controller/foldercontroller.php | 38 | ||||
-rw-r--r-- | controller/itemapicontroller.php | 33 | ||||
-rw-r--r-- | controller/itemcontroller.php | 54 | ||||
-rw-r--r-- | controller/pagecontroller.php | 23 |
9 files changed, 149 insertions, 169 deletions
diff --git a/controller/apicontroller.php b/controller/apicontroller.php index 9e0ff2401..25b230016 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -32,17 +32,18 @@ use \OCP\AppFramework\Http\JSONResponse; use \OCP\AppFramework\Http\Response; use \OCA\News\Utility\Updater; -use \OCA\News\Core\API; +use \OCA\News\Core\Settings; class ApiController extends Controller { private $updater; - private $api; + private $settings; - public function __construct(API $api, IRequest $request, Updater $updater){ - parent::__construct($api->getAppName(), $request); + public function __construct($appName, IRequest $request, Updater $updater, + Settings $settings){ + parent::__construct($appName, $request); $this->updater = $updater; - $this->api = $api; + $this->settings = $settings; } @@ -52,7 +53,7 @@ class ApiController extends Controller { * @API */ public function version() { - $version = $this->api->getAppValue('installed_version'); + $version = $this->settings->getAppValue('installed_version'); $response = new JSONResponse(array('version' => $version)); return $response; } diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php index 33cb05204..a0011f9e6 100644 --- a/controller/exportcontroller.php +++ b/controller/exportcontroller.php @@ -32,7 +32,6 @@ use \OCP\AppFramework\Http\JSONResponse; use \OCP\AppFramework\Http\Response; use \OCA\News\Http\TextDownloadResponse; -use \OCA\News\Core\API; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -44,19 +43,21 @@ class ExportController extends Controller { private $folderBusinessLayer; private $feedBusinessLayer; private $itemBusinessLayer; - private $api; + private $userId; - public function __construct(API $api, IRequest $request, + public function __construct($appName, + IRequest $request, FeedBusinessLayer $feedBusinessLayer, FolderBusinessLayer $folderBusinessLayer, ItemBusinessLayer $itemBusinessLayer, - OPMLExporter $opmlExporter){ - parent::__construct($api->getAppName(), $request); + OPMLExporter $opmlExporter, + $userId){ + parent::__construct($appName, $request); $this->feedBusinessLayer = $feedBusinessLayer; $this->folderBusinessLayer = $folderBusinessLayer; $this->opmlExporter = $opmlExporter; $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; } @@ -65,9 +66,8 @@ class ExportController extends Controller { * @NoCSRFRequired */ public function opml(){ - $userId = $this->api->getUserId(); - $feeds = $this->feedBusinessLayer->findAll($userId); - $folders = $this->folderBusinessLayer->findAll($userId); + $feeds = $this->feedBusinessLayer->findAll($this->userId); + $folders = $this->folderBusinessLayer->findAll($this->userId); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); return new TextDownloadResponse($opml, 'subscriptions.opml', 'text/xml'); } @@ -78,9 +78,8 @@ class ExportController extends Controller { * @NoCSRFRequired */ public function articles(){ - $userId = $this->api->getUserId(); - $feeds = $this->feedBusinessLayer->findAll($userId); - $items = $this->itemBusinessLayer->getUnreadOrStarred($userId); + $feeds = $this->feedBusinessLayer->findAll($this->userId); + $items = $this->itemBusinessLayer->getUnreadOrStarred($this->userId); // build assoc array for fast access $feedsDict = array(); diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php index 6537e51df..51aa48dd9 100644 --- a/controller/feedapicontroller.php +++ b/controller/feedapicontroller.php @@ -30,7 +30,7 @@ use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\Core\API; +use \OCA\News\Core\Logger; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -43,18 +43,22 @@ class FeedApiController extends Controller { private $itemBusinessLayer; private $feedBusinessLayer; private $folderBusinessLayer; - private $api; + private $userId; + private $logger; - public function __construct(API $api, + public function __construct($appName, IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, - ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api->getAppName(), $request); + ItemBusinessLayer $itemBusinessLayer, + Logger $logger, + $userId){ + parent::__construct($appName, $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; + $this->logger = $logger; } @@ -64,21 +68,20 @@ class FeedApiController extends Controller { * @API */ public function index() { - $userId = $this->api->getUserId(); $result = array( 'feeds' => array(), - 'starredCount' => $this->itemBusinessLayer->starredCount($userId) + 'starredCount' => $this->itemBusinessLayer->starredCount($this->userId) ); - foreach ($this->feedBusinessLayer->findAll($userId) as $feed) { + foreach ($this->feedBusinessLayer->findAll($this->userId) as $feed) { array_push($result['feeds'], $feed->toAPI()); } // check case when there are no items try { $result['newestItemId'] = - $this->itemBusinessLayer->getNewestItemId($userId); + $this->itemBusinessLayer->getNewestItemId($this->userId); } catch(BusinessLayerException $ex) {} return new JSONResponse($result); @@ -91,21 +94,20 @@ class FeedApiController extends Controller { * @API */ public function create() { - $userId = $this->api->getUserId(); $feedUrl = $this->params('url'); $folderId = (int) $this->params('folderId', 0); try { - $this->feedBusinessLayer->purgeDeleted($userId, false); + $this->feedBusinessLayer->purgeDeleted($this->userId, false); - $feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $userId); + $feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $this->userId); $result = array( 'feeds' => array($feed->toAPI()) ); try { $result['newestItemId'] = - $this->itemBusinessLayer->getNewestItemId($userId); + $this->itemBusinessLayer->getNewestItemId($this->userId); } catch(BusinessLayerException $ex) {} return new JSONResponse($result); @@ -126,11 +128,10 @@ class FeedApiController extends Controller { * @API */ public function delete() { - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); try { - $this->feedBusinessLayer->delete($feedId, $userId); + $this->feedBusinessLayer->delete($feedId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array('message' => $ex->getMessage()), @@ -145,11 +146,10 @@ class FeedApiController extends Controller { * @API */ public function read() { - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $newestItemId = (int) $this->params('newestItemId'); - $this->itemBusinessLayer->readFeed($feedId, $newestItemId, $userId); + $this->itemBusinessLayer->readFeed($feedId, $newestItemId, $this->userId); return new JSONResponse(); } @@ -160,12 +160,11 @@ class FeedApiController extends Controller { * @API */ public function move() { - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $folderId = (int) $this->params('folderId'); try { - $this->feedBusinessLayer->move($feedId, $folderId, $userId); + $this->feedBusinessLayer->move($feedId, $folderId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array('message' => $ex->getMessage()), @@ -180,12 +179,11 @@ class FeedApiController extends Controller { * @API */ public function rename() { - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $feedTitle = $this->params('feedTitle'); try { - $this->feedBusinessLayer->rename($feedId, $feedTitle, $userId); + $this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array('message' => $ex->getMessage()), @@ -225,7 +223,7 @@ class FeedApiController extends Controller { $this->feedBusinessLayer->update($feedId, $userId); // ignore update failure (feed could not be reachable etc, we dont care) } catch(\Exception $ex) { - $this->api->log('Could not update feed ' . $ex->getMessage(), + $this->logger->log('Could not update feed ' . $ex->getMessage(), 'debug'); } return new JSONResponse(); diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index cfd4458a9..9d7f091bc 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -30,7 +30,7 @@ use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\Core\API; +use \OCA\News\Core\Settings; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; @@ -44,17 +44,22 @@ class FeedController extends Controller { private $feedBusinessLayer; private $folderBusinessLayer; private $itemBusinessLayer; - private $api; + private $userId; + private $settings; - public function __construct(API $api, IRequest $request, + public function __construct($appName, + IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, - ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api->getAppName(), $request); + ItemBusinessLayer $itemBusinessLayer, + $userId, + Settings $settings){ + parent::__construct($appName, $request); $this->feedBusinessLayer = $feedBusinessLayer; $this->folderBusinessLayer = $folderBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; + $this->settings = $settings; } @@ -62,19 +67,18 @@ class FeedController extends Controller { * @NoAdminRequired */ public function index(){ - $userId = $this->api->getUserId(); // this method is also used to update the interface // because of this we also pass the starred count and the newest // item id which will be used for marking feeds read $params = array( - 'feeds' => $this->feedBusinessLayer->findAll($userId), - 'starred' => $this->itemBusinessLayer->starredCount($userId) + 'feeds' => $this->feedBusinessLayer->findAll($this->userId), + 'starred' => $this->itemBusinessLayer->starredCount($this->userId) ); try { $params['newestItemId'] = - $this->itemBusinessLayer->getNewestItemId($userId); + $this->itemBusinessLayer->getNewestItemId($this->userId); } catch (BusinessLayerException $ex) {} return new JSONResponse($params); @@ -85,9 +89,8 @@ class FeedController extends Controller { * @NoAdminRequired */ public function active(){ - $userId = $this->api->getUserId(); - $feedId = (int) $this->api->getUserValue('lastViewedFeedId'); - $feedType = $this->api->getUserValue('lastViewedFeedType'); + $feedId = (int) $this->settings->getUserValue('lastViewedFeedId'); + $feedType = $this->settings->getUserValue('lastViewedFeedType'); // cast from null to int is 0 if($feedType !== null){ @@ -97,10 +100,10 @@ class FeedController extends Controller { // check if feed or folder exists try { if($feedType === FeedType::FOLDER){ - $this->folderBusinessLayer->find($feedId, $userId); + $this->folderBusinessLayer->find($feedId, $this->userId); } elseif ($feedType === FeedType::FEED){ - $this->feedBusinessLayer->find($feedId, $userId); + $this->feedBusinessLayer->find($feedId, $this->userId); // if its the first launch, those values will be null } elseif($feedType === null){ @@ -129,21 +132,20 @@ class FeedController extends Controller { public function create(){ $url = $this->params('url'); $parentFolderId = (int) $this->params('parentFolderId'); - $userId = $this->api->getUserId(); try { // we need to purge deleted feeds if a feed is created to // prevent already exists exceptions - $this->feedBusinessLayer->purgeDeleted($userId, false); + $this->feedBusinessLayer->purgeDeleted($this->userId, false); - $feed = $this->feedBusinessLayer->create($url, $parentFolderId, $userId); + $feed = $this->feedBusinessLayer->create($url, $parentFolderId, $this->userId); $params = array( 'feeds' => array($feed) ); try { $params['newestItemId'] = - $this->itemBusinessLayer->getNewestItemId($userId); + $this->itemBusinessLayer->getNewestItemId($this->userId); } catch (BusinessLayerException $ex) {} return new JSONResponse($params); @@ -166,10 +168,9 @@ class FeedController extends Controller { */ public function delete(){ $feedId = (int) $this->params('feedId'); - $userId = $this->api->getUserId(); try { - $this->feedBusinessLayer->markDeleted($feedId, $userId); + $this->feedBusinessLayer->markDeleted($feedId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array( @@ -185,9 +186,8 @@ class FeedController extends Controller { public function update(){ try { $feedId = (int) $this->params('feedId'); - $userId = $this->api->getUserId(); - $feed = $this->feedBusinessLayer->update($feedId, $userId); + $feed = $this->feedBusinessLayer->update($feedId, $this->userId); $params = array( 'feeds' => array( @@ -216,10 +216,9 @@ class FeedController extends Controller { public function move(){ $feedId = (int) $this->params('feedId'); $parentFolderId = (int) $this->params('parentFolderId'); - $userId = $this->api->getUserId(); try { - $this->feedBusinessLayer->move($feedId, $parentFolderId, $userId); + $this->feedBusinessLayer->move($feedId, $parentFolderId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array( @@ -234,10 +233,9 @@ class FeedController extends Controller { public function rename() { $feedId = (int) $this->params('feedId'); $feedTitle = $this->params('feedTitle'); - $userId = $this->api->getUserId(); try { - $this->feedBusinessLayer->rename($feedId, $feedTitle, $userId); + $this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array( @@ -251,9 +249,8 @@ class FeedController extends Controller { */ public function import() { $json = $this->params('json'); - $userId = $this->api->getUserId(); - $feed = $this->feedBusinessLayer->importArticles($json, $userId); + $feed = $this->feedBusinessLayer->importArticles($json, $this->userId); $params = array(); if($feed) { @@ -268,11 +265,10 @@ class FeedController extends Controller { * @NoAdminRequired */ public function read(){ - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $highestItemId = (int) $this->params('highestItemId'); - $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $userId); + $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $this->userId); $params = array( 'feeds' => array( @@ -291,10 +287,9 @@ class FeedController extends Controller { */ public function restore(){ $feedId = (int) $this->params('feedId'); - $userId = $this->api->getUserId(); try { - $this->feedBusinessLayer->unmarkDeleted($feedId, $userId); + $this->feedBusinessLayer->unmarkDeleted($feedId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array( diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php index 0954380c3..24a7ba151 100644 --- a/controller/folderapicontroller.php +++ b/controller/folderapicontroller.php @@ -30,7 +30,6 @@ use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\Core\API; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -42,16 +41,17 @@ class FolderApiController extends Controller { private $folderBusinessLayer; private $itemBusinessLayer; - private $api; + private $userId; - public function __construct(API $api, + public function __construct($appName, IRequest $request, FolderBusinessLayer $folderBusinessLayer, - ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api->getAppName(), $request); + ItemBusinessLayer $itemBusinessLayer, + $userId){ + parent::__construct($appName, $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; } @@ -61,12 +61,11 @@ class FolderApiController extends Controller { * @API */ public function index() { - $userId = $this->api->getUserId(); $result = array( 'folders' => array() ); - foreach ($this->folderBusinessLayer->findAll($userId) as $folder) { + foreach ($this->folderBusinessLayer->findAll($this->userId) as $folder) { array_push($result['folders'], $folder->toAPI()); } @@ -80,15 +79,14 @@ class FolderApiController extends Controller { * @API */ public function create() { - $userId = $this->api->getUserId(); $folderName = $this->params('name'); $result = array( 'folders' => array() ); try { - $this->folderBusinessLayer->purgeDeleted($userId, false); - $folder = $this->folderBusinessLayer->create($folderName, $userId); + $this->folderBusinessLayer->purgeDeleted($this->userId, false); + $folder = $this->folderBusinessLayer->create($folderName, $this->userId); array_push($result['folders'], $folder->toAPI()); return new JSONResponse($result); @@ -110,11 +108,10 @@ class FolderApiController extends Controller { * @API */ public function delete() { - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); try { - $this->folderBusinessLayer->delete($folderId, $userId); + $this->folderBusinessLayer->delete($folderId, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex) { return new JSONResponse(array('message' => $ex->getMessage()), @@ -129,12 +126,11 @@ class FolderApiController extends Controller { * @API */ public function update() { - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); $folderName = $this->params('name'); try { - $this->folderBusinessLayer->rename($folderId, $folderName, $userId); + $this->folderBusinessLayer->rename($folderId, $folderName, $this->userId); return new JSONResponse(); } catch(BusinessLayerValidationException $ex) { @@ -158,11 +154,10 @@ class FolderApiController extends Controller { * @API */ public function read() { - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); $newestItemId = (int) $this->params('newestItemId'); - $this->itemBusinessLayer->readFolder($folderId, $newestItemId, $userId); + $this->itemBusinessLayer->readFolder($folderId, $newestItemId, $this->userId); return new JSONResponse(); } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index 557315665..1e0eea390 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -30,7 +30,6 @@ use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\Core\API; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -43,17 +42,18 @@ class FolderController extends Controller { private $folderBusinessLayer; private $feedBusinessLayer; private $itemBusinessLayer; - private $api; + private $userId; - public function __construct(API $api, IRequest $request, + public function __construct($appName, IRequest $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, - ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api->getAppName(), $request); + ItemBusinessLayer $itemBusinessLayer, + $userId){ + parent::__construct($appName, $request); $this->folderBusinessLayer = $folderBusinessLayer; $this->feedBusinessLayer = $feedBusinessLayer; $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; } @@ -61,7 +61,7 @@ class FolderController extends Controller { * @NoAdminRequired */ public function index(){ - $folders = $this->folderBusinessLayer->findAll($this->api->getUserId()); + $folders = $this->folderBusinessLayer->findAll($this->userId); $result = array( 'folders' => $folders ); @@ -70,10 +70,9 @@ class FolderController extends Controller { private function setOpened($isOpened){ - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); - $this->folderBusinessLayer->open($folderId, $isOpened, $userId); + $this->folderBusinessLayer->open($folderId, $isOpened, $this->userId); } @@ -111,15 +110,14 @@ class FolderController extends Controller { * @NoAdminRequired */ public function create(){ - $userId = $this->api->getUserId(); $folderName = $this->params('folderName'); try { // we need to purge deleted folders if a folder is created to // prevent already exists exceptions - $this->folderBusinessLayer->purgeDeleted($userId, false); + $this->folderBusinessLayer->purgeDeleted($this->userId, false); - $folder = $this->folderBusinessLayer->create($folderName, $userId); + $folder = $this->folderBusinessLayer->create($folderName, $this->userId); $params = array( 'folders' => array($folder) @@ -146,11 +144,10 @@ class FolderController extends Controller { * @NoAdminRequired */ public function delete(){ - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); try { - $this->folderBusinessLayer->markDeleted($folderId, $userId); + $this->folderBusinessLayer->markDeleted($folderId, $this->userId); return new JSONResponse(); } catch (BusinessLayerException $ex){ return new JSONResponse(array( @@ -164,12 +161,13 @@ class FolderController extends Controller { * @NoAdminRequired */ public function rename(){ - $userId = $this->api->getUserId(); + $userId = $this->userId; $folderName = $this->params('folderName'); $folderId = (int) $this->params('folderId'); try { - $folder = $this->folderBusinessLayer->rename($folderId, $folderName, $userId); + $folder = $this->folderBusinessLayer->rename($folderId, $folderName, + $this->userId); $params = array( 'folders' => array($folder) @@ -197,14 +195,13 @@ class FolderController extends Controller { * @NoAdminRequired */ public function read(){ - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); $highestItemId = (int) $this->params('highestItemId'); - $this->itemBusinessLayer->readFolder($folderId, $highestItemId, $userId); + $this->itemBusinessLayer->readFolder($folderId, $highestItemId, $this->userId); $params = array( - 'feeds' => $this->feedBusinessLayer->findAll($userId) + 'feeds' => $this->feedBusinessLayer->findAll($this->userId) ); return new JSONResponse($params); } @@ -214,11 +211,10 @@ class FolderController extends Controller { * @NoAdminRequired */ public function restore(){ - $userId = $this->api->getUserId(); $folderId = (int) $this->params('folderId'); try { - $this->folderBusinessLayer->unmarkDeleted($folderId, $userId); + $this->folderBusinessLayer->unmarkDeleted($folderId, $this->userId); return new JSONResponse(); } catch (BusinessLayerException $ex){ return new JSONResponse(array( diff --git a/controller/itemapicontroller.php b/controller/itemapicontroller.php index 3b0a5457d..7b1852545 100644 --- a/controller/itemapicontroller.php +++ b/controller/itemapicontroller.php @@ -32,19 +32,19 @@ use \OCP\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\Core\API; class ItemApiController extends Controller { private $itemBusinessLayer; - private $api; + private $userId; - public function __construct(API $api, + public function __construct($appName, IRequest $request, - ItemBusinessLayer $itemBusinessLayer){ - parent::__construct($api->getAppName(), $request); + ItemBusinessLayer $itemBusinessLayer, + $userId){ + parent::__construct($appName, $request); $this->itemBusinessLayer = $itemBusinessLayer; - $this->api = $api; + $this->userId = $userId; } @@ -58,7 +58,6 @@ class ItemApiController extends Controller { 'items' => array() ); - $userId = $this->api->getUserId(); $batchSize = (int) $this->params('batchSize', 20); $offset = (int) $this->params('offset', 0); $type = (int) $this->params('type'); @@ -77,7 +76,7 @@ class ItemApiController extends Controller { $batchSize, $offset, $showAll, - $userId + $this->userId ); foreach ($items as $item) { @@ -98,7 +97,6 @@ class ItemApiController extends Controller { 'items' => array() ); - $userId = $this->api->getUserId(); $lastModified = (int) $this->params('lastModified', 0); $type = (int) $this->params('type'); $id = (int) $this->params('id'); @@ -108,7 +106,7 @@ class ItemApiController extends Controller { $type, $lastModified, true, - $userId + $this->userId ); foreach ($items as $item) { @@ -120,10 +118,9 @@ class ItemApiController extends Controller { private function setRead($isRead) { - $userId = $this->api->getUserId(); $itemId = (int) $this->params('itemId'); try { - $this->itemBusinessLayer->read($itemId, $isRead, $userId); + $this->itemBusinessLayer->read($itemId, $isRead, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex){ return new JSONResponse(array('message' => $ex->getMessage()), @@ -133,11 +130,10 @@ class ItemApiController extends Controller { private function setStarred($isStarred) { - $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $guidHash = $this->params('guidHash'); try { - $this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $userId); + $this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $this->userId); return new JSONResponse(); } catch(BusinessLayerException $ex){ return new JSONResponse(array('message' => $ex->getMessage()), < |