File tree Expand file tree Collapse file tree 4 files changed +66
-6
lines changed Expand file tree Collapse file tree 4 files changed +66
-6
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import json
3
+ from google .cloud import firestore
4
+ from .result import Result
5
+
6
+ DB = firestore .Client (project = os .environ .get ('PROJECT' ))
7
+
8
+ def list_data (params ):
9
+ ref = DB .collection (u'technologies' )
10
+
11
+ query = ref
12
+ print ("params" , params )
13
+ if 'start' in params :
14
+ query = query .where ('date' , '>=' , params ['start' ])
15
+ if 'end' in params :
16
+ query = query .where ('date' , '<=' , params ['end' ])
17
+ if 'geo' in params :
18
+ query = query .where ('geo' , '==' , params ['geo' ])
19
+ if 'technology' in params :
20
+ params_array = json .loads (params ['technology' ])
21
+ query = query .where ('technology' , 'in' , params_array )
22
+ if 'rank' in params :
23
+ query = query .where ('rank' , '==' , params ['rank' ])
24
+ if 'category' in params :
25
+ params_array = json .loads (params ['category' ])
26
+ query = query .where ('category' , 'in' , params_array )
27
+
28
+ documents = query .stream ()
29
+
30
+ data = []
31
+ for doc in documents :
32
+ data .append (doc .to_dict ())
33
+
34
+ return Result (result = data )
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ from .result import Result
2
+
3
+ class Validator ():
4
+ def __init__ (self , params ):
5
+ self .params = params
6
+ self .errors = []
7
+ self .normalizer_params = self .normalize (params )
8
+
9
+ def validate (self ):
10
+ result = Result (status = "ok" , result = "()" )
11
+
12
+ # if 'geo' not in self.params:
13
+ # self.add_error("geo", "missing geo parameters")
14
+
15
+ return Result (errors = self .errors , result = self .params )
16
+
17
+ def add_error (self , key , error ):
18
+ self .errors .append ([key , error ])
19
+
20
+ def normalize (self , params ):
21
+ return ""
Original file line number Diff line number Diff line change 1
1
import functions_framework
2
-
2
+ from . libs . validator import Validator
3
3
from .libs .utils import output
4
- from .libs .utils import ( TECHNOLOGIES )
5
- from .libs .result import Result
4
+ from .libs .queries import list_data
6
5
7
6
@functions_framework .http
8
7
def dispatcher (request ):
8
+ args = request .args .to_dict ()
9
+
10
+ validator = Validator (params = args )
11
+ result = validator .validate ()
12
+
13
+ if result .failure ():
14
+ print ("error" , result .errors )
15
+ return output (result )
9
16
10
- response = Result (result = TECHNOLOGIES )
17
+ response = list_data (result . result )
11
18
12
19
return output (response )
You can’t perform that action at this time.
0 commit comments