Start fixing forecast service API

This commit is contained in:
Urtzi Alfaro
2025-07-29 13:02:42 +02:00
parent cd6fd875f7
commit dfb619a7b5
2 changed files with 13 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ Forecast API endpoints
"""
import structlog
from fastapi import APIRouter, Depends, HTTPException, status, Query
from fastapi import APIRouter, Depends, HTTPException, status, Query, Path
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List, Optional
from datetime import date
@@ -29,11 +29,11 @@ router = APIRouter()
# Initialize service
forecasting_service = ForecastingService()
@router.post("/single", response_model=ForecastResponse)
@router.post("/tenants/{tenant_id}/forecasts/single", response_model=ForecastResponse)
async def create_single_forecast(
request: ForecastRequest,
db: AsyncSession = Depends(get_db),
tenant_id: str = Depends(get_current_tenant_id_dep),
tenant_id: str = Path(..., description="Tenant ID"),
current_user: dict = Depends(get_current_user_dep)
):
"""Generate a single product forecast"""
@@ -88,11 +88,11 @@ async def create_single_forecast(
detail="Internal server error"
)
@router.post("/batch", response_model=BatchForecastResponse)
@router.post("/tenants/{tenant_id}/forecasts/batch", response_model=BatchForecastResponse)
async def create_batch_forecast(
request: BatchForecastRequest,
db: AsyncSession = Depends(get_db),
tenant_id: str = Depends(get_current_tenant_id_dep),
tenant_id: str = Path(..., description="Tenant ID"),
current_user: dict = Depends(get_current_user_dep)
):
"""Generate batch forecasts for multiple products"""
@@ -170,14 +170,14 @@ async def create_batch_forecast(
detail="Internal server error"
)
@router.get("/list", response_model=List[ForecastResponse])
@router.get("/tenants/{tenant_id}/forecasts/list", response_model=List[ForecastResponse])
async def list_forecasts(
location: str,
start_date: Optional[date] = Query(None),
end_date: Optional[date] = Query(None),
product_name: Optional[str] = Query(None),
db: AsyncSession = Depends(get_db),
tenant_id: str = Depends(get_current_tenant_id_dep)
tenant_id: str = Path(..., description="Tenant ID")
):
"""List forecasts with filtering"""
@@ -230,11 +230,11 @@ async def list_forecasts(
detail="Internal server error"
)
@router.get("/alerts", response_model=List[AlertResponse])
@router.get("/tenants/{tenant_id}/forecasts/alerts", response_model=List[AlertResponse])
async def get_forecast_alerts(
active_only: bool = Query(True),
db: AsyncSession = Depends(get_db),
tenant_id: str = Depends(get_current_tenant_id_dep),
tenant_id: str = Path(..., description="Tenant ID"),
current_user: dict = Depends(get_current_user_dep)
):
"""Get forecast alerts for tenant"""
@@ -280,11 +280,11 @@ async def get_forecast_alerts(
detail="Internal server error"
)
@router.put("/alerts/{alert_id}/acknowledge")
@router.put("/tenants/{tenant_id}/forecasts/alerts/{alert_id}/acknowledge")
async def acknowledge_alert(
alert_id: str,
db: AsyncSession = Depends(get_db),
tenant_id: str = Depends(get_current_tenant_id_dep),
tenant_id: str = Path(..., description="Tenant ID"),
current_user: dict = Depends(get_current_user_dep)
):
"""Acknowledge a forecast alert"""