Skip to content

Commit

Permalink
Merge pull request #945 from hackforla/mattyweb/issue942
Browse files Browse the repository at this point in the history
Added /requests/updated route
  • Loading branch information
mattyweb authored Feb 11, 2021
2 parents 3a15740 + bba1b25 commit 4fac3c6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 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
24 changes: 19 additions & 5 deletions server/api/tests/integration/test_api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,42 @@ def test_service_requests_end(client):
url = "/requests?start_date=2020-01-01&end_date=2020-01-02"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 7574
assert len(response.json()) == 8208


def test_service_requests_type(client):
url = "/requests?start_date=2020-01-01&end_date=2020-01-02&type_id=2"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 297
assert len(response.json()) == 294


def test_service_requests_council(client):
url = "/requests?start_date=2020-01-01&end_date=2020-01-02&council_id=4"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 38
assert len(response.json()) == 55


def test_service_requests_all(client):
url = "/requests?start_date=2020-01-01&end_date=2020-01-02&type_id=2&council_id=4"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 3
assert len(response.json()) == 6


def test_updated_service_requests(client):
url = "/requests/updated?start_date=2020-01-01&end_date=2020-01-02"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 9682


def test_updated_service_requests_council(client):
url = "/requests/updated?start_date=2020-01-01&end_date=2020-01-02&council_id=4"
response = client.get(url)
assert response.status_code == 200
assert len(response.json()) == 64


def test_service_request(client):
Expand Down Expand Up @@ -85,7 +99,7 @@ def test_service_request_pins(client):
]
})
assert response.status_code == 200
assert len(response.json()) == 36
assert len(response.json()) == 34


def test_service_request_points(client):
Expand Down
2 changes: 1 addition & 1 deletion server/api/tests/integration/test_api_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_map_pins(client):
}
)
assert response.status_code == 200
assert len(response.json()) == 621
assert len(response.json()) == 662


def test_open_requests(client):
Expand Down

0 comments on commit 4fac3c6

Please sign in to comment.