fix internal methods
This commit is contained in:
parent
712c5ec83b
commit
5d7102423a
@ -6,13 +6,34 @@ from config import settings
|
|||||||
from common_lib.utils.ssl_transport import ssl_transport
|
from common_lib.utils.ssl_transport import ssl_transport
|
||||||
|
|
||||||
|
|
||||||
async def get_profile_by_user_id(user_id: UUID, token: str) -> dict:
|
# async def get_profile_by_user_id(user_id: UUID, token: str) -> dict:
|
||||||
|
# try:
|
||||||
|
# async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0) as client:
|
||||||
|
# response = await client.get(
|
||||||
|
# f"{settings.PROFILE_SERVICE}/user_id/{user_id}",
|
||||||
|
# headers={"Authorization": f"Bearer {token}"}
|
||||||
|
# )
|
||||||
|
|
||||||
|
# if response.status_code != 200:
|
||||||
|
# raise HTTPException(
|
||||||
|
# status_code=response.status_code,
|
||||||
|
# detail=f"profile_service: {response.text}"
|
||||||
|
# )
|
||||||
|
|
||||||
|
# wrapped = response.json()
|
||||||
|
# return wrapped["data"]
|
||||||
|
|
||||||
|
# except httpx.RequestError:
|
||||||
|
# raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Token service unavailable")
|
||||||
|
|
||||||
|
async def get_profile_by_user_id(user_id: UUID, current_user: UUID, token: str) -> dict:
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0) as client:
|
async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0) as client:
|
||||||
response = await client.get(
|
response = await client.post(
|
||||||
f"{settings.PROFILE_SERVICE}/user_id/{user_id}",
|
f"{settings.PROFILE_SERVICE}/user_id/internal",
|
||||||
headers={"Authorization": f"Bearer {token}"}
|
headers={"Authorization": f"Bearer {token}"},
|
||||||
)
|
json={"user_id": str(user_id),
|
||||||
|
"current_user": str(current_user)})
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -23,8 +44,8 @@ async def get_profile_by_user_id(user_id: UUID, token: str) -> dict:
|
|||||||
wrapped = response.json()
|
wrapped = response.json()
|
||||||
return wrapped["data"]
|
return wrapped["data"]
|
||||||
|
|
||||||
except httpx.RequestError:
|
except httpx.RequestError as e:
|
||||||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Token service unavailable")
|
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"profile_service unreachable: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
async def get_profiles_by_user_ids(user_ids: List[UUID], token: str, user_id: UUID) -> Dict[str, dict]:
|
async def get_profiles_by_user_ids(user_ids: List[UUID], token: str, user_id: UUID) -> Dict[str, dict]:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "common-lib"
|
name = "common-lib"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
description = "Библиотека общих компонентов для микросервисов yobble"
|
description = "Библиотека общих компонентов для микросервисов yobble"
|
||||||
authors = [{ name = "cheykrym", email = "you@example.com" }]
|
authors = [{ name = "cheykrym", email = "you@example.com" }]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user