Push geo-filter: Giftköder-Alert nur im 30km-Radius, Standort via Alerts-Check gespeichert
This commit is contained in:
parent
9213b58d3c
commit
b5e4eab84d
4 changed files with 44 additions and 5 deletions
|
|
@ -1,9 +1,10 @@
|
|||
"""BAN YARO — Nearby Alerts (Giftköder + Vermisste Hunde)"""
|
||||
import math
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from database import db
|
||||
from auth import get_current_user_optional as get_optional_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ def _haversine(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
|
|||
|
||||
|
||||
@router.get("")
|
||||
async def nearby_alerts(lat: float, lon: float):
|
||||
async def nearby_alerts(lat: float, lon: float, user=Depends(get_optional_user)):
|
||||
now = datetime.utcnow().isoformat()
|
||||
with db() as conn:
|
||||
poisons = conn.execute(
|
||||
|
|
@ -29,6 +30,13 @@ async def nearby_alerts(lat: float, lon: float):
|
|||
lost = conn.execute(
|
||||
"SELECT lat, lon FROM lost_dogs WHERE is_active=1"
|
||||
).fetchall()
|
||||
# Letzten Standort des Users für geo-basierte Push-Filter speichern
|
||||
if user:
|
||||
conn.execute(
|
||||
"""UPDATE push_subscriptions SET last_lat=?, last_lon=?
|
||||
WHERE user_id=?""",
|
||||
(lat, lon, user["id"])
|
||||
)
|
||||
|
||||
has_poison = any(_haversine(lat, lon, r["lat"], r["lon"]) <= _RADIUS_M for r in poisons)
|
||||
has_lost = any(_haversine(lat, lon, r["lat"], r["lon"]) <= _RADIUS_M for r in lost)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue