Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style fixes #113

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -119,15 +119,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
Loading