From 5664feb8cfcb30b079f2383bee8123a510af619c Mon Sep 17 00:00:00 2001 From: Federico Pacheco Date: Fri, 19 Apr 2024 17:59:22 -0300 Subject: [PATCH] manual fix lint ! --- app/controller/Users.py | 2 +- app/exceptions/InternalServerErrorException.py | 2 +- app/models/users.py | 3 ++- app/repository/Users.py | 4 +++- app/service/Social.py | 16 +++++++++++----- app/service/Users.py | 7 +++++-- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/controller/Users.py b/app/controller/Users.py index 1a87427..b88e84f 100644 --- a/app/controller/Users.py +++ b/app/controller/Users.py @@ -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, }), ) diff --git a/app/exceptions/InternalServerErrorException.py b/app/exceptions/InternalServerErrorException.py index e1dae6c..1bdfec6 100644 --- a/app/exceptions/InternalServerErrorException.py +++ b/app/exceptions/InternalServerErrorException.py @@ -2,7 +2,7 @@ from typing import Optional -class InternalServerErrorException(HTTPException): +class InternalServerErrorExcep(HTTPException): def __init__( self, microservice: Optional[str] = "User service", diff --git a/app/models/users.py b/app/models/users.py index f350ee5..f975eb9 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -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) diff --git a/app/repository/Users.py b/app/repository/Users.py index d4c95c5..d913bb0 100644 --- a/app/repository/Users.py +++ b/app/repository/Users.py @@ -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) diff --git a/app/service/Social.py b/app/service/Social.py index 62a5830..4a68375 100644 --- a/app/service/Social.py +++ b/app/service/Social.py @@ -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") @@ -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) @@ -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") diff --git a/app/service/Users.py b/app/service/Users.py index 39c6226..8f71524 100644 --- a/app/service/Users.py +++ b/app/service/Users.py @@ -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): @@ -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