StockPred-Backend / app /api /routes_prediction.py
Anurag33Gaikwad's picture
Update app/api/routes_prediction.py
b4a65cd verified
Raw
History Blame Contribute Delete
1.68 kB
from fastapi import APIRouter, HTTPException, Query
from app.schemas import PredictionResponse, ChartForecastResponse
from app.services.prediction import predict_path
router = APIRouter(prefix="/api")
@router.get("/prediction", response_model=PredictionResponse)
def get_prediction(
ticker: str = Query(..., min_length=1),
days: int = Query(7, ge=1),
):
try:
prediction_payload, _chart_payload = predict_path(ticker, days)
return prediction_payload
except HTTPException:
raise
except Exception as e:
print("🔥 BACKEND ERROR:", repr(e))
raise HTTPException(status_code=500, detail=str(e))
@router.get("/price/forecast", response_model=ChartForecastResponse)
def get_price_forecast(
ticker: str = Query(..., min_length=1),
days: int = Query(7, ge=1),
):
try:
_prediction_payload, chart_payload = predict_path(ticker, days)
return chart_payload
except HTTPException:
raise
except Exception as e:
print("🔥 BACKEND ERROR:", repr(e))
raise HTTPException(
status_code=500,
detail=str(e),
)
@router.get("/prediction/full")
def get_full_prediction(
ticker: str = Query(..., min_length=1),
days: int = Query(7, ge=1),
):
try:
prediction_payload, chart_payload = predict_path(ticker, days)
return {
"prediction": prediction_payload,
"chart": chart_payload,
}
except HTTPException:
raise
except Exception as e:
print("🔥 BACKEND ERROR:", repr(e))
raise HTTPException(
status_code=500,
detail=str(e),
)