Skip to content

Commit

Permalink
implementing FieldFilter for lighthouse endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
maceto committed Jul 22, 2024
1 parent 121cd7f commit a31443f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions functions/lighthouse/libs/queries.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import os
import json
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from .result import Result
from .utils import convert_to_array

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

def list_data(params):

technology_array = convert_to_array(params['technology'])
data = []

for technology in technology_array:
query = DB.collection(u'lighthouse')
query = DB.collection(TABLE)

if 'start' in params:
query = query.where('date', '>=', params['start'])
query = query.where(filter=FieldFilter('date', '>=', params['start']))
if 'end' in params:
query = query.where('date', '<=', params['end'])
query = query.where(filter=FieldFilter('date', '<=', params['end']))

query = query.where('geo', '==', params['geo'])
query = query.where('rank', '==', params['rank'])
query = query.where('technology', '==', technology)
query = query.where(filter=FieldFilter('geo', '==', params['geo']))
query = query.where(filter=FieldFilter('rank', '==', params['rank']))
query = query.where(filter=FieldFilter('technology', '==', technology))

documents = query.stream()

Expand Down

0 comments on commit a31443f

Please sign in to comment.