Fix docker

This commit is contained in:
Urtzi Alfaro
2025-07-17 19:46:41 +02:00
parent ea5b75b685
commit caf7dea73a
8 changed files with 292 additions and 16 deletions

View File

@@ -0,0 +1,66 @@
"""
Data routes for gateway
"""
from fastapi import APIRouter, Request, HTTPException
from fastapi.responses import JSONResponse
import httpx
import logging
from app.core.config import settings
logger = logging.getLogger(__name__)
router = APIRouter()
@router.post("/upload")
async def upload_sales_data(request: Request):
"""Proxy data upload to data service"""
try:
body = await request.body()
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{settings.DATA_SERVICE_URL}/upload",
content=body,
headers={
"Content-Type": "application/json",
"Authorization": auth_header
}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Data service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Data service unavailable"
)
@router.get("/sales")
async def get_sales_data(request: Request):
"""Get sales data"""
try:
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(
f"{settings.DATA_SERVICE_URL}/sales",
headers={"Authorization": auth_header}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Data service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Data service unavailable"
)

View File

@@ -0,0 +1,66 @@
"""
Forecasting routes for gateway
"""
from fastapi import APIRouter, Request, HTTPException
from fastapi.responses import JSONResponse
import httpx
import logging
from app.core.config import settings
logger = logging.getLogger(__name__)
router = APIRouter()
@router.post("/predict")
async def create_forecast(request: Request):
"""Proxy forecast request to forecasting service"""
try:
body = await request.body()
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{settings.FORECASTING_SERVICE_URL}/predict",
content=body,
headers={
"Content-Type": "application/json",
"Authorization": auth_header
}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Forecasting service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Forecasting service unavailable"
)
@router.get("/forecasts")
async def get_forecasts(request: Request):
"""Get forecasts"""
try:
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(
f"{settings.FORECASTING_SERVICE_URL}/forecasts",
headers={"Authorization": auth_header}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Forecasting service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Forecasting service unavailable"
)

View File

@@ -0,0 +1,66 @@
"""
Notification routes for gateway
"""
from fastapi import APIRouter, Request, HTTPException
from fastapi.responses import JSONResponse
import httpx
import logging
from app.core.config import settings
logger = logging.getLogger(__name__)
router = APIRouter()
@router.post("/send")
async def send_notification(request: Request):
"""Proxy notification request to notification service"""
try:
body = await request.body()
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(
f"{settings.NOTIFICATION_SERVICE_URL}/send",
content=body,
headers={
"Content-Type": "application/json",
"Authorization": auth_header
}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Notification service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Notification service unavailable"
)
@router.get("/history")
async def get_notification_history(request: Request):
"""Get notification history"""
try:
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(
f"{settings.NOTIFICATION_SERVICE_URL}/history",
headers={"Authorization": auth_header}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Notification service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Notification service unavailable"
)

View File

@@ -0,0 +1,66 @@
"""
Tenant routes for gateway
"""
from fastapi import APIRouter, Request, HTTPException
from fastapi.responses import JSONResponse
import httpx
import logging
from app.core.config import settings
logger = logging.getLogger(__name__)
router = APIRouter()
@router.post("/")
async def create_tenant(request: Request):
"""Proxy tenant creation to tenant service"""
try:
body = await request.body()
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(
f"{settings.TENANT_SERVICE_URL}/tenants",
content=body,
headers={
"Content-Type": "application/json",
"Authorization": auth_header
}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Tenant service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Tenant service unavailable"
)
@router.get("/")
async def get_tenants(request: Request):
"""Get tenants"""
try:
auth_header = request.headers.get("Authorization")
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(
f"{settings.TENANT_SERVICE_URL}/tenants",
headers={"Authorization": auth_header}
)
return JSONResponse(
status_code=response.status_code,
content=response.json()
)
except httpx.RequestError as e:
logger.error(f"Tenant service unavailable: {e}")
raise HTTPException(
status_code=503,
detail="Tenant service unavailable"
)