Обновить routers/client.py
This commit is contained in:
parent
675eca167b
commit
a0335727b7
|
@ -11,6 +11,7 @@ import json
|
||||||
from model.database import get_async_session, Client
|
from model.database import get_async_session, Client
|
||||||
from utils.clients import upsert_client, del_jobs, add_jobs, get_applied_jobs, get_filtered_jobs, client_list, get_avtopilot, get_delite, get_update
|
from utils.clients import upsert_client, del_jobs, add_jobs, get_applied_jobs, get_filtered_jobs, client_list, get_avtopilot, get_delite, get_update
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
import requests
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
@ -48,12 +49,32 @@ async def get_client_modal(client_id: int, db: Session = Depends(get_async_sessi
|
||||||
|
|
||||||
client = await client_list(client_id, db)
|
client = await client_list(client_id, db)
|
||||||
|
|
||||||
# print(client)
|
print(client)
|
||||||
|
|
||||||
|
# Получаем токен
|
||||||
|
token = client.get("token") if isinstance(client, dict) else getattr(client, "token", None)
|
||||||
|
if not token:
|
||||||
|
raise HTTPException(status_code=400, detail="Token not found for client")
|
||||||
|
|
||||||
|
# Запрос к внешнему API
|
||||||
|
try:
|
||||||
|
response = requests.get(
|
||||||
|
"https://devnet.turboapply.ai/api/getKnows",
|
||||||
|
headers={"token": token}
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
external_data = response.json()
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=502, detail=f"Error from external API: {str(e)}")
|
||||||
|
|
||||||
|
# Добавляем knows к клиенту
|
||||||
|
if isinstance(client, dict):
|
||||||
|
client["knows"] = external_data
|
||||||
|
else:
|
||||||
|
# Если client — объект, делаем dict
|
||||||
|
client = dict(client)
|
||||||
|
client["knows"] = external_data
|
||||||
|
|
||||||
if not client:
|
|
||||||
raise HTTPException(status_code=404, detail="Client not found")
|
|
||||||
return JSONResponse(content=client)
|
return JSONResponse(content=client)
|
||||||
|
|
||||||
class JsonData(BaseModel):
|
class JsonData(BaseModel):
|
||||||
|
|
Loading…
Reference in New Issue