fix: Resolve missing argument error in get_weather_forecasts function
This commit is contained in:
parent
f7ed3999d0
commit
d1e18e72ba
@ -1,13 +1,13 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, Depends
|
||||||
from typing import List
|
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
|
from helpers.weather_forecast_helpers import get_weather_forecasts
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/weather", status_code=200, response_model=List[dict])
|
@router.get("/weather", status_code=200, response_model=List[WeatherForecastSchema])
|
||||||
async def get_weather_forecasts_endpoint():
|
async def get_weather_forecasts_endpoint(db: Session = Depends(get_db)):
|
||||||
try:
|
weather_forecasts = get_weather_forecasts(db)
|
||||||
forecasts = get_weather_forecasts()
|
return weather_forecasts
|
||||||
return forecasts
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
|
@ -8,15 +8,16 @@ from sqlalchemy import func
|
|||||||
|
|
||||||
def get_weather_forecasts(db: Session) -> List[WeatherForecastSchema]:
|
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:
|
Args:
|
||||||
db (Session): The database session (not used).
|
db (Session): The database session.
|
||||||
|
|
||||||
Returns:
|
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]:
|
def get_weather_forecast_by_id(db: Session, forecast_id: Union[str, uuid.UUID]) -> Optional[WeatherForecast]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user