fix: Resolve missing argument error in get_weather_forecasts function

This commit is contained in:
Backend IM Bot 2025-04-29 07:43:01 +00:00
parent f7ed3999d0
commit d1e18e72ba
2 changed files with 13 additions and 12 deletions

View File

@ -1,13 +1,13 @@
from fastapi import APIRouter, HTTPException
from fastapi import APIRouter, Depends
from typing import List
from sqlalchemy.orm import Session
from core.database import get_db
from schemas.weather_forecast import WeatherForecastSchema
from helpers.weather_forecast_helpers import get_weather_forecasts
router = APIRouter()
@router.get("/weather", status_code=200, response_model=List[dict])
async def get_weather_forecasts_endpoint():
try:
forecasts = get_weather_forecasts()
return forecasts
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/weather", status_code=200, response_model=List[WeatherForecastSchema])
async def get_weather_forecasts_endpoint(db: Session = Depends(get_db)):
weather_forecasts = get_weather_forecasts(db)
return weather_forecasts

View File

@ -8,15 +8,16 @@ from sqlalchemy import func
def get_weather_forecasts(db: Session) -> List[WeatherForecastSchema]:
"""
Retrieves a fixed list of 10 weather forecasts for different countries.
Retrieves weather forecasts from the database.
Args:
db (Session): The database session (not used).
db (Session): The database session.
Returns:
List[WeatherForecastSchema]: A list of 10 weather forecast objects.
List[WeatherForecastSchema]: A list of weather forecast objects.
"""
return WeatherForecastSchema.forecasts
forecasts = db.query(WeatherForecast).all()
return [WeatherForecastSchema.from_orm(forecast) for forecast in forecasts]
def get_weather_forecast_by_id(db: Session, forecast_id: Union[str, uuid.UUID]) -> Optional[WeatherForecast]:
"""