From d1e18e72bad019a821fc2f1959a36aa0c27c5567 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 29 Apr 2025 07:43:01 +0000 Subject: [PATCH] fix: Resolve missing argument error in get_weather_forecasts function --- endpoints/weather.get.py | 16 ++++++++-------- helpers/weather_forecast_helpers.py | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/endpoints/weather.get.py b/endpoints/weather.get.py index f96b15a..dd5b89c 100644 --- a/endpoints/weather.get.py +++ b/endpoints/weather.get.py @@ -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)) \ No newline at end of file +@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 \ No newline at end of file diff --git a/helpers/weather_forecast_helpers.py b/helpers/weather_forecast_helpers.py index 5c2803f..7537028 100644 --- a/helpers/weather_forecast_helpers.py +++ b/helpers/weather_forecast_helpers.py @@ -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]: """