|
2 | 2 | import json
|
3 | 3 | from google.cloud import firestore
|
4 | 4 | from .result import Result
|
| 5 | +from .utils import convert_to_array |
5 | 6 |
|
6 | 7 | DB = firestore.Client(project=os.environ.get('PROJECT'))
|
7 | 8 |
|
8 | 9 | def list_data(params):
|
9 |
| - ref = DB.collection(u'lighthouse') |
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: |
| 10 | + |
| 11 | + technology_array = convert_to_array(params['technology']) |
| 12 | + data = [] |
| 13 | + |
| 14 | + for technology in technology_array: |
| 15 | + query = DB.collection(u'lighthouse') |
| 16 | + |
| 17 | + if 'start' in params: |
| 18 | + query = query.where('date', '>=', params['start']) |
| 19 | + if 'end' in params: |
| 20 | + query = query.where('date', '<=', params['end']) |
| 21 | + |
18 | 22 | 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 | 23 | query = query.where('rank', '==', params['rank'])
|
| 24 | + query = query.where('technology', '==', technology) |
24 | 25 |
|
25 |
| - documents = query.stream() |
| 26 | + documents = query.stream() |
26 | 27 |
|
27 |
| - data = [] |
28 |
| - for doc in documents: |
29 |
| - data.append(doc.to_dict()) |
| 28 | + for doc in documents: |
| 29 | + data.append(doc.to_dict()) |
30 | 30 |
|
31 | 31 | return Result(result=data)
|
0 commit comments