Skip to content

Commit 911b95f

Browse files
committed
convert parameters to comma separated string
1 parent ede7869 commit 911b95f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

functions/categories/libs/queries.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from google.cloud import firestore
44
from .result import Result
5+
from .utils import convert_to_array
56

67
DB = firestore.Client(project=os.environ.get('PROJECT'))
78

@@ -10,13 +11,13 @@ def list_data(params):
1011

1112
query = ref
1213

14+
if 'technology' in params:
15+
params_array = convert_to_array(params['technology'])
16+
query = query.where('technology', 'in', params_array)
17+
1318
if 'category' in params:
14-
category_array = json.loads(params['category'])
15-
query = query.where('category', 'in', category_array)
16-
17-
if 'technologies' in params:
18-
params_array = json.loads(params['technologies'])
19-
query = query.where('technologies', 'in', params_array)
19+
params_array = convert_to_array(params['category'])
20+
query = query.where('category', 'in', params_array)
2021

2122
documents = query.stream()
2223

functions/categories/libs/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ def convert_to_hashes(arr):
1111
hash_dict = {inner_arr[0]: inner_arr[1]}
1212
hashes_arr.append(hash_dict)
1313
return hashes_arr
14+
15+
def convert_to_array(data_string):
16+
list = data_string.split(',')
17+
return list

0 commit comments

Comments
 (0)