use response trait for remaining controllers
This commit is contained in:
parent
8d31c83d29
commit
c94e737e42
3 changed files with 30 additions and 45 deletions
|
@ -26,12 +26,13 @@ namespace OCA\Tasks\Controller;
|
|||
use \OCA\Tasks\Service\CollectionsService;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
class CollectionsController extends Controller {
|
||||
|
||||
private $collectionsService;
|
||||
|
||||
use Response;
|
||||
|
||||
public function __construct($appName, IRequest $request, CollectionsService $collectionsService){
|
||||
parent::__construct($appName, $request);
|
||||
$this->collectionsService = $collectionsService;
|
||||
|
@ -41,21 +42,17 @@ class CollectionsController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function getCollections(){
|
||||
$result = $this->collectionsService->getAll();
|
||||
$response = array(
|
||||
'data' => array(
|
||||
'collections' => $result
|
||||
)
|
||||
);
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () {
|
||||
return ['collections' => $this->collectionsService->getAll()];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setVisibility($collectionID, $visibility){
|
||||
$result = $this->collectionsService->setVisibility($collectionID, $visibility);
|
||||
$response = array();
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () use ($collectionID, $visibility) {
|
||||
return $this->collectionsService->setVisibility($collectionID, $visibility);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -26,12 +26,13 @@ namespace OCA\Tasks\Controller;
|
|||
use \OCA\Tasks\Service\ListsService;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
class ListsController extends Controller {
|
||||
|
||||
private $listsService;
|
||||
|
||||
use Response;
|
||||
|
||||
public function __construct($appName, IRequest $request, ListsService $listsService){
|
||||
parent::__construct($appName, $request);
|
||||
$this->listsService = $listsService;
|
||||
|
@ -41,45 +42,35 @@ class ListsController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function getLists(){
|
||||
$result = $this->listsService->getAll();
|
||||
$response = array(
|
||||
'data' => array(
|
||||
'lists' => $result
|
||||
)
|
||||
);
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () {
|
||||
return ['lists' => $this->listsService->getAll()];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addList($name, $tmpID){
|
||||
$result = $this->listsService->add($name, $tmpID);
|
||||
$response = array(
|
||||
'data' => array(
|
||||
'list' => $result
|
||||
)
|
||||
);
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () use ($name, $tmpID) {
|
||||
return ['list' => $this->listsService->add($name, $tmpID)];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteList($listID){
|
||||
$result = $this->listsService->delete($listID);
|
||||
$response = $result;
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () use ($listID) {
|
||||
return $this->listsService->delete($listID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setListName($listID, $name){
|
||||
$result = $this->listsService->setName($listID, $name);
|
||||
$response = array(
|
||||
'data' => $result
|
||||
);
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () use ($listID, $name) {
|
||||
return $this->listsService->setName($listID, $name);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -26,12 +26,13 @@ namespace OCA\Tasks\Controller;
|
|||
use \OCA\Tasks\Service\SettingsService;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
class SettingsController extends Controller {
|
||||
|
||||
private $settingsService;
|
||||
|
||||
use Response;
|
||||
|
||||
public function __construct($appName, IRequest $request, SettingsService $settingsService){
|
||||
parent::__construct($appName, $request);
|
||||
$this->settingsService = $settingsService;
|
||||
|
@ -41,21 +42,17 @@ class SettingsController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function get(){
|
||||
$result = $this->settingsService->get();
|
||||
$response = array(
|
||||
'data' => array(
|
||||
'settings' => $result
|
||||
)
|
||||
);
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () {
|
||||
return ['settings' => $this->settingsService->get()];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function set($setting, $type, $value){
|
||||
$result = $this->settingsService->set($setting, $type, $value);
|
||||
$response = array();
|
||||
return (new JSONResponse())->setData($response);
|
||||
return $this->generateResponse(function () use ($setting, $type, $value) {
|
||||
return $this->settingsService->set($setting, $type, $value);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue