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 c9e6425 commit 7694c72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
48 changes: 19 additions & 29 deletions app/controller/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ def handle_get_user(self, user_id: int):
user = self.users_service.get_user(user_id)
return JSONResponse(
status_code=status.HTTP_200_OK,
content=jsonable_encoder(
{
"message": user,
"status": status.HTTP_200_OK,
}
),
content=jsonable_encoder({
"message": user,
"status": status.HTTP_200_OK,
})
)

def handle_get_all_users(self, ids: list | None = None):
Expand All @@ -28,49 +26,41 @@ def handle_get_all_users(self, ids: list | None = None):
users = self.users_service.get_users_by_ids(ids)
return JSONResponse(
status_code=status.HTTP_200_OK,
content=jsonable_encoder(
{
"message": users,
"status": status.HTTP_200_OK,
}
),
content=jsonable_encoder({
"message": users,
"status": status.HTTP_200_OK,
})
)
else:
users = self.users_service.get_all_users()
return JSONResponse(
status_code=status.HTTP_200_OK,
content=jsonable_encoder(
{
"message": users,
"status": status.HTTP_200_OK,
}
),
content=jsonable_encoder({
"message": users,
"status": status.HTTP_200_OK,
}),
)

async def handle_create_user(self, user_data: dict):
result = self.users_service.create_user(user_data)
await SocialService.create_social_user(user_id=result.id)
return JSONResponse(
status_code=status.HTTP_201_CREATED,
content=jsonable_encoder(
{
"message": "User created successfully",
content=jsonable_encoder({
"message": "User created successfully",
"status": status.HTTP_201_CREATED,
}
),
}),
)

async def handle_login(self, auth_code: str):
user, jwt_token = self.users_service.login(auth_code)
await SocialService.create_social_user(user_id=user.get("id"))
return JSONResponse(
status_code=status.HTTP_200_OK,
content=jsonable_encoder(
{
"message": user,
"status": status.HTTP_200_OK,
}
),
content=jsonable_encoder({
"message": user,
"status": status.HTTP_200_OK,
}),
headers={"x-access-token": f"{jwt_token}"},
)

Expand Down
14 changes: 6 additions & 8 deletions app/service/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ def update_user(self, user_id: int, update_data: dict):
# es el propio usuario editando sus datos y no permitir
# que un usuario edite los de un tercero
self.get_user(user_id)
filtered_update_data = {k: v for k, v in update_data.items() if v is not None}
if "photo" in filtered_update_data:
photo_url = filtered_update_data["photo"]
if not re.match(
r"^https?://(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}"
r"(?:/[^/#?]+)+(?:\?.*)?$",
photo_url,
):
filtered_update_data = {k: v for k, v in update_data.items()
if v is not None}
if 'photo' in filtered_update_data:
photo_url = filtered_update_data['photo']
if not re.match(r'^https?://(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}'
r'(?:/[^/#?]+)+(?:\?.*)?$', photo_url):
raise InvalidURL("Invalid photo URL")
self.user_repository.edit_user(user_id, filtered_update_data)

Expand Down

0 comments on commit 7694c72

Please sign in to comment.