Skip to content

Commit

Permalink
Fix formatting and update gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
violetamedallia committed Apr 2, 2024
1 parent 48020fd commit 04549aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.DS_Store
3 changes: 2 additions & 1 deletion app/exceptions/UserException.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ def __init__(self, id: int):
detail = f"User with id {id} not found"
super().__init__(status_code=status_code, detail=detail)


class InvalidURL(HTTPException):
def __init__(self, id: int):
status_code = status.HTTP_400_BAD_REQUEST
detail = f"Invalid URL"
detail = "Invalid URL"
super().__init__(status_code=status_code, detail=detail)
2 changes: 1 addition & 1 deletion app/schemas/Schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, HttpUrl
from pydantic import BaseModel
from typing import Optional


Expand Down
6 changes: 4 additions & 2 deletions app/service/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ 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}
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}(?:/[^/#?]+)+\.(?:jpg|jpeg|png|gif)$', photo_url):
if not re.match(r'^https?://(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}'
r'(?:/[^/#?]+)+\.(?:jpg|jpeg|png|gif)$', photo_url):
raise InvalidURL("Invalid photo URL")
self.user_repository.edit_user(user_id, filtered_update_data)

0 comments on commit 04549aa

Please sign in to comment.