diff options
author | David Guillot <david@guillot.me> | 2018-06-29 22:28:12 +0200 |
---|---|---|
committer | David Guillot <david@guillot.me> | 2018-07-01 23:01:54 +0200 |
commit | a84e80131a891184e234ddeee1ba0606ea898d7b (patch) | |
tree | 493d7a609192c86cb3c5b79a5e2ab8d193386f90 /lib/Controller/FeedApiController.php | |
parent | ec3cc602f1bd363efe776ce4914319034d35c18e (diff) |
feat(api): support new OC core login flow
* Base ApiController now needs IUserSession and extracts/serves IUser from it
* All other API controllers now inherit from ApiController
Diffstat (limited to 'lib/Controller/FeedApiController.php')
-rw-r--r-- | lib/Controller/FeedApiController.php | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index 344d72bd0..2e4a85eef 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -7,14 +7,17 @@ * * @author Alessandro Cosentino <cosenal@gmail.com> * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author David Guillot <david@guillot.me> * @copyright 2012 Alessandro Cosentino * @copyright 2012-2014 Bernhard Posselt + * @copyright 2018 David Guillot */ namespace OCA\News\Controller; use \OCP\IRequest; use \OCP\ILogger; +use \OCP\IUserSession; use \OCP\AppFramework\Http; use \OCA\News\Service\FeedService; @@ -30,23 +33,21 @@ class FeedApiController extends ApiController private $itemService; private $feedService; - private $userId; private $logger; private $loggerParams; private $serializer; public function __construct($appName, IRequest $request, + IUserSession $userSession, FeedService $feedService, ItemService $itemService, ILogger $logger, - $UserId, $LoggerParameters ) { - parent::__construct($appName, $request); + parent::__construct($appName, $request, $userSession); $this->feedService = $feedService; $this->itemService = $itemService; - $this->userId = $UserId; $this->logger = $logger; $this->loggerParams = $LoggerParameters; $this->serializer = new EntityApiSerializer('feeds'); @@ -62,14 +63,14 @@ class FeedApiController extends ApiController { $result = [ - 'starredCount' => $this->itemService->starredCount($this->userId), - 'feeds' => $this->feedService->findAll($this->userId) + 'starredCount' => $this->itemService->starredCount($this->getUserId()), + 'feeds' => $this->feedService->findAll($this->getUserId()) ]; try { $result['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); + $this->itemService->getNewestItemId($this->getUserId()); // in case there are no items, ignore } catch(ServiceNotFoundException $ex) { @@ -91,14 +92,14 @@ class FeedApiController extends ApiController public function create($url, $folderId=0) { try { - $this->feedService->purgeDeleted($this->userId, false); + $this->feedService->purgeDeleted($this->getUserId(), false); - $feed = $this->feedService->create($url, $folderId, $this->userId); + $feed = $this->feedService->create($url, $folderId, $this->getUserId()); $result = ['feeds' => [$feed]]; try { $result['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); + $this->itemService->getNewestItemId($this->getUserId()); // in case there are no items, ignore } catch(ServiceNotFoundException $ex) { @@ -125,7 +126,7 @@ class FeedApiController extends ApiController public function delete($feedId) { try { - $this->feedService->delete($feedId, $this->userId); + $this->feedService->delete($feedId, $this->getUserId()); } catch(ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -144,7 +145,7 @@ class FeedApiController extends ApiController */ public function read($feedId, $newestItemId) { - $this->itemService->readFeed($feedId, $newestItemId, $this->userId); + $this->itemService->readFeed($feedId, $newestItemId, $this->getUserId()); } @@ -161,7 +162,7 @@ class FeedApiController extends ApiController { try { $this->feedService->patch( - $feedId, $this->userId, ['folderId' => $folderId] + $feedId, $this->getUserId(), ['folderId' => $folderId] ); } catch(ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); @@ -184,7 +185,7 @@ class FeedApiController extends ApiController { try { $this->feedService->patch( - $feedId, $this->userId, ['title' => $feedTitle] + $feedId, $this->getUserId(), ['title' => $feedTitle] ); } catch(ServiceNotFoundException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); |