New Endpoint for advanced search

This commit is contained in:
cgfhtw
2025-06-16 11:57:27 +02:00
parent f321e07731
commit 688f87e2ba
2 changed files with 29 additions and 5 deletions
@@ -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);
+4
View File
@@ -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);