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

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-10-31 13:20:15 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-10-31 13:20:15 +0300
commit759ad720b82f0d8e09ae819a69fce7af2597db25 (patch)
tree7708f1aaf06ae79dae71d11dd4b9d552b45c7493 /lib
parentaadc13ea0b802961f86dc43432deffa9323bcc7d (diff)
using my-small-php-tools
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ApiController.php51
1 files changed, 17 insertions, 34 deletions
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index 1c3b0e4..f973ea9 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,11 @@
*
*/
+
namespace OCA\FullTextSearch\Controller;
+
+use daita\MySmallPhpTools\Traits\TNCDataResponse;
use Exception;
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Model\SearchRequest;
@@ -33,12 +39,16 @@ use OCA\FullTextSearch\Service\ConfigService;
use OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\SearchService;
use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
+
class ApiController extends Controller {
+
+ use TNCDataResponse;
+
+
/** @var SearchService */
private $searchService;
@@ -76,7 +86,7 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- public function search($request) {
+ public function search(string $request): DataResponse {
return $this->searchDocuments(SearchRequest::fromJSON($request));
}
@@ -90,7 +100,7 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- public function searchFromRemote($request) {
+ public function searchFromRemote(string $request): DataResponse {
return $this->searchDocuments(SearchRequest::fromJSON($request));
}
@@ -100,54 +110,27 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- private function searchDocuments(SearchRequest $request) {
+ private function searchDocuments(SearchRequest $request): DataResponse {
try {
$result = $this->searchService->search('', $request);
return $this->success(
+ $result,
[
'request' => $request,
- 'result' => $result,
'version' => $this->configService->getAppValue('installed_version')
]
);
} catch (Exception $e) {
return $this->fail(
+ $e->getMessage(),
[
'request' => $request,
- 'error' => $e->getMessage(),
'version' => $this->configService->getAppValue('installed_version')
]
);
}
}
-
- /**
- * @param $data
- *
- * @return DataResponse
- */
- protected function fail($data) {
- $this->miscService->log(json_encode($data));
-
- return new DataResponse(
- array_merge($data, array('status' => 0)),
- Http::STATUS_NON_AUTHORATIVE_INFORMATION
- );
- }
-
-
- /**
- * @param $data
- *
- * @return DataResponse
- */
- protected function success($data) {
- return new DataResponse(
- array_merge($data, array('status' => 1)),
- Http::STATUS_CREATED
- );
- }
-
}
+