summaryrefslogtreecommitdiffstats
path: root/controller
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 20:14:00 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 20:14:00 +0200
commitf82b818bdb852f63fdb4a431808f37902f4272ff (patch)
tree60e23d0b4b95a5f862661f3ad4fcc8cfa21f076f /controller
parentc9c7b457a09ed3f1899099bba60dad21ff6ad026 (diff)
break all the things!
Diffstat (limited to 'controller')
-rw-r--r--controller/feedapicontroller.php91
-rw-r--r--controller/feedcontroller.php4
-rw-r--r--controller/folderapicontroller.php17
-rw-r--r--controller/foldercontroller.php65
-rw-r--r--controller/itemapicontroller.php146
-rw-r--r--controller/itemcontroller.php8
-rw-r--r--controller/jsonhttperror.php36
-rw-r--r--controller/pagecontroller.php27
-rw-r--r--controller/utilityapicontroller.php (renamed from controller/apicontroller.php)38
9 files changed, 213 insertions, 219 deletions
diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php
index 05c50543e..883732c87 100644
--- a/controller/feedapicontroller.php
+++ b/controller/feedapicontroller.php
@@ -14,11 +14,11 @@
namespace OCA\News\Controller;
use \OCP\IRequest;
-use \OCP\AppFramework\Controller;
+use \OCP\ILogger;
+use \OCP\AppFramework\ApiController;
use \OCP\AppFramework\Http;
use \OCP\AppFramework\Http\JSONResponse;
-use \OCA\News\Core\Logger;
use \OCA\News\BusinessLayer\FeedBusinessLayer;
use \OCA\News\BusinessLayer\FolderBusinessLayer;
use \OCA\News\BusinessLayer\ItemBusinessLayer;
@@ -26,34 +26,37 @@ use \OCA\News\BusinessLayer\BusinessLayerException;
use \OCA\News\BusinessLayer\BusinessLayerConflictException;
-class FeedApiController extends Controller {
+class FeedApiController extends ApiController {
private $itemBusinessLayer;
private $feedBusinessLayer;
private $folderBusinessLayer;
private $userId;
private $logger;
+ private $loggerParams;
public function __construct($appName,
IRequest $request,
FolderBusinessLayer $folderBusinessLayer,
FeedBusinessLayer $feedBusinessLayer,
ItemBusinessLayer $itemBusinessLayer,
- Logger $logger,
- $userId){
+ ILogger $logger,
+ $userId,
+ $loggerParams){
parent::__construct($appName, $request);
$this->folderBusinessLayer = $folderBusinessLayer;
$this->feedBusinessLayer = $feedBusinessLayer;
$this->itemBusinessLayer = $itemBusinessLayer;
$this->userId = $userId;
$this->logger = $logger;
+ $this->loggerParams = $loggerParams;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function index() {
@@ -62,56 +65,66 @@ class FeedApiController extends Controller {
'starredCount' => $this->itemBusinessLayer->starredCount($this->userId)
);
- foreach ($this->feedBusinessLayer->findAll($this->userId) as $feed) {
+ $feeds = $this->feedBusinessLayer->findAll($this->userId);
+ foreach ($feeds as $feed) {
array_push($result['feeds'], $feed->toAPI());
}
// check case when there are no items
try {
- $result['newestItemId'] =
- $this->itemBusinessLayer->getNewestItemId($this->userId);
+ $result['newestItemId'] = $this->itemBusinessLayer
+ ->getNewestItemId($this->userId);
// An exception occurs if there is a newest item. If there is none,
// simply ignore it and do not add the newestItemId
} catch(BusinessLayerException $ex) {}
- return new JSONResponse($result);
+ return $result;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param string $url
+ * @param int $folderId
*/
- public function create() {
- $feedUrl = $this->params('url');
- $folderId = (int) $this->params('folderId', 0);
-
+ public function create($url, $folderId=0) {
try {
$this->feedBusinessLayer->purgeDeleted($this->userId, false);
- $feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $this->userId);
+ $feed = $this->feedBusinessLayer->create($url, $folderId,
+ $this->userId);
$result = array(
'feeds' => array($feed->toAPI())
);
try {
- $result['newestItemId'] =
- $this->itemBusinessLayer->getNewestItemId($this->userId);
+ $result['newestItemId'] = $this->itemBusinessLayer
+ ->getNewestItemId($this->userId);
// An exception occurs if there is a newest item. If there is none,
// simply ignore it and do not add the newestItemId
} catch(BusinessLayerException $ex) {}
- return new JSONResponse($result);
+ return $result;
} catch(BusinessLayerConflictException $ex) {
- return new JSONResponse(array('message' => $ex->getMessage()),
- Http::STATUS_CONFLICT);
+
+ return new JSONResponse(
+ array('message' => $ex->getMessage()),
+ Http::STATUS_CONFLICT
+ );
+
} catch(BusinessLayerException $ex) {
- return new JSONResponse(array('message' => $ex->getMessage()),
- Http::STATUS_NOT_FOUND);
+
+ return new JSONResponse(
+ array('message' => $ex->getMessage()),
+ Http::STATUS_NOT_FOUND
+ );
+
}
}
@@ -119,17 +132,18 @@ class FeedApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $feedId
*/
- public function delete() {
- $feedId = (int) $this->params('feedId');
-
+ public function delete($feedId) {
try {
$this->feedBusinessLayer->delete($feedId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
- return new JSONResponse(array('message' => $ex->getMessage()),
- Http::STATUS_NOT_FOUND);
+ return new JSONResponse(
+ array('message' => $ex->getMessage()),
+ Http::STATUS_NOT_FOUND
+ );
}
}
@@ -137,21 +151,20 @@ class FeedApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function read() {
$feedId = (int) $this->params('feedId');
$newestItemId = (int) $this->params('newestItemId');
$this->itemBusinessLayer->readFeed($feedId, $newestItemId, $this->userId);
- return new JSONResponse();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function move() {
$feedId = (int) $this->params('feedId');
@@ -159,7 +172,6 @@ class FeedApiController extends Controller {
try {
$this->feedBusinessLayer->move($feedId, $folderId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array('message' => $ex->getMessage()),
Http::STATUS_NOT_FOUND);
@@ -170,7 +182,7 @@ class FeedApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function rename() {
$feedId = (int) $this->params('feedId');
@@ -178,7 +190,6 @@ class FeedApiController extends Controller {
try {
$this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array('message' => $ex->getMessage()),
Http::STATUS_NOT_FOUND);
@@ -188,7 +199,7 @@ class FeedApiController extends Controller {
/**
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function fromAllUsers() {
$feeds = $this->feedBusinessLayer->findAllFromAllUsers();
@@ -216,11 +227,9 @@ 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->logger->log('Could not update feed ' . $ex->getMessage(),
- 'debug');
+ $this->logger->debug('Could not update feed ' . $ex->getMessage(),
+ $this->loggerParams);
}
- return new JSONResponse();
-
}
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
index 56c7d5af8..02e523dff 100644
--- a/controller/feedcontroller.php
+++ b/controller/feedcontroller.php
@@ -167,7 +167,6 @@ class FeedController extends Controller {
try {
$this->feedBusinessLayer->markDeleted($feedId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array(
'msg' => $ex->getMessage()
@@ -215,7 +214,6 @@ class FeedController extends Controller {
try {
$this->feedBusinessLayer->move($feedId, $parentFolderId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array(
'msg' => $ex->getMessage()
@@ -232,7 +230,6 @@ class FeedController extends Controller {
try {
$this->feedBusinessLayer->rename($feedId, $feedTitle, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array(
'msg' => $ex->getMessage()
@@ -286,7 +283,6 @@ class FeedController extends Controller {
try {
$this->feedBusinessLayer->unmarkDeleted($feedId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array(
'msg' => $ex->getMessage()
diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php
index 4e566541c..40ffc1389 100644
--- a/controller/folderapicontroller.php
+++ b/controller/folderapicontroller.php
@@ -14,7 +14,7 @@
namespace OCA\News\Controller;
use \OCP\IRequest;
-use \OCP\AppFramework\Controller;
+use \OCP\AppFramework\ApiController;
use \OCP\AppFramework\Http;
use \OCP\AppFramework\Http\JSONResponse;
@@ -25,7 +25,7 @@ use \OCA\News\BusinessLayer\BusinessLayerConflictException;
use \OCA\News\BusinessLayer\BusinessLayerValidationException;
-class FolderApiController extends Controller {
+class FolderApiController extends ApiController {
private $folderBusinessLayer;
private $itemBusinessLayer;
@@ -46,7 +46,7 @@ class FolderApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function index() {
$result = array(
@@ -64,7 +64,7 @@ class FolderApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function create() {
$folderName = $this->params('name');
@@ -93,14 +93,13 @@ class FolderApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function delete() {
$folderId = (int) $this->params('folderId');
try {
$this->folderBusinessLayer->delete($folderId, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex) {
return new JSONResponse(array('message' => $ex->getMessage()),
Http::STATUS_NOT_FOUND);
@@ -111,7 +110,7 @@ class FolderApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function update() {
$folderId = (int) $this->params('folderId');
@@ -119,7 +118,6 @@ class FolderApiController extends Controller {
try {
$this->folderBusinessLayer->rename($folderId, $folderName, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerValidationException $ex) {
return new JSONResponse(array('message' => $ex->getMessage()),
@@ -139,14 +137,13 @@ class FolderApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
*/
public function read() {
$folderId = (int) $this->params('folderId');
$newestItemId = (int) $this->params('newestItemId');
$this->itemBusinessLayer->readFolder($folderId, $newestItemId, $this->userId);
- return new JSONResponse();
}
diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php
index caa07f4d2..76476dd7a 100644
--- a/controller/foldercontroller.php
+++ b/controller/foldercontroller.php
@@ -27,12 +27,15 @@ use \OCA\News\BusinessLayer\BusinessLayerValidationException;
class FolderController extends Controller {
+ use JSONHttpError;
+
private $folderBusinessLayer;
private $feedBusinessLayer;
private $itemBusinessLayer;
private $userId;
- public function __construct($appName, IRequest $request,
+ public function __construct($appName,
+ IRequest $request,
FolderBusinessLayer $folderBusinessLayer,
FeedBusinessLayer $feedBusinessLayer,
ItemBusinessLayer $itemBusinessLayer,
@@ -53,76 +56,64 @@ class FolderController extends Controller {
$result = array(
'folders' => $folders
);
- return new JSONResponse($result);
+ return $result;
}
- private function setOpened($isOpened){
- $folderId = (int) $this->params('folderId');
-
+ private function setOpened($isOpened, $folderId){
$this->folderBusinessLayer->open($folderId, $isOpened, $this->userId);
}
/**
* @NoAdminRequired
+ *
+ * @param int $folderId
*/
- public function open(){
+ public function open($folderId){
try {
- $this->setOpened(true);
- return new JSONResponse();
+ $this->setOpened(true, $folderId);
} catch(BusinessLayerException $ex) {
- return new JSONResponse(array(
- 'msg' => $ex->getMessage()
- ), Http::STATUS_NOT_FOUND);
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
/**
* @NoAdminRequired
+ *
+ * @param int $folderId
*/
- public function collapse(){
+ public function collapse($folderId){
try {
- $this->setOpened(false);
- return new JSONResponse();
+ $this->setOpened(false, $folderId);
} catch(BusinessLayerException $ex) {
- return new JSONResponse(array(
- 'msg' => $ex->getMessage()
- ), Http::STATUS_NOT_FOUND);
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
/**
* @NoAdminRequired
+ *
+ * @param string $folderName
*/
- public function create(){
- $folderName = $this->params('folderName');
-
+ public function create($folderName){
try {
// we need to purge deleted folders if a folder is created to
// prevent already exists exceptions
$this->folderBusinessLayer->purgeDeleted($this->userId, false);
-
$folder = $this->folderBusinessLayer->create($folderName, $this->userId);
$params = array(
'folders' => array($folder)
);
- return new JSONResponse($params);
-
-
+ return $params;
} catch(BusinessLayerConflictException $ex) {
- return new JSONResponse(array(
- 'msg' => $ex->getMessage()
- ), Http::STATUS_CONFLICT);
-
+ return $this->error($ex, Http::STATUS_CONFLICT);
} catch(BusinessLayerValidationException $ex) {
- return new JSONResponse(array(
- 'msg' => $ex->getMessage()
- ), Http::STATUS_UNPROCESSABLE_ENTITY);
+ return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
}
}
@@ -130,17 +121,14 @@ class FolderController extends Controller {
/**
* @NoAdminRequired
+ *
+ * @param int $folderId
*/
- public function delete(){
- $folderId = (int) $this->params('folderId');
-
+ public function delete($folderId){
try {
$this->folderBusinessLayer->markDeleted($folderId, $this->userId);
- return new JSONResponse();
} catch (BusinessLayerException $ex){
- return new JSONResponse(array(
- 'msg' => $ex->getMessage()
- ), Http::STATUS_NOT_FOUND);
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
@@ -202,7 +190,6 @@ class FolderController extends Controller {
try {
$this->folderBusinessLayer->unmarkDeleted($folderId, $this->userId);
- return new JSONResponse();
} catch (BusinessLayerException $ex){
return new JSONResponse(array(
'msg' => $ex->getMessage()
diff --git a/controller/itemapicontroller.php b/controller/itemapicontroller.php
index 533fb2032..767023877 100644
--- a/controller/itemapicontroller.php
+++ b/controller/itemapicontroller.php
@@ -14,14 +14,16 @@
namespace OCA\News\Controller;
use \OCP\IRequest;
-use \OCP\AppFramework\Controller;
+use \OCP\AppFramework\ApiController;
use \OCP\AppFramework\Http;
use \OCP\AppFramework\Http\JSONResponse;
use \OCA\News\BusinessLayer\ItemBusinessLayer;
use \OCA\News\BusinessLayer\BusinessLayerException;
-class ItemApiController extends Controller {
+class ItemApiController extends ApiController {
+
+ use JSONHttpError;
private $itemBusinessLayer;
private $userId;
@@ -39,25 +41,19 @@ class ItemApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $type
+ * @param int $id
+ * @param bool $getRead
+ * @param int $batchSize
+ * @param int $offset
*/
- public function index() {
+ public function index($type, $id, $getRead, $batchSize=20, $offset=0) {
$result = array(
'items' => array()
);
- $batchSize = (int) $this->params('batchSize', 20);
- $offset = (int) $this->params('offset', 0);
- $type = (int) $this->params('type');
- $id = (int) $this->params('id');
- $showAll = $this->params('getRead');
-
- if($showAll === 'true' || $showAll === true) {
- $showAll = true;
- } else {
- $showAll = false;
- }
-
$items = $this->itemBusinessLayer->findAll(
$id,
$type,
@@ -71,24 +67,24 @@ class ItemApiController extends Controller {
array_push($result['items'], $item->toAPI());
}
- return new JSONResponse($result);
+ return $result;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $type
+ * @param int $id
+ * @param int $lastModified
*/
- public function updated() {
+ public function updated($type, $id, $lastModified=0) {
$result = array(
'items' => array()
);
- $lastModified = (int) $this->params('lastModified', 0);
- $type = (int) $this->params('type');
- $id = (int) $this->params('id');
-
$items = $this->itemBusinessLayer->findAllNew(
$id,
$type,
@@ -101,31 +97,24 @@ class ItemApiController extends Controller {
array_push($result['items'], $item->toAPI());
}
- return new JSONResponse($result);
+ $result;
}
- private function setRead($isRead) {
- $itemId = (int) $this->params('itemId');
+ private function setRead($isRead, $itemId) {
try {
$this->itemBusinessLayer->read($itemId, $isRead, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex){
- return new JSONResponse(array('message' => $ex->getMessage()),
- Http::STATUS_NOT_FOUND);
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
- private function setStarred($isStarred) {
- $feedId = (int) $this->params('feedId');
- $guidHash = $this->params('guidHash');
+ private function setStarred($isStarred, $feedId, $guidHash) {
try {
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $this->userId);
- return new JSONResponse();
} catch(BusinessLayerException $ex){
- return new JSONResponse(array('message' => $ex->getMessage()),
- Http::STATUS_NOT_FOUND);
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
@@ -133,59 +122,66 @@ class ItemApiController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $itemId
*/
- public function read() {
- return $this->setRead(true);
+ public function read($itemId) {
+ return $this->setRead(true, $itemId);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $itemId
*/
- public function unread() {
- return $this->setRead(false);
+ public function unread($itemId) {
+ return $this->setRead(false, $itemId);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $feedId
+ * @param string $guidHash
*/
- public function star() {
- return $this->setStarred(true);
+ public function star($feedId, $guidHash) {
+ return $this->setStarred(true, $feedId, $guidHash);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $feedId
+ * @param string $guidHash
*/
- public function unstar() {
- return $this->setStarred(false);
+ public function unstar($feedId, $guidHash) {
+ return $this->setStarred(false, $feedId, $guidHash);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int $newestItemId
*/
- public function readAll() {
- $newestItemId = (int) $this->params('newestItemId');
-
+ public function readAll($newestItemId) {
$this->itemBusinessLayer->readAll($newestItemId, $this->userId);
- return new JSONResponse();
}
- private function setMultipleRead($isRead) {
- $items = $this->params('items');
-
+ private function setMultipleRead($isRead, $items) {
foreach($items as $id) {
try {
$this->itemBusinessLayer->read($id, $isRead, $this->userId);
@@ -193,34 +189,34 @@ class ItemApiController extends Controller {
continue;
}
}
-
- return new JSONResponse();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int[] item ids
*/
- public function readMultiple() {
- return $this->setMultipleRead(true);
+ public function readMultiple($items) {
+ return $this->setMultipleRead(true, $items);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int[] item ids
*/
- public function unreadMultiple() {
- return $this->setMultipleRead(false);
+ public function unreadMultiple($items) {
+ return $this->setMultipleRead(false, $items);
}
- private function setMultipleStarred($isStarred) {
- $items = $this->params('items');
-
+ private function setMultipleStarred($isStarred, $items) {
foreach($items as $item) {
try {
$this->itemBusinessLayer->star($item['feedId'],
@@ -229,28 +225,30 @@ class ItemApiController extends Controller {
continue;
}
}
-
- return new JSONResponse();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @API
+ * @CORS
+ *
+ * @param int[] item ids
*/
- public function starMultiple() {
- return $this->setMultipleStarred(true);
+ public function starMultiple($items) {
+ return $this->setMultipleStarred(true, $items);