Skip to content

Commit

Permalink
manual fix lint !
Browse files Browse the repository at this point in the history
  • Loading branch information
fjpacheco committed Apr 19, 2024
1 parent 7694c72 commit 5664feb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controller/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def handle_create_user(self, user_data: dict):
status_code=status.HTTP_201_CREATED,
content=jsonable_encoder({
"message": "User created successfully",
"status": status.HTTP_201_CREATED,
"status": status.HTTP_201_CREATED,
}),
)

Expand Down
2 changes: 1 addition & 1 deletion app/exceptions/InternalServerErrorException.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional


class InternalServerErrorException(HTTPException):
class InternalServerErrorExcep(HTTPException):
def __init__(
self,
microservice: Optional[str] = "User service",
Expand Down
3 changes: 2 additions & 1 deletion app/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class User(Base):
__tablename__ = "users"
__table_args__ = {"schema": environ.get("POSTGRES_SCHEMA", "users_service")}
__table_args__ = {"schema": environ.get("POSTGRES_SCHEMA",
"users_service")}
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
name = Column(String, nullable=True)
email = Column(String, nullable=False)
Expand Down
4 changes: 3 additions & 1 deletion app/repository/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


class UsersRepository:
db_url = environ.get("DATABASE_URL").replace("postgres://", "postgresql://", 1)
db_url = environ.get("DATABASE_URL").replace("postgres://",
"postgresql://",
1)

engine = create_engine(db_url)

Expand Down
16 changes: 11 additions & 5 deletions app/service/Social.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import logging
from httpx import AsyncClient, Response, AsyncHTTPTransport
from httpx import (
AsyncClient,
Response,
AsyncHTTPTransport
)
from os import environ

from exceptions.InternalServerErrorException import InternalServerErrorException
from exceptions.InternalServerErrorException import InternalServerErrorExcep
from exceptions.UserException import InvalidData

logger = logging.getLogger("social")
Expand All @@ -21,7 +25,8 @@ class SocialService:
@staticmethod
async def post(path: str, body: dict) -> Response:
async with AsyncClient(
transport=AsyncHTTPTransport(retries=NUMBER_OF_RETRIES), timeout=TIMEOUT
transport=AsyncHTTPTransport(retries=NUMBER_OF_RETRIES),
timeout=TIMEOUT
) as client:
url = SOCIAL_SERVICE_URL + path
response = await client.post(url, json=body)
Expand All @@ -30,11 +35,12 @@ async def post(path: str, body: dict) -> Response:
@staticmethod
async def create_social_user(user_id: int):
try:
response = await SocialService.post("/social/users", body={"id": user_id})
response = await SocialService.post("/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")
raise InternalServerErrorExcep("Social service")
7 changes: 5 additions & 2 deletions app/service/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def login(self, auth_code: str):
user = self.user_repository.get_user_by_email(user_info["email"])
user_id = user.get("id")
payload = {"user_id": user_id}
jwt_token = jwt.encode(payload, os.environ["JWT_SECRET"], algorithm="HS256")
jwt_token = jwt.encode(payload,
os.environ["JWT_SECRET"],
algorithm="HS256")
return user, jwt_token

def _get_access_token(self, authorization_code):
Expand Down Expand Up @@ -94,6 +96,7 @@ def _get_user_info(self, access_token):

def _validate_location(self, location):
if "lat" in location and "long" in location:
if -90 <= location["lat"] <= 90 and -180 <= location["long"] <= 180:
if -90 <= location["lat"] <= 90 and -180 \
<= location["long"] <= 180:
return True
return False

0 comments on commit 5664feb

Please sign in to comment.