Skip to content

fix: add weather location fallbacks#75

Merged
Anyesh merged 11 commits into
Anyesh:mainfrom
gzhang33:codex/weather-location-fallback
Jul 1, 2026
Merged

fix: add weather location fallbacks#75
Anyesh merged 11 commits into
Anyesh:mainfrom
gzhang33:codex/weather-location-fallback

Conversation

@gzhang33

Copy link
Copy Markdown
Contributor

Summary

  • add a frontend location fallback that uses network-based approximate coordinates when browser geolocation fails
  • keep approximate coordinates unsaved until the user explicitly saves them in settings
  • geocode location_name on the backend when weather endpoints are called without stored coordinates

Testing

  • npm test -- --run tests/location.test.ts
  • npx tsc --noEmit
  • docker compose exec -T -e TEST_DATABASE_URL=postgresql+asyncpg://wardrobe:4f5a5cb732900d2d7890d3bcb215f05268b2dce7e6188c2d56810cd8e9ccba91@postgres:5432/wardrobe_test backend pytest tests/test_weather_api.py
  • manual verification in local containers for the weather flow

Notes

  • .gitignore has local changes in the worktree and is intentionally excluded from this PR.

@gzhang33 gzhang33 marked this pull request as ready for review May 12, 2026 17:26
Copilot AI review requested due to automatic review settings May 12, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds fallback mechanisms so the weather flow can still work when precise geolocation (or stored coordinates) aren’t available, by using network-based approximation on the frontend and on-demand geocoding on the backend.

Changes:

  • Frontend: introduce shared location helper utilities (+ tests) and update Settings to fall back to IP-based approximate coordinates when browser geolocation fails.
  • Backend: add WeatherService.geocode_location_name() and update weather endpoints to geocode location_name when coordinates are missing (plus API tests).
  • UX: improve user-facing messaging when exact geolocation fails and approximate data is used.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
frontend/tests/location.test.ts Adds unit coverage for new location helper utilities.
frontend/lib/location.ts Introduces helpers for resolving network location responses, reverse-geocode formatting, and geolocation error messaging.
frontend/app/dashboard/settings/page.tsx Adds network-location fallback and refactors reverse geocoding + messaging in Settings.
backend/tests/test_weather_api.py Adds API-level tests for geocoding fallback behavior and missing-location errors.
backend/app/services/weather_service.py Adds a Nominatim geocoding helper for resolving location_name to coordinates.
backend/app/api/weather.py Uses geocoding fallback in /weather/current and /weather/forecast when coordinates aren’t stored/provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/app/services/weather_service.py
Comment thread backend/app/services/weather_service.py
Comment thread backend/app/api/weather.py Outdated
Comment thread backend/app/api/weather.py Outdated
Comment thread frontend/app/dashboard/settings/page.tsx Outdated
@gzhang33

gzhang33 commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Validation update for latest branch push:

  • Reviewed all Copilot review threads in the PR UI/API: 5/5 are resolved; no remaining unresolved review comment requests found.
  • Cleaned up the geocoding JSON error handling so HTTP failures and invalid JSON responses are handled distinctly.
  • Fixed the Settings page lint warning for the unitSystem dependency without resetting unsaved measurement edits on unit toggles.
  • Backend local test environment prepared with Python 3.11.15 in backend/.venv and project test dependencies installed.
  • Backend full suite: 292 passed via pytest -q.
  • Backend coverage validation: 292 passed via pytest --cov=app --cov-report=xml.
  • Frontend tests: 61 passed via npm test.
  • Frontend lint: npm run lint passes; the PR-touched Settings warning is gone. Remaining warnings are pre-existing in unrelated files.

Note: agent.md remains untracked locally and was not added to the PR.

Anyesh

This comment was marked as outdated.

@Anyesh

This comment was marked as outdated.

Anyesh added 4 commits May 31, 2026 19:02
Cache Nominatim geocode results in Redis (30-day TTL) so a saved
location name is geocoded at most once per TTL instead of on every
weather request, avoiding Nominatim rate-limit bans and keeping the
external call off the weather hot path.
Gate the IP-based location fallback behind NEXT_PUBLIC_ENABLE_IP_LOCATION_FALLBACK
(off by default) so the user's IP is only sent to a third party when an operator
explicitly enables it. Document the flag and provider override in README and
.env.example.
@Anyesh Anyesh merged commit 7426d6d into Anyesh:main Jul 1, 2026
6 checks passed
@Anyesh

Anyesh commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Thankyou for your PR 🙏🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants