summaryrefslogtreecommitdiffstats
path: root/controller/feedapicontroller.php
diff options
context:
space:
mode:
Diffstat (limited to 'controller/feedapicontroller.php')
-rw-r--r--controller/feedapicontroller.php262
1 files changed, 131 insertions, 131 deletions
diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php
index 33a9cbb7f..c75cd5879 100644
--- a/controller/feedapicontroller.php
+++ b/controller/feedapicontroller.php
@@ -26,53 +26,53 @@ use \OCA\News\Service\ServiceConflictException;
class FeedApiController extends ApiController {
- use JSONHttpError;
-
- private $itemService;
- private $feedService;
- private $userId;
- private $logger;
- private $loggerParams;
- private $serializer;
-
- public function __construct($appName,
- IRequest $request,
- FeedService $feedService,
- ItemService $itemService,
- ILogger $logger,
- $userId,
- $loggerParams){
- parent::__construct($appName, $request);
- $this->feedService = $feedService;
- $this->itemService = $itemService;
- $this->userId = $userId;
- $this->logger = $logger;
- $this->loggerParams = $loggerParams;
- $this->serializer = new EntityApiSerializer('feeds');
- }
-
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @CORS
- */
- public function index() {
-
- $result = [
- 'starredCount' => $this->itemService->starredCount($this->userId),
- 'feeds' => $this->feedService->findAll($this->userId)
- ];
-
-
- try {
- $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId);
-
- // in case there are no items, ignore
- } catch(ServiceNotFoundException $ex) {}
-
- return $this->serializer->serialize($result);
- }
+ use JSONHttpError;
+
+ private $itemService;
+ private $feedService;
+ private $userId;
+ private $logger;
+ private $loggerParams;
+ private $serializer;
+
+ public function __construct($appName,
+ IRequest $request,
+ FeedService $feedService,
+ ItemService $itemService,
+ ILogger $logger,
+ $userId,
+ $loggerParams){
+ parent::__construct($appName, $request);
+ $this->feedService = $feedService;
+ $this->itemService = $itemService;
+ $this->userId = $userId;
+ $this->logger = $logger;
+ $this->loggerParams = $loggerParams;
+ $this->serializer = new EntityApiSerializer('feeds');
+ }
+
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ */
+ public function index() {
+
+ $result = [
+ 'starredCount' => $this->itemService->starredCount($this->userId),
+ 'feeds' => $this->feedService->findAll($this->userId)
+ ];
+
+
+ try {
+ $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId);
+
+ // in case there are no items, ignore
+ } catch(ServiceNotFoundException $ex) {}
+
+ return $this->serializer->serialize($result);
+ }
/**
@@ -84,27 +84,27 @@ class FeedApiController extends ApiController {
* @param int $folderId
* @return array|mixed|\OCP\AppFramework\Http\JSONResponse
*/
- public function create($url, $folderId=0) {
- try {
- $this->feedService->purgeDeleted($this->userId, false);
+ public function create($url, $folderId=0) {
+ try {
+ $this->feedService->purgeDeleted($this->userId, false);
- $feed = $this->feedService->create($url, $folderId, $this->userId);
- $result = ['feeds' => [$feed]];
+ $feed = $this->feedService->create($url, $folderId, $this->userId);
+ $result = ['feeds' => [$feed]];
- try {
- $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId);
+ try {
+ $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId);
- // in case there are no items, ignore
- } catch(ServiceNotFoundException $ex) {}
+ // in case there are no items, ignore
+ } catch(ServiceNotFoundException $ex) {}
- return $this->serializer->serialize($result);
+ return $this->serializer->serialize($result);
- } catch(ServiceConflictException $ex) {
- return $this->error($ex, Http::STATUS_CONFLICT);
- } catch(ServiceNotFoundException $ex) {
- return $this->error($ex, Http::STATUS_NOT_FOUND);
- }
- }
+ } catch(ServiceConflictException $ex) {
+ return $this->error($ex, Http::STATUS_CONFLICT);
+ } catch(ServiceNotFoundException $ex) {
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
+ }
+ }
/**
@@ -115,28 +115,28 @@ class FeedApiController extends ApiController {
* @param int $feedId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function delete($feedId) {
- try {
- $this->feedService->delete($feedId, $this->userId);
- } catch(ServiceNotFoundException $ex) {
- return $this->error($ex, Http::STATUS_NOT_FOUND);
- }
+ public function delete($feedId) {
+ try {
+ $this->feedService->delete($feedId, $this->userId);
+ } catch(ServiceNotFoundException $ex) {
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
+ }
return [];
- }
+ }
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @CORS
- *
- * @param int $feedId
- * @param int $newestItemId
- */
- public function read($feedId, $newestItemId) {
- $this->itemService->readFeed($feedId, $newestItemId, $this->userId);
- }
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
+ * @param int $feedId
+ * @param int $newestItemId
+ */
+ public function read($feedId, $newestItemId) {
+ $this->itemService->readFeed($feedId, $newestItemId, $this->userId);
+ }
/**
@@ -148,15 +148,15 @@ class FeedApiController extends ApiController {
* @param int $folderId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function move($feedId, $folderId) {
- try {
- $this->feedService->move($feedId, $folderId, $this->userId);
- } catch(ServiceNotFoundException $ex) {
- return $this->error($ex, Http::STATUS_NOT_FOUND);
- }
+ public function move($feedId, $folderId) {
+ try {
+ $this->feedService->move($feedId, $folderId, $this->userId);
+ } catch(ServiceNotFoundException $ex) {
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
+ }
return [];
- }
+ }
/**
@@ -168,51 +168,51 @@ class FeedApiController extends ApiController {
* @param string $feedTitle
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function rename($feedId, $feedTitle) {
- try {
- $this->feedService->rename($feedId, $feedTitle, $this->userId);
- } catch(ServiceNotFoundException $ex) {
- return $this->error($ex, Http::STATUS_NOT_FOUND);
- }
+ public function rename($feedId, $feedTitle) {
+ try {
+ $this->feedService->rename($feedId, $feedTitle, $this->userId);
+ } catch(ServiceNotFoundException $ex) {
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
+ }
return [];
- }
-
-
- /**
- * @NoCSRFRequired
- * @CORS
- */
- public function fromAllUsers() {
- $feeds = $this->feedService->findAllFromAllUsers();
- $result = ['feeds' => []];
-
- foreach ($feeds as $feed) {
- $result['feeds'][] = [
- 'id' => $feed->getId(),
- 'userId' => $feed->getUserId()
- ];
- }
-
- return $result;
- }
-
-
- /**
- * @NoCSRFRequired
- *
- * @param string $userId
- * @param int $feedId
- */
- public function update($userId, $feedId) {
- try {
- $this->feedService->update($feedId, $userId);
- // ignore update failure (feed could not be reachable etc, we don't care)
- } catch(\Exception $ex) {
- $this->logger->debug('Could not update feed ' . $ex->getMessage(),
- $this->loggerParams);
- }
- }
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ * @CORS
+ */
+ public function fromAllUsers() {
+ $feeds = $this->feedService->findAllFromAllUsers();
+ $result = ['feeds' => []];
+
+ foreach ($feeds as $feed) {
+ $result['feeds'][] = [
+ 'id' => $feed->getId(),
+ 'userId' => $feed->getUserId()
+ ];
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * @NoCSRFRequired
+ *
+ * @param string $userId
+ * @param int $feedId
+ */
+ public function update($userId, $feedId) {
+ try {
+ $this->feedService->update($feedId, $userId);
+ // ignore update failure (feed could not be reachable etc, we don't care)
+ } catch(\Exception $ex) {
+ $this->logger->debug('Could not update feed ' . $ex->getMessage(),
+ $this->loggerParams);
+ }
+ }
}