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/ItemApiController.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/ItemApiController.php')
-rw-r--r-- | lib/Controller/ItemApiController.php | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index ae523a5f1..601a3b409 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -7,13 +7,16 @@ * * @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\IUserSession; use \OCP\AppFramework\Http; use \OCA\News\Service\ItemService; @@ -25,17 +28,15 @@ class ItemApiController extends ApiController use JSONHttpError; private $itemService; - private $userId; private $serializer; public function __construct($appName, IRequest $request, - ItemService $itemService, - $UserId + IUserSession $userSession, + ItemService $itemService ) { - parent::__construct($appName, $request); + parent::__construct($appName, $request, $userSession); $this->itemService = $itemService; - $this->userId = $UserId; $this->serializer = new EntityApiSerializer('items'); } @@ -59,7 +60,7 @@ class ItemApiController extends ApiController return $this->serializer->serialize( $this->itemService->findAll( $id, $type, $batchSize, $offset, $getRead, $oldestFirst, - $this->userId + $this->getUserId() ) ); } @@ -86,7 +87,7 @@ class ItemApiController extends ApiController return $this->serializer->serialize( $this->itemService->findAllNew( $id, $type, $paddedLastModified, - true, $this->userId + true, $this->getUserId() ) ); } @@ -95,7 +96,7 @@ class ItemApiController extends ApiController private function setRead($isRead, $itemId) { try { - $this->itemService->read($itemId, $isRead, $this->userId); + $this->itemService->read($itemId, $isRead, $this->getUserId()); } catch(ServiceNotFoundException $ex){ return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -136,7 +137,7 @@ class ItemApiController extends ApiController { try { $this->itemService->star( - $feedId, $guidHash, $isStarred, $this->userId + $feedId, $guidHash, $isStarred, $this->getUserId() ); } catch(ServiceNotFoundException $ex){ return $this->error($ex, Http::STATUS_NOT_FOUND); @@ -185,7 +186,7 @@ class ItemApiController extends ApiController */ public function readAll($newestItemId) { - $this->itemService->readAll($newestItemId, $this->userId); + $this->itemService->readAll($newestItemId, $this->getUserId()); } @@ -193,7 +194,7 @@ class ItemApiController extends ApiController { foreach($items as $id) { try { - $this->itemService->read($id, $isRead, $this->userId); + $this->itemService->read($id, $isRead, $this->getUserId()); } catch(ServiceNotFoundException $ex) { continue; } @@ -233,7 +234,7 @@ class ItemApiController extends ApiController try { $this->itemService->star( $item['feedId'], $item['guidHash'], - $isStarred, $this->userId + $isStarred, $this->getUserId() ); } catch(ServiceNotFoundException $ex) { continue; |