Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions schemas/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class GeoJSONProperties(BaseModel):
elevation_unit: str = "ft"
vertical_datum: str = "NAVD88"
elevation_method: ElevationMethod | None
county: str | None = None
state: str | None = None
quad_name: str | None = None
utm_coordinates: GeoJSONUTMCoordinates = Field(
default_factory=GeoJSONUTMCoordinates
)
Expand Down Expand Up @@ -154,6 +157,9 @@ def populate_fields(cls, data: Any) -> Any:
data_dict["properties"]["notes"] = data_dict.get("notes")
data_dict["properties"]["elevation"] = convert_m_to_ft(elevation_m)
data_dict["properties"]["elevation_method"] = data_dict.get("elevation_method")
data_dict["properties"]["county"] = data_dict.get("county")
data_dict["properties"]["state"] = data_dict.get("state")
data_dict["properties"]["quad_name"] = data_dict.get("quad_name")
data_dict["properties"]["nma_location_notes"] = data_dict.get(
"nma_location_notes"
)
Expand Down
10 changes: 10 additions & 0 deletions schemas/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
WellPumpType,
FormationCode,
OriginType,
Role,
ContactType,
)
from schemas import BaseCreateModel, BaseUpdateModel, BaseResponseModel, PastOrTodayDate
from schemas.group import GroupResponse
Expand Down Expand Up @@ -229,6 +231,13 @@ def remove_records_with_end_date(cls, monitoring_frequencies):
return active_frequencies


class WellContactSummaryResponse(BaseResponseModel):
name: str | None = None
organization: str | None = None
role: Role
contact_type: ContactType


class WellResponse(BaseThingResponse):
"""
Response schema for well details.
Expand Down Expand Up @@ -262,6 +271,7 @@ class WellResponse(BaseThingResponse):
aquifers: list[dict] = []
water_notes: list[NoteResponse] = []
construction_notes: list[NoteResponse] = []
contacts: list[WellContactSummaryResponse] = []
permissions: list[PermissionHistoryResponse]
formation_completion_code: FormationCode | None
nma_formation_zone: str | None
Expand Down
4 changes: 4 additions & 0 deletions services/thing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from db import (
LocationThingAssociation,
Thing,
ThingContactAssociation,
Location,
WellScreen,
WellPurpose,
Expand Down Expand Up @@ -55,6 +56,9 @@
selectinload(Thing.location_associations).selectinload(
LocationThingAssociation.location
),
selectinload(Thing.contact_associations).selectinload(
ThingContactAssociation.contact
),
selectinload(Thing.well_purposes),
selectinload(Thing.well_casing_materials),
selectinload(Thing.links),
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def location():
loc = Location(
point="POINT(-107.949533 33.809665)",
elevation=2464.9,
county="Sierra",
release_status="draft",
state="NM",
quad_name="Hillsboro Peak",
)

session.add(loc)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,45 @@ def test_get_water_well_details_payload_404_not_found():
assert response.json()["detail"] == "Thing with ID 999999 not found."


def test_get_water_well_by_id_includes_location_properties(
water_well_thing,
):
response = client.get(f"/thing/water-well/{water_well_thing.id}")

assert response.status_code == 200
data = response.json()

assert data["current_location"]["properties"]["county"] == "Sierra"
assert data["current_location"]["properties"]["state"] == "NM"
assert data["current_location"]["properties"]["quad_name"] == "Hillsboro Peak"


def test_get_water_wells_includes_contact_summary(
water_well_thing,
contact,
):
response = client.get("/thing/water-well")

assert response.status_code == 200
data = response.json()

well = next(
(item for item in data["items"] if item["id"] == water_well_thing.id), None
)
assert well is not None, f"Well {water_well_thing.id} not found in response"
assert well["contacts"] == [
{
"id": contact.id,
"created_at": contact.created_at.astimezone(timezone.utc).strftime(DT_FMT),
"release_status": contact.release_status,
"name": contact.name,
"organization": contact.organization,
"contact_type": contact.contact_type,
"role": contact.role,
}
]


def test_get_water_well_by_id_404_not_found(water_well_thing):
bad_id = 99999
response = client.get(f"/thing/water-well/{bad_id}")
Expand Down
Loading