diff --git a/application/controllers/api/frontend/v1/Searchbar.php b/application/controllers/api/frontend/v1/Searchbar.php index d630d3afd..95ae6a6b3 100644 --- a/application/controllers/api/frontend/v1/Searchbar.php +++ b/application/controllers/api/frontend/v1/Searchbar.php @@ -37,9 +37,6 @@ class Searchbar extends FHCAPI_Controller parent::__construct([ 'search' => self::PERM_LOGGED ]); - - // Load the library SearchBarLib - $this->load->library('SearchBarLib'); } //------------------------------------------------------------------------------------------------------------------ @@ -50,6 +47,29 @@ class Searchbar extends FHCAPI_Controller */ public function search() { + $this->load->library('SearchBarLib'); + $this->load->library('form_validation'); + + // Checks if the searchstr and the types parameters are in the POSTed JSON + $this->form_validation->set_rules(self::SEARCHSTR_PARAM, null, 'required'); + $this->form_validation->set_rules(self::TYPES_PARAM . '[]', null, 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL); + + // Convert to json the result from searchbarlib->search + $result = $this->searchbarlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); + if (property_exists($result, 'error')) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->terminateWithSuccess($result); + } + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function searchAdvanced() + { + $this->load->library('SearchLib'); $this->load->library('form_validation'); // Checks if the searchstr and the types parameters are in the POSTed JSON @@ -59,8 +79,8 @@ class Searchbar extends FHCAPI_Controller if (!$this->form_validation->run()) $this->terminateWithValidationErrors($this->form_validation->error_array()); - // Convert to json the result from searchbarlib->search - $result = $this->searchbarlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); + // Convert to json the result from searchlib->search + $result = $this->searchlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); $data = $this->getDataOrTerminateWithError($result); diff --git a/public/js/api/search.js b/public/js/api/search.js index c6a5d77a5..76b3fcd9b 100644 --- a/public/js/api/search.js +++ b/public/js/api/search.js @@ -20,6 +20,10 @@ export default { const url = '/api/frontend/v1/searchbar/search'; return this.$fhcApi.post(url, searchsettings, config); }, + searchAdvanced(searchsettings, config) { + const url = '/api/frontend/v1/searchbar/searchAdvanced'; + return this.$fhcApi.post(url, searchsettings, config); + }, searchdummy(searchsettings) { const url = 'public/js/apps/api/dummyapi.php/Search'; return this.$fhcApi.post(url, searchsettings);