feat: Fix nutrition service and add location-based alerts
All checks were successful
continuous-integration/drone/push Build is passing

Changes:
- Fix nutrition service: add is_active column and Pydantic validation for UUID/datetime
- Add location-based alerts feature: users can now see alerts within 1km radius
- Fix CORS and response serialization in nutrition service
- Add getCurrentLocation() and loadAlertsNearby() functions
- Improve UI for nearby alerts display with distance and response count
This commit is contained in:
2025-12-13 16:34:50 +09:00
parent 3050e084fa
commit cfc93cb99a
34 changed files with 7016 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ This module provides common authentication functionality to avoid circular impor
"""
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Optional
import jwt
@@ -65,14 +65,18 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
"""Create access token."""
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=15)
expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(
to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM
)
return encoded_jwt
try:
encoded_jwt = jwt.encode(
to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM
)
return encoded_jwt
except Exception as e:
logging.error(f"Error encoding JWT: {e}, data: {data}, expire: {expire}")
raise
def verify_token(token: str) -> Optional[dict]:
@@ -85,7 +89,8 @@ def verify_token(token: str) -> Optional[dict]:
if user_id is None:
return None
return {"user_id": int(user_id), "email": payload.get("email")}
except InvalidTokenError:
except InvalidTokenError as e:
logging.error(f"Token validation error: {e}")
return None