summaryrefslogtreecommitdiffstats
path: root/controller/foldercontroller.php
diff options
context:
space:
mode:
Diffstat (limited to 'controller/foldercontroller.php')
-rw-r--r--controller/foldercontroller.php65
1 files changed, 26 insertions, 39 deletions
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()