Skip to content

Commit

Permalink
allow responid to be list (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaslavskiy authored Jan 22, 2024
1 parent 4225d00 commit d2cac94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions gdrive/export_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class FindModel(BaseModel):
Request body format for the `/find` endpoint
"""

responseId: str
responseId: str | list[str]
field: str
values: list[str] = Field(..., min_items=1)
result_field: str | None = None
Expand All @@ -148,5 +148,8 @@ class FindModel(BaseModel):
async def find(find: FindModel):
# for given responseid, find all occurences of
result = find.result_field if find.result_field is not None else find.field
export_data = export_client.find(find.responseId, find.field, find.values, result)
responseId = (
find.responseId if isinstance(find.responseId, list) else [find.responseId]
)
export_data = export_client.find(responseId, find.field, find.values, result)
return export_data
6 changes: 4 additions & 2 deletions gdrive/export_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def find(responseId, field, values, result):
hosts=[{"host": settings.ES_HOST, "port": settings.ES_PORT}], timeout=300
)

all_interactionIds = get_all_InteractionIds(responseId)
all_interactionIds = []
for resid in responseId:
all_interactionIds.extend(get_all_InteractionIds(resid))

if len(all_interactionIds) == 0:
return {"found": []}
Expand Down Expand Up @@ -306,7 +308,7 @@ def find(responseId, field, values, result):
]
}
},
"_source": [result],
"_source": ["interactionId", result],
}

found_result = es.search(body=json.dumps(query_found), index="_all")
Expand Down

0 comments on commit d2cac94

Please sign in to comment.