Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-01-30 18:59:03 +0300
committerJoas Schilling <coding@schilljs.com>2019-02-20 14:17:35 +0300
commit835e6bdc77881eba0979b396e975053786b98e82 (patch)
treeccb9497ce25a492965f0bc47a92d4410a2d5c6fb /lib/Controller/CommandController.php
parent18aa82dabf3a00d34ce4e17010fd9bd67e0792d3 (diff)
Add console commands to manage commands
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/CommandController.php')
-rw-r--r--lib/Controller/CommandController.php28
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/Controller/CommandController.php b/lib/Controller/CommandController.php
index d61bd9e86..cc1e0e193 100644
--- a/lib/Controller/CommandController.php
+++ b/lib/Controller/CommandController.php
@@ -23,6 +23,7 @@
namespace OCA\Spreed\Controller;
+use OCA\Spreed\Model\Command;
use OCA\Spreed\Service\CommandService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
@@ -53,18 +54,9 @@ class CommandController extends OCSController {
public function index(): DataResponse {
$commands = $this->commandService->findAll();
- $result = [];
- foreach ($commands as $command) {
- $result[] = [
- 'id' => $command->getId(),
- 'app' => $command->getApp(),
- 'name' => $command->getName(),
- 'pattern' => $command->getCommand(),
- 'script' => $command->getScript(),
- 'response' => $command->getResponse(),
- 'enabled' => $command->getEnabled(),
- ];
- }
+ $result = array_map(function(Command $command) {
+ return $command->asArray();
+ }, $commands);
return new DataResponse($result);
}
@@ -84,15 +76,7 @@ class CommandController extends OCSController {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
}
- return new DataResponse([
- 'id' => $command->getId(),
- 'app' => $command->getApp(),
- 'name' => $command->getName(),
- 'pattern' => $command->getCommand(),
- 'script' => $command->getScript(),
- 'response' => $command->getResponse(),
- 'enabled' => $command->getEnabled(),
- ]);
+ return new DataResponse($command->asArray());
}
/**
@@ -104,6 +88,8 @@ class CommandController extends OCSController {
$this->commandService->delete($id);
} catch (DoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
+ } catch (\InvalidArgumentException $e) {
+ return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
}
return new DataResponse();