diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-13 21:57:44 +0200 |
commit | 066b4b5a22a89fe3b38d37f09153090091928cd5 (patch) | |
tree | e01b7eaf641314259de1a54f146fa3e5d582ce02 /controller/folderapicontroller.php | |
parent | fb85040af65e77e6f4b2e596e259b38b510a8b60 (diff) |
move to new controller layout
Diffstat (limited to 'controller/folderapicontroller.php')
-rw-r--r-- | controller/folderapicontroller.php | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php index 40ffc1389..4e9f3e00c 100644 --- a/controller/folderapicontroller.php +++ b/controller/folderapicontroller.php @@ -27,6 +27,8 @@ use \OCA\News\BusinessLayer\BusinessLayerValidationException; class FolderApiController extends ApiController { + use JSONHttpError; + private $folderBusinessLayer; private $itemBusinessLayer; private $userId; @@ -49,15 +51,9 @@ class FolderApiController extends ApiController { * @CORS */ public function index() { - $result = array( - 'folders' => array() - ); - - foreach ($this->folderBusinessLayer->findAll($this->userId) as $folder) { - array_push($result['folders'], $folder->toAPI()); - } + $this->registerSerializer(new EntityApiSerializer('folders')); - return new JSONResponse($result); + return $this->folderBusinessLayer->findAll($this->userId); } @@ -65,27 +61,21 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param string $name */ - public function create() { - $folderName = $this->params('name'); - $result = array( - 'folders' => array() - ); - + public function create($name) { try { $this->folderBusinessLayer->purgeDeleted($this->userId, false); $folder = $this->folderBusinessLayer->create($folderName, $this->userId); - array_push($result['folders'], $folder->toAPI()); + + $this->registerSerializer(new EntityApiSerializer('folders')); + return $folder; - return new JSONResponse($result); - } catch(BusinessLayerValidationException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_UNPROCESSABLE_ENTITY); - + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_CONFLICT); + return $this->error($ex, Http::STATUS_CONFLICT); } } @@ -94,15 +84,14 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $folderId */ - public function delete() { - $folderId = (int) $this->params('folderId'); - + public function delete($folderId) { try { $this->folderBusinessLayer->delete($folderId, $this->userId); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -111,25 +100,19 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * @param int $folderId + * @param string $name */ - public function update() { - $folderId = (int) $this->params('folderId'); - $folderName = $this->params('name'); - + public function update($folderId, $name) { try { $this->folderBusinessLayer->rename($folderId, $folderName, $this->userId); } catch(BusinessLayerValidationException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_UNPROCESSABLE_ENTITY); - + return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); } catch(BusinessLayerConflictException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_CONFLICT); - + return $this->error($ex, Http::STATUS_CONFLICT); } catch(BusinessLayerException $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), - Http::STATUS_NOT_FOUND); + return $this->error($ex, Http::STATUS_NOT_FOUND); } } @@ -138,11 +121,11 @@ class FolderApiController extends ApiController { * @NoAdminRequired * @NoCSRFRequired * @CORS + * + * @param int $folderId + * @param int $newestItemId */ - public function read() { - $folderId = (int) $this->params('folderId'); - $newestItemId = (int) $this->params('newestItemId'); - + public function read($folderId, $newestItemId) { $this->itemBusinessLayer->readFolder($folderId, $newestItemId, $this->userId); } |