Skip to content

Commit 2818287

Browse files
committed
technologies added params and onlyname
1 parent be3d94f commit 2818287

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
class Presenters:
3+
@staticmethod
4+
def technology(item):
5+
return {
6+
'client': item['client'],
7+
'similar_technologies': item['similar_technologies'],
8+
'description': item['description'],
9+
'origins': item['origins'],
10+
'technology': item['technology'],
11+
'category': item['category']
12+
}
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
import os
22
import json
33
from google.cloud import firestore
4+
from google.cloud.firestore_v1.base_query import FieldFilter, Or
5+
46
from .result import Result
57
from .utils import convert_to_array
8+
from .presenters import Presenters
9+
610

711
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
812

913
def list_data(params):
14+
onlyname = False
1015
ref = DB.collection(u'technologies')
1116

1217
query = ref
1318

14-
if 'start' in params:
15-
query = query.where('date', '>=', params['start'])
16-
if 'end' in params:
17-
query = query.where('date', '<=', params['end'])
18-
if 'geo' in params:
19-
query = query.where('geo', '==', params['geo'])
2019
if 'technology' in params:
20+
arfilters = []
2121
params_array = convert_to_array(params['technology'])
22-
query = query.where('technology', 'in', params_array)
23-
if 'rank' in params:
24-
query = query.where('rank', '==', params['rank'])
22+
for tech in params_array:
23+
arfilters.append(FieldFilter('technology', '==', tech))
24+
25+
or_filter = Or(filters=arfilters)
26+
27+
query = query.where(filter=or_filter)
28+
29+
2530
if 'category' in params:
2631
params_array = convert_to_array(params['category'])
27-
query = query.where('category', 'in', params_array)
32+
query = query.where(filter=FieldFilter('category_obj', 'array_contains_any', params_array))
33+
34+
if 'onlyname' in params:
35+
onlyname = True
2836

2937
documents = query.stream()
3038

3139
data = []
3240
for doc in documents:
33-
data.append(doc.to_dict())
41+
item = doc.to_dict()
42+
if onlyname:
43+
data.append(item['technology'])
44+
else:
45+
data.append(Presenters.technology(doc.to_dict()))
3446

3547
return Result(result=data)

functions/technologies/libs/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def __init__(self, params):
99
def validate(self):
1010
result = Result(status="ok", result="()")
1111

12-
if 'technology' not in self.params:
13-
self.add_error("technology", "missing technology parameter")
12+
# if 'technology' not in self.params:
13+
# self.add_error("technology", "missing technology parameter")
1414

1515
return Result(errors=self.errors, result=self.params)
1616

0 commit comments

Comments
 (0)