Skip to content

Commit b90d99c

Browse files
committed
add areatype lookup
1 parent 37c6431 commit b90d99c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

findthatpostcode/crud/areas.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from elasticsearch import Elasticsearch
77
from mypy_boto3_s3 import S3Client
88

9+
from findthatpostcode.areatypes import AreaTypeEnum
910
from findthatpostcode.crud.utils import get_or_404
1011
from findthatpostcode.schema import Area, Postcode
1112
from findthatpostcode.schema.db import Area as AreaDocument
@@ -75,13 +76,15 @@ def get_example_postcodes(
7576
return []
7677

7778

78-
def get_child_areas(area: Area, areatype: str, es: Elasticsearch) -> list[Area]:
79+
def get_child_areas(
80+
area: Area, areatype: AreaTypeEnum, es: Elasticsearch
81+
) -> list[Area]:
7982
query = {
8083
"query": {
8184
"bool": {
8285
"filter": [
8386
{"term": {"parent.keyword": area.code}},
84-
{"term": {"type.keyword": areatype}},
87+
{"term": {"type.keyword": areatype.value}},
8588
]
8689
}
8790
}

findthatpostcode/routers/areas.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import APIRouter
22

3+
from findthatpostcode.areatypes import AreaTypeEnum
34
from findthatpostcode.crud.areas import (
45
get_area,
56
get_area_boundary,
@@ -52,7 +53,7 @@ async def read_example_postcodes(
5253
tags=["GeoJSON"],
5354
)
5455
async def read_area_children_geojson(
55-
areacode: str, areatype: str, es: ElasticsearchDep, s3_client: S3Dep
56+
areacode: str, areatype: AreaTypeEnum, es: ElasticsearchDep, s3_client: S3Dep
5657
) -> AreaGeoJSON:
5758
area = get_area(areacode, es)
5859
areas = get_child_areas(area, areatype, es)
@@ -68,7 +69,7 @@ async def read_area_children_geojson(
6869

6970
@router.get("/{areacode}/children/{areatype}", response_model_exclude_unset=True)
7071
async def read_area_children(
71-
areacode: str, areatype: str, es: ElasticsearchDep
72+
areacode: str, areatype: AreaTypeEnum, es: ElasticsearchDep
7273
) -> list[AreaResponse]:
7374
area = get_area(areacode, es)
7475
return get_child_areas(area, areatype, es)

0 commit comments

Comments
 (0)