Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
feijooso committed Apr 4, 2024
2 parents fb3b117 + 7251a41 commit 43620a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# 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/
.idea/
.DS_Store
7 changes: 7 additions & 0 deletions app/exceptions/UserException.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ def __init__(self):
status_code=status_code,
detail="Invalid user data was provided"
)


class InvalidURL(HTTPException):
def __init__(self, id: int):
status_code = status.HTTP_400_BAD_REQUEST
detail = "Invalid URL"
super().__init__(status_code=status_code, detail=detail)
25 changes: 17 additions & 8 deletions app/service/Users.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from exceptions.UserException import UserNotFound, InvalidData
from exceptions.UserException import UserNotFound, InvalidData, InvalidURL
from exceptions.LoginException import AuthenticationError
from models.users import User
from repository.Users import UsersRepository
import requests
import os
import re


class UsersService:
Expand Down Expand Up @@ -38,13 +39,6 @@ def login(self, auth_code: str):

return user

def update_user(self, user_id: int, update_data: dict):
# TODO: aca habria que chequear a partir del token, session o algo que
# es el propio usuario editando sus datos y no permitir
# que un usuario edite los de un tercero
self.get_user(user_id)
self.user_repository.edit_user(user_id, update_data)

def _get_access_token(self, authorization_code):
token_url = "https://oauth2.googleapis.com/token"
payload = {
Expand Down Expand Up @@ -78,6 +72,21 @@ def _get_user_info(self, access_token):
user_data['photo'] = response.json().get("picture")
return user_data

def update_user(self, user_id: int, update_data: dict):
# TODO: aca habria que chequear a partir del token, session o algo que
# 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'(?:/[^/#?]+)+\.(?:jpg|jpeg|png|gif)$',
photo_url):
raise InvalidURL("Invalid photo URL")
self.user_repository.edit_user(user_id, filtered_update_data)

def _validate_location(self, location):
if "lat" in location and "long" in location:
if -90 <= location["lat"] <= 90 and \
Expand Down

0 comments on commit 43620a6

Please sign in to comment.