Skip to content

Commit

Permalink
Merge branch 'development' into feature/DIMOC-215/catalogi-listed
Browse files Browse the repository at this point in the history
  • Loading branch information
RalkeyOfficial authored Aug 7, 2024
2 parents 23b9426 + 0e03954 commit 9bc7184
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 93 deletions.
12 changes: 6 additions & 6 deletions lib/Controller/CatalogiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->catalogMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->catalogMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->listingMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->listingMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' =>$this->metaDataMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' =>$this->metaDataMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
42 changes: 10 additions & 32 deletions lib/Controller/OrganisationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCA\OpenCatalogi\Db\OrganisationMapper;
use OCA\OpenCatalogi\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCA\OpenCatalogi\Service\SearchService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
Expand Down Expand Up @@ -44,47 +45,24 @@ public function page(): TemplateResponse
*
* @return JSONResponse
*/
public function index(ObjectService $objectService): JSONResponse
public function index(ObjectService $objectService, SearchService $searchService): JSONResponse
{

$filters = $this->request->getParams();

$searchConditions = [];
$searchParams = [];
$fieldsToSearch = ['title', 'description', 'summary'];

foreach ($filters as $key => $value) {
if ($key === '_search') {
// MongoDB
$searchRegex = ['$regex' => $value, '$options' => 'i'];
$filters['$or'] = [];

// MySQL
$searchParams['search'] = '%' . strtolower($value) . '%';

foreach ($fieldsToSearch as $field) {
// MongoDB
$filters['$or'][] = [$field => $searchRegex];

// MySQL
$searchConditions[] = "LOWER($field) LIKE :search";
}
}

if (str_starts_with($key, '_')) {
unset($filters[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
// Unset mongodb filter
unset($filters['$or']);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->organisationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->organisationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}


$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'),
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/PublicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function index(SearchService $searchService): JSONResponse
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

//@TODO: find a better way to get query params. This fixes it for now.
Expand Down
44 changes: 11 additions & 33 deletions lib/Controller/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use OCA\OpenCatalogi\Db\ThemeMapper;
use OCA\OpenCatalogi\Service\ObjectService;
use OCA\OpenCatalogi\Service\SearchService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
Expand Down Expand Up @@ -58,47 +59,24 @@ public function page(): TemplateResponse
*
* @return JSONResponse
*/
public function index(ObjectService $objectService): JSONResponse
public function index(ObjectService $objectService, SearchService $searchService): JSONResponse
{

$filters = $this->request->getParams();

$searchConditions = [];
$searchParams = [];
$fieldsToSearch = ['title', 'description', 'summary'];

foreach ($filters as $key => $value) {
if ($key === '_search') {
// MongoDB
$searchRegex = ['$regex' => $value, '$options' => 'i'];
$filters['$or'] = [];

// MySQL
$searchParams['search'] = '%' . strtolower($value) . '%';

foreach ($fieldsToSearch as $field) {
// MongoDB
$filters['$or'][] = [$field => $searchRegex];

// MySQL
$searchConditions[] = "LOWER($field) LIKE :search";
}
}

if (str_starts_with($key, '_')) {
unset($filters[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
// Unset mongodb filter
unset($filters['$or']);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->themeMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->themeMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}


$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'),
Expand Down Expand Up @@ -160,7 +138,7 @@ public function show(string $id, ObjectService $objectService): JSONResponse
*/
public function create(ObjectService $objectService): JSONResponse
{

$data = $this->request->getParams();

foreach ($data as $key => $value) {
Expand Down

0 comments on commit 9bc7184

Please sign in to comment.