Start fixing forecast service API
This commit is contained in:
@@ -6,7 +6,7 @@ Forecast API endpoints
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import structlog
|
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 sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from datetime import date
|
from datetime import date
|
||||||
@@ -29,11 +29,11 @@ router = APIRouter()
|
|||||||
# Initialize service
|
# Initialize service
|
||||||
forecasting_service = ForecastingService()
|
forecasting_service = ForecastingService()
|
||||||
|
|
||||||
@router.post("/single", response_model=ForecastResponse)
|
@router.post("/tenants/{tenant_id}/forecasts/single", response_model=ForecastResponse)
|
||||||
async def create_single_forecast(
|
async def create_single_forecast(
|
||||||
request: ForecastRequest,
|
request: ForecastRequest,
|
||||||
db: AsyncSession = Depends(get_db),
|
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)
|
current_user: dict = Depends(get_current_user_dep)
|
||||||
):
|
):
|
||||||
"""Generate a single product forecast"""
|
"""Generate a single product forecast"""
|
||||||
@@ -88,11 +88,11 @@ async def create_single_forecast(
|
|||||||
detail="Internal server error"
|
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(
|
async def create_batch_forecast(
|
||||||
request: BatchForecastRequest,
|
request: BatchForecastRequest,
|
||||||
db: AsyncSession = Depends(get_db),
|
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)
|
current_user: dict = Depends(get_current_user_dep)
|
||||||
):
|
):
|
||||||
"""Generate batch forecasts for multiple products"""
|
"""Generate batch forecasts for multiple products"""
|
||||||
@@ -170,14 +170,14 @@ async def create_batch_forecast(
|
|||||||
detail="Internal server error"
|
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(
|
async def list_forecasts(
|
||||||
location: str,
|
location: str,
|
||||||
start_date: Optional[date] = Query(None),
|
start_date: Optional[date] = Query(None),
|
||||||
end_date: Optional[date] = Query(None),
|
end_date: Optional[date] = Query(None),
|
||||||
product_name: Optional[str] = Query(None),
|
product_name: Optional[str] = Query(None),
|
||||||
db: AsyncSession = Depends(get_db),
|
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"""
|
"""List forecasts with filtering"""
|
||||||
|
|
||||||
@@ -230,11 +230,11 @@ async def list_forecasts(
|
|||||||
detail="Internal server error"
|
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(
|
async def get_forecast_alerts(
|
||||||
active_only: bool = Query(True),
|
active_only: bool = Query(True),
|
||||||
db: AsyncSession = Depends(get_db),
|
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)
|
current_user: dict = Depends(get_current_user_dep)
|
||||||
):
|
):
|
||||||
"""Get forecast alerts for tenant"""
|
"""Get forecast alerts for tenant"""
|
||||||
@@ -280,11 +280,11 @@ async def get_forecast_alerts(
|
|||||||
detail="Internal server error"
|
detail="Internal server error"
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.put("/alerts/{alert_id}/acknowledge")
|
@router.put("/tenants/{tenant_id}/forecasts/alerts/{alert_id}/acknowledge")
|
||||||
async def acknowledge_alert(
|
async def acknowledge_alert(
|
||||||
alert_id: str,
|
alert_id: str,
|
||||||
db: AsyncSession = Depends(get_db),
|
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)
|
current_user: dict = Depends(get_current_user_dep)
|
||||||
):
|
):
|
||||||
"""Acknowledge a forecast alert"""
|
"""Acknowledge a forecast alert"""
|
||||||
|
|||||||
@@ -250,12 +250,8 @@ class ForecastingService:
|
|||||||
# Call training service to get model information
|
# Call training service to get model information
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
f"{settings.TRAINING_SERVICE_URL}/api/v1/models/latest",
|
f"{settings.TRAINING_SERVICE_URL}/tenants/{tenant_id}/models/{product_name}/active",
|
||||||
params={
|
params={},
|
||||||
"tenant_id": tenant_id,
|
|
||||||
"product_name": product_name,
|
|
||||||
"location": location
|
|
||||||
},
|
|
||||||
headers={"X-Service-Auth": settings.SERVICE_AUTH_TOKEN}
|
headers={"X-Service-Auth": settings.SERVICE_AUTH_TOKEN}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user