-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
social_user is created in login/create_user && get endpoint changed: …
…can now filter by lists of ids by query param.
- Loading branch information
Showing
10 changed files
with
152 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from fastapi import HTTPException, status | ||
from typing import Optional | ||
|
||
|
||
class InternalServerErrorException(HTTPException): | ||
def __init__( | ||
self, | ||
microservice: Optional[str] = "User service", | ||
detail: Optional[str] = None, | ||
): | ||
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR | ||
message = f"An error occurred in the {microservice}" | ||
|
||
if detail: | ||
message += f": {detail.lower()}" | ||
|
||
super().__init__(status_code=status_code, detail=message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
from httpx import AsyncClient, Response, AsyncHTTPTransport | ||
from os import environ | ||
|
||
from exceptions.InternalServerErrorException import InternalServerErrorException | ||
from exceptions.UserException import InvalidData | ||
|
||
logger = logging.getLogger("social") | ||
logger.setLevel("DEBUG") | ||
|
||
SOCIAL_SERVICE_URL = environ["SOCIAL_SERVICE_URL"] | ||
|
||
# Heroku dyno plan has a limit of 30 seconds... | ||
# so, assign 3 retries of 10 seconds each :) | ||
# https://devcenter.heroku.com/articles/request-timeout | ||
NUMBER_OF_RETRIES = 3 | ||
TIMEOUT = 10 | ||
|
||
|
||
class SocialService: | ||
@staticmethod | ||
async def post(path: str, body: dict) -> Response: | ||
async with AsyncClient( | ||
transport=AsyncHTTPTransport(retries=NUMBER_OF_RETRIES), timeout=TIMEOUT | ||
) as client: | ||
url = SOCIAL_SERVICE_URL + path | ||
response = await client.post(url, json=body) | ||
return response | ||
|
||
@staticmethod | ||
async def create_social_user(user_id: int): | ||
try: | ||
response = await SocialService.post(f"/social/users", body={"id": user_id}) | ||
if response.status_code == 201: | ||
return | ||
else: | ||
raise InvalidData() | ||
except Exception as e: | ||
print(f"Unexpected error: {e}") | ||
raise InternalServerErrorException("Social service") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ psycopg2-binary | |
SQLAlchemy | ||
requests_oauthlib | ||
pyjwt | ||
httpx |