зеркало из https://github.com/nextcloud/news.git
implement folder modify and delete api calls
This commit is contained in:
Родитель
3c87c2be39
Коммит
25a766a009
|
@ -26,7 +26,7 @@ require_once \OC_App::getAppPath('news') . '/appinfo/bootstrap.php';
|
|||
function callController($controllerName, $methodName, $urlParams, $disableAdminCheck=true,
|
||||
$isAjax=false){
|
||||
$container = createDIContainer();
|
||||
|
||||
|
||||
// run security checks
|
||||
$security = $container['Security'];
|
||||
runSecurityChecks($security, $isAjax, $disableAdminCheck);
|
||||
|
@ -60,7 +60,7 @@ function callAjaxController($controllerName, $methodName, $urlParams, $disableAd
|
|||
*/
|
||||
function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
|
||||
if($disableAdminCheck){
|
||||
$security->setIsAdminCheck(false);
|
||||
$security->setIsAdminCheck(false);
|
||||
}
|
||||
|
||||
if($isAjax){
|
||||
|
@ -80,19 +80,19 @@ function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
|
|||
* Normal Routes
|
||||
*/
|
||||
$this->create('news_index', '/')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callController('NewsController', 'index', $params, true);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_index_feed', '/feed/{feedid}')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callController('NewsController', 'index', $params, true);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_export_opml', '/export/opml')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callController('NewsController', 'exportOPML', $params, true);
|
||||
}
|
||||
);
|
||||
|
@ -102,13 +102,13 @@ $this->create('news_export_opml', '/export/opml')->action(
|
|||
* AJAX Routes
|
||||
*/
|
||||
$this->create('news_ajax_init', '/ajax/init')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'init', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'setShowAll', $params);
|
||||
}
|
||||
);
|
||||
|
@ -118,25 +118,25 @@ $this->create('news_ajax_setshowall', '/ajax/setshowall')->action(
|
|||
* Folders
|
||||
*/
|
||||
$this->create('news_ajax_collapsefolder', '/ajax/collapsefolder')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'collapseFolder', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_changefoldername', '/ajax/changefoldername')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'changeFolderName', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_createfolder', '/ajax/createfolder')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'createFolder', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'deleteFolder', $params);
|
||||
}
|
||||
);
|
||||
|
@ -146,31 +146,31 @@ $this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action(
|
|||
* Feeds
|
||||
*/
|
||||
$this->create('news_ajax_loadfeed', '/ajax/loadfeed')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'loadFeed', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_deletefeed', '/ajax/deletefeed')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'deleteFeed', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_movefeedtofolder', '/ajax/movefeedtofolder')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'moveFeedToFolder', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_updatefeed', '/ajax/updatefeed')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'updateFeed', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'createFeed', $params);
|
||||
}
|
||||
);
|
||||
|
@ -180,13 +180,13 @@ $this->create('news_ajax_createfeed', '/ajax/createfeed')->action(
|
|||
* Items
|
||||
*/
|
||||
$this->create('news_ajax_setitemstatus', '/ajax/setitemstatus')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'setItemStatus', $params);
|
||||
}
|
||||
);
|
||||
|
||||
$this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'setAllItemsRead', $params);
|
||||
}
|
||||
);
|
||||
|
@ -196,7 +196,7 @@ $this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action(
|
|||
* Import stuff
|
||||
*/
|
||||
$this->create('news_ajax_importOPML', '/import')->action(
|
||||
function($params){
|
||||
function($params){
|
||||
callAjaxController('NewsAjaxController', 'uploadOPML', $params);
|
||||
}
|
||||
);
|
||||
|
@ -205,13 +205,13 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
/**
|
||||
* External API
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Feed API
|
||||
*/
|
||||
|
||||
\OCP\API::register(
|
||||
'get', '/news/feeds',
|
||||
'get', '/news/feeds',
|
||||
function($urlParams) {
|
||||
$container = createDIContainer();
|
||||
return $container['FeedApi']->getAll($urlParams);
|
||||
|
@ -219,7 +219,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
\OCP\API::register(
|
||||
'get', '/news/feeds/{feedid}',
|
||||
'get', '/news/feeds/{feedid}',
|
||||
function($urlParams) {
|
||||
$container = createDIContainer();
|
||||
return $container['FeedApi']->getById($urlParams);
|
||||
|
@ -227,7 +227,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
\OCP\API::register(
|
||||
'post', '/news/feeds/create',
|
||||
'post', '/news/feeds/create',
|
||||
function($urlParams) {
|
||||
$container = createDIContainer();
|
||||
return $container['FeedApi']->create($urlParams);
|
||||
|
@ -235,7 +235,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Folder API
|
||||
*/
|
||||
|
||||
|
@ -247,7 +247,6 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
},
|
||||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
|
||||
\OCP\API::register(
|
||||
'post', '/news/folders/create',
|
||||
function($urlParams) {
|
||||
|
@ -255,4 +254,20 @@ $this->create('news_ajax_importOPML', '/import')->action(
|
|||
return $container['FolderApi']->create($urlParams);
|
||||
},
|
||||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
\OCP\API::register(
|
||||
'get', '/news/folders/{folderid}/delete',
|
||||
function($urlParams) {
|
||||
$container = createDIContainer();
|
||||
return $container['FolderApi']->delete($urlParams);
|
||||
},
|
||||
'news', \OC_API::USER_AUTH
|
||||
);
|
||||
\OCP\API::register(
|
||||
'post', '/news/folders/{folderid}/modify',
|
||||
function($urlParams) {
|
||||
$container = createDIContainer();
|
||||
return $container['FolderApi']->modify($urlParams);
|
||||
},
|
||||
'news', \OC_API::USER_AUTH
|
||||
);
|
|
@ -53,7 +53,7 @@ class FolderMapper {
|
|||
|
||||
return $folderlist;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the forest (list of trees) of folders children of $parentid
|
||||
* @param
|
||||
|
@ -111,6 +111,9 @@ class FolderMapper {
|
|||
$result = $stmt->execute(array($this->userid, $id));
|
||||
|
||||
$row = $result->fetchRow();
|
||||
if(!$row)
|
||||
return null;
|
||||
|
||||
$folder = new Folder($row['name'], $row['id']);
|
||||
$folder->setOpened($row['opened']);
|
||||
|
||||
|
|
|
@ -13,22 +13,47 @@ class FolderApi {
|
|||
public function getAll() {
|
||||
$folders = $this->bl->getAll();
|
||||
$serializedFolders = array();
|
||||
|
||||
//TODO: check the behaviour for nested folders
|
||||
|
||||
//TODO: check the behaviour for nested folders
|
||||
foreach ($folders as $folder) {
|
||||
$serializedFolders[] = $folder->jsonSerialize();
|
||||
}
|
||||
return new \OC_OCS_Result($serializedFolders);
|
||||
}
|
||||
|
||||
|
||||
public function create() {
|
||||
|
||||
$name = $_POST['name'];
|
||||
$parentId = $_POST['parentid'];
|
||||
|
||||
|
||||
$this->bl->create($name, $parentId);
|
||||
|
||||
|
||||
return new \OC_OCS_Result();
|
||||
}
|
||||
|
||||
public function delete($params) {
|
||||
$id = $params['folderid'];
|
||||
if(!is_numeric($id))
|
||||
return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer');
|
||||
|
||||
if($this->bl->delete($id))
|
||||
return new \OC_OCS_Result();
|
||||
else
|
||||
return new \OC_OCS_Result(null,999,'Could not delete folder');
|
||||
}
|
||||
|
||||
public function modify($params) {
|
||||
$id = $params['folderid'];
|
||||
if(!is_numeric($id))
|
||||
return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer'.$id);
|
||||
|
||||
$name = $_POST['name'];
|
||||
$parentId = $_POST['parentid'];
|
||||
$opened = $_POST['opened'];
|
||||
|
||||
if($this->bl->modify($id, $name, $parentid, $opened))
|
||||
return new \OC_OCS_Result();
|
||||
else
|
||||
return new \OC_OCS_Result(null,999,'Could not modify folder');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,32 @@ class FolderBl {
|
|||
public function __construct($folderMapper){
|
||||
$this->folderMapper = $folderMapper;
|
||||
}
|
||||
|
||||
|
||||
public function getAll() {
|
||||
return $this->folderMapper->getAll();
|
||||
return $this->folderMapper->getAll();
|
||||
}
|
||||
|
||||
|
||||
public function create($name, $parentId) {
|
||||
//TODO: change the setparentid in the model class Folder
|
||||
$folder = new Folder($name, null, null);
|
||||
return $this->folderMapper->save($folder);
|
||||
return $this->folderMapper->save($folder);
|
||||
}
|
||||
|
||||
public function delete($folderid) {
|
||||
return $this->folderMapper->deleteById($folderid);
|
||||
}
|
||||
|
||||
public function modify($folderid, $name = null, $parent = null, $opened = null) {
|
||||
$folder = $this->folderMapper->find($folderid);
|
||||
if(!$folder)
|
||||
return false;
|
||||
|
||||
if($name)
|
||||
$folder->setName($name);
|
||||
if($parent)
|
||||
$folder->setParentId($parent);
|
||||
if($opened)
|
||||
$folder->setOpened($opened);
|
||||
return $this->folderMapper->update($folder);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче