Skip to content

Commit

Permalink
Added /requests/updated endpoint
Browse files Browse the repository at this point in the history
- captures both new and updated requests
Fixes #942
  • Loading branch information
mattyweb committed Feb 11, 2021
1 parent fe5ebbc commit e94b865
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql.functions import now

SEED_FILE = join(dirname(dirname(__file__)), 'seeds/requests.csv')
SEED_FILE = join(dirname(dirname(__file__)), 'seeds/test_requests.csv')

# revision identifiers, used by Alembic.
revision = '72973ee94bac'
Expand Down
15 changes: 12 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 @@ -122,13 +122,22 @@ async def get_filtered_requests(
start_date: datetime.date,
end_date: datetime.date = None,
type_ids: List[int] = None,
council_ids: List[int] = None
council_ids: List[int] = None,
include_updated: bool = False
):
from .council import Council # noqa ... avoiding circular import

where_text = f"created_date >= '{start_date}'"
if include_updated:
where_text = f"(created_date >= '{start_date}' OR closed_date >= '{start_date}')" # noqa
else:
where_text = f"created_date >= '{start_date}'"

if (end_date):
where_text += f" AND created_date <= '{end_date}'"
if include_updated:
where_text = f"(created_date >= '{end_date}' OR closed_date >= '{end_date}')" # noqa
else:
where_text = f"created_date >= '{end_date}'"

if (type_ids):
where_text += f" AND service_requests.type_id IN ({', '.join([str(i) for i in type_ids])})" # noqa
if (council_ids):
Expand Down
26 changes: 26 additions & 0 deletions server/api/code/lacity_data_api/routers/service_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ async def get_all_service_requests(
return result


@router.get("/updated", response_model=ServiceRequestList)
async def get_updated_service_requests(
start_date: datetime.date = datetime.date.today() - datetime.timedelta(days=7),
end_date: datetime.date = None,
type_id: Optional[int] = None,
council_id: Optional[int] = None,
):
type_ids = []
council_ids = []

if type_id:
type_ids = [type_id]
if council_id:
council_ids = [council_id]

result = await get_filtered_requests(
start_date=start_date,
end_date=end_date,
type_ids=type_ids,
council_ids=council_ids,
include_updated=True
)

return result


@router.get("/counts/open/types", response_model=TypeCountList)
async def get_open_request_counts_by_type():
result = await get_open_request_counts()
Expand Down

0 comments on commit e94b865

Please sign in to comment.