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 all 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
10 changes: 5 additions & 5 deletions src/store/modules/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export const useConfigurationStore = defineStore(
)
.then(
(response) => {
response.json().then(
(data) => {
this.setConfigurationItem(data)
response.json().then(
(data) => {
this.setConfigurationItem(data)
}
)
)
}
)
.catch(
(err) => {
console.error(err)
console.error(err)
}
)
},
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/configuration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { useConfigurationStore } from './configuration.js'

describe(
'Configuration Store', () => {
beforeEach(
() => {
setActivePinia(createPinia())
beforeEach(
() => {
setActivePinia(createPinia())
}
)
)

it(
'sets configuration item correctly', () => {
const store = useConfigurationStore()
const store = useConfigurationStore()

store.setConfigurationItem(mockConfiguration()[0])

Expand Down
12 changes: 6 additions & 6 deletions src/store/modules/configuration.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { useConfigurationStore } from './configuration.js';

describe(
'Metadata Store', () => {
beforeEach(
() => {
setActivePinia(createPinia())
beforeEach(
() => {
setActivePinia(createPinia())
}
)
)

it(
'sets configuration item correctly', () => {
const store = useConfigurationStore()
const store = useConfigurationStore()

store.setConfigurationItem(testData[0])

Expand All @@ -38,7 +38,7 @@ describe(

it(
'sets configuration list correctly', () => {
const store = useConfigurationStore()
const store = useConfigurationStore()

store.setConfigurationItem(testData)

Expand Down
14 changes: 7 additions & 7 deletions src/store/modules/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ export const useMetadataStore = defineStore(
)
.then(
(response) => {
response.json().then(
(data) => {
this.metaDataList = data.results.map(
(metadataItem) => new Metadata(metadataItem),
)
response.json().then(
(data) => {
this.metaDataList = data.results.map(
(metadataItem) => new Metadata(metadataItem),
)
return data
}
)
)
}
)
.catch(
(err) => {
console.error(err)
console.error(err)
return err
}
)
Expand Down
16 changes: 8 additions & 8 deletions src/store/modules/metadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Metadata, mockMetadata } from '../../entities/index.js'

describe(
'Metadata Store', () => {
beforeEach(
() => {
setActivePinia(createPinia())
beforeEach(
() => {
setActivePinia(createPinia())
}
)
)

it(
'sets metadata item correctly', () => {
const store = useMetadataStore()
const store = useMetadataStore()

store.setMetaDataItem(mockMetadata()[0])

Expand All @@ -27,7 +27,7 @@ describe(

it(
'sets metadata item with string "properties" property', () => {
const store = useMetadataStore()
const store = useMetadataStore()

// stringify json data
const mockData = mockMetadata()[0]
Expand All @@ -44,7 +44,7 @@ describe(

it(
'sets metadata list correctly', () => {
const store = useMetadataStore()
const store = useMetadataStore()

store.setMetaDataList(mockMetadata())

Expand All @@ -57,7 +57,7 @@ describe(

it(
'get metadata property from key', () => {
const store = useMetadataStore()
const store = useMetadataStore()

store.setMetaDataItem(mockMetadata()[0])
store.setMetadataDataKey('test')
Expand Down
Loading