From be3d94f1eff0895358db264bf8280314faf3a724 Mon Sep 17 00:00:00 2001 From: Martin Aceto Date: Mon, 27 Nov 2023 22:49:46 -0500 Subject: [PATCH] multi techonologies issue fix --- functions/adoption/libs/utils.py | 4 +++- functions/categories/libs/utils.py | 4 +++- functions/cwvtech/libs/queries.py | 8 ++++++-- functions/cwvtech/libs/utils.py | 6 ++++++ functions/lighthouse/libs/utils.py | 4 +++- functions/page-weight/libs/queries.py | 2 ++ functions/page-weight/libs/utils.py | 4 +++- functions/technologies/libs/utils.py | 4 +++- 8 files changed, 29 insertions(+), 7 deletions(-) diff --git a/functions/adoption/libs/utils.py b/functions/adoption/libs/utils.py index 3a5fe39..36b3a96 100644 --- a/functions/adoption/libs/utils.py +++ b/functions/adoption/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -13,5 +14,6 @@ def convert_to_hashes(arr): return hashes_arr def convert_to_array(data_string): - list = data_string.split(',') + decoded_data = unquote(data_string) + list = decoded_data.split(',') return list diff --git a/functions/categories/libs/utils.py b/functions/categories/libs/utils.py index d2cfeed..63890f1 100644 --- a/functions/categories/libs/utils.py +++ b/functions/categories/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -13,5 +14,6 @@ def convert_to_hashes(arr): return hashes_arr def convert_to_array(data_string): - list = data_string.split(',') + decoded_data = unquote(data_string) + list = decoded_data.split(',') return list \ No newline at end of file diff --git a/functions/cwvtech/libs/queries.py b/functions/cwvtech/libs/queries.py index 7da9d60..ae7b012 100644 --- a/functions/cwvtech/libs/queries.py +++ b/functions/cwvtech/libs/queries.py @@ -2,6 +2,7 @@ import json from google.cloud import firestore from .result import Result +from .utils import convert_to_array DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) @@ -14,11 +15,14 @@ def list_data(params): query = query.where('date', '>=', params['start']) if 'end' in params: query = query.where('date', '<=', params['end']) - + if 'geo' in params: query = query.where('geo', '==', params['geo']) + if 'technology' in params: - query = query.where('technology', '==', params['technology']) + params_array = convert_to_array(params['technology']) + query = query.where('technology', 'in', params_array) + if 'rank' in params: query = query.where('rank', '==', params['rank']) diff --git a/functions/cwvtech/libs/utils.py b/functions/cwvtech/libs/utils.py index b0c5a67..63890f1 100644 --- a/functions/cwvtech/libs/utils.py +++ b/functions/cwvtech/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -11,3 +12,8 @@ def convert_to_hashes(arr): hash_dict = {inner_arr[0]: inner_arr[1]} hashes_arr.append(hash_dict) return hashes_arr + +def convert_to_array(data_string): + decoded_data = unquote(data_string) + list = decoded_data.split(',') + return list \ No newline at end of file diff --git a/functions/lighthouse/libs/utils.py b/functions/lighthouse/libs/utils.py index d2cfeed..63890f1 100644 --- a/functions/lighthouse/libs/utils.py +++ b/functions/lighthouse/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -13,5 +14,6 @@ def convert_to_hashes(arr): return hashes_arr def convert_to_array(data_string): - list = data_string.split(',') + decoded_data = unquote(data_string) + list = decoded_data.split(',') return list \ No newline at end of file diff --git a/functions/page-weight/libs/queries.py b/functions/page-weight/libs/queries.py index 902c7f1..c3224dd 100644 --- a/functions/page-weight/libs/queries.py +++ b/functions/page-weight/libs/queries.py @@ -17,9 +17,11 @@ def list_data(params): query = query.where('date', '<=', params['end']) if 'geo' in params: query = query.where('geo', '==', params['geo']) + if 'technology' in params: params_array = convert_to_array(params['technology']) query = query.where('technology', 'in', params_array) + if 'rank' in params: query = query.where('rank', '==', params['rank']) diff --git a/functions/page-weight/libs/utils.py b/functions/page-weight/libs/utils.py index 3a5fe39..36b3a96 100644 --- a/functions/page-weight/libs/utils.py +++ b/functions/page-weight/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -13,5 +14,6 @@ def convert_to_hashes(arr): return hashes_arr def convert_to_array(data_string): - list = data_string.split(',') + decoded_data = unquote(data_string) + list = decoded_data.split(',') return list diff --git a/functions/technologies/libs/utils.py b/functions/technologies/libs/utils.py index d2cfeed..63890f1 100644 --- a/functions/technologies/libs/utils.py +++ b/functions/technologies/libs/utils.py @@ -1,4 +1,5 @@ import json +from urllib.parse import unquote def output(result, headers={}): status = 200 if result.success() else 400 @@ -13,5 +14,6 @@ def convert_to_hashes(arr): return hashes_arr def convert_to_array(data_string): - list = data_string.split(',') + decoded_data = unquote(data_string) + list = decoded_data.split(',') return list \ No newline at end of file