Skip to content

Commit

Permalink
Merge pull request #944 from hackforla/mattyweb/issue942
Browse files Browse the repository at this point in the history
Adding council_name and type_name
  • Loading branch information
mattyweb authored Feb 11, 2021
2 parents c929b17 + fe5ebbc commit bb098a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/api/code/lacity_data_api/models/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class ServiceRequest(APIModel):
request_id: int
srnumber: str
council_id: int
council_name: str
type_id: int
type_name: str
created_date: datetime.date
closed_date: Optional[datetime.date]
address: str
Expand Down
9 changes: 6 additions & 3 deletions server/api/code/lacity_data_api/models/service_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,21 @@ async def get_filtered_requests(
type_ids: List[int] = None,
council_ids: List[int] = None
):
from .council import Council # noqa ... avoiding circular import

where_text = f"created_date >= '{start_date}'"
if (end_date):
where_text += f" AND created_date <= '{end_date}'"
if (type_ids):
where_text += f" AND type_id IN ({', '.join([str(i) for i in type_ids])})"
where_text += f" AND service_requests.type_id IN ({', '.join([str(i) for i in type_ids])})" # noqa
if (council_ids):
where_text += f" AND council_id IN ({', '.join([str(i) for i in council_ids])})"
where_text += f" AND service_requests.council_id IN ({', '.join([str(i) for i in council_ids])})" # noqa

result = await (
db.select(
ServiceRequest
[ServiceRequest, RequestType.type_name, Council.council_name]
).select_from(
ServiceRequest.join(RequestType).join(Council)
).where(
text(where_text)
).order_by(
Expand Down

0 comments on commit bb098a6

Please sign in to comment.