diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 20:42:39 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 20:42:39 +0200 |
commit | 20d4c2911fa39454b5c0cc9811b15a45d1fdfd2a (patch) | |
tree | 83854dfa7940d7f4ed5022cbb61a119e84e656ff /external/folderapi.php | |
parent | 61299d72050db23b62b96e0ea22cf54a515631f4 (diff) |
implemented folder api methods
Diffstat (limited to 'external/folderapi.php')
-rw-r--r-- | external/folderapi.php | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/external/folderapi.php b/external/folderapi.php index a7ea2f257..d9515b3ce 100644 --- a/external/folderapi.php +++ b/external/folderapi.php @@ -31,6 +31,7 @@ use \OCA\AppFramework\Http\Request; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\BusinessLayer\BusinessLayerExistsException; class FolderAPI extends Controller { @@ -59,18 +60,52 @@ class FolderAPI extends Controller { } - public function create() { + public function create() { + $userId = $this->api->getUserId(); + $folderName = $this->params('name'); + $result = array( + 'folders' => array() + ); + try { + $folder = $this->folderBusinessLayer->create($folderName, $userId); + array_push($result['folders'], $folder->toAPI()); + + return new NewsAPIResult($result); + } catch(BusinessLayerExistsException $ex) { + return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR, + $ex->getMessage()); + } } public function delete() { - + $userId = $this->api->getUserId(); + $folderId = $this->params('folderId'); + + try { + $this->folderBusinessLayer->delete($folderId, $userId); + return new NewsAPIResult(); + } catch(BusinessLayerException $ex) { + return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND, + $ex->getMessage()); + } } public function update() { - + $userId = $this->api->getUserId(); + $folderId = $this->params('folderId'); + $folderName = $this->params('name'); + + try { + $this->folderBusinessLayer->rename($folderId, $folderName, $userId); + return new NewsAPIResult(); + } catch(BusinessLayerException $ex) { + return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND, + $ex->getMessage()); + } } + } |