From fb3b1178965c8c5cada02b1b568ac75c3f37d4f3 Mon Sep 17 00:00:00 2001 From: feijooso Date: Wed, 3 Apr 2024 01:30:13 -0300 Subject: [PATCH] add bio and nickname --- app/docker/tablas.sql | 4 +++- app/exceptions/UserException.py | 7 +++++-- app/models/users.py | 2 ++ app/repository/Users.py | 6 ++++++ app/schemas/Schemas.py | 8 ++++++++ app/service/Users.py | 9 ++++----- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/docker/tablas.sql b/app/docker/tablas.sql index a649ed8..f5f45eb 100644 --- a/app/docker/tablas.sql +++ b/app/docker/tablas.sql @@ -7,7 +7,9 @@ CREATE TABLE IF NOT EXISTS users_service.users ( gender VARCHAR(20), photo VARCHAR(255), birthdate DATE, - location JSONB + location JSONB, + nickname VARCHAR(30), + biography VARCHAR(255) ); INSERT INTO diff --git a/app/exceptions/UserException.py b/app/exceptions/UserException.py index 5aa7b1a..c644507 100644 --- a/app/exceptions/UserException.py +++ b/app/exceptions/UserException.py @@ -7,8 +7,11 @@ def __init__(self, id: int): detail = f"User with id {id} not found" super().__init__(status_code=status_code, detail=detail) + class InvalidData(HTTPException): def __init__(self): status_code = status.HTTP_400_BAD_REQUEST - detail = f"Invalid user data was provided" - super().__init__(status_code=status_code, detail=detail) \ No newline at end of file + super().__init__( + status_code=status_code, + detail="Invalid user data was provided" + ) diff --git a/app/models/users.py b/app/models/users.py index cc63fbf..ab73efe 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -15,3 +15,5 @@ class User(Base): photo = Column(String, nullable=True) birthdate = Column(Date, nullable=True) location = Column(JSON, nullable=True) + nickname = Column(String, nullable=True) + biography = Column(String, nullable=True) diff --git a/app/repository/Users.py b/app/repository/Users.py index 3a3b686..54cfdaa 100644 --- a/app/repository/Users.py +++ b/app/repository/Users.py @@ -49,6 +49,8 @@ def create_user( name: Optional[str] = None, gender: Optional[str] = None, photo: Optional[str] = None, + nickname: Optional[str] = None, + biography: Optional[str] = None, location: Optional[dict] = None, birthdate: Optional[date] = None ) -> User: @@ -64,6 +66,10 @@ def create_user( user_data["location"] = location if birthdate is not None: user_data["birthdate"] = birthdate + if nickname is not None: + user_data["nickname"] = nickname + if biography is not None: + user_data["biography"] = biography new_user = User(**user_data) self.session.add(new_user) diff --git a/app/schemas/Schemas.py b/app/schemas/Schemas.py index 1c36ca5..ad0718c 100644 --- a/app/schemas/Schemas.py +++ b/app/schemas/Schemas.py @@ -11,6 +11,8 @@ class UserSchema(BaseModel): photo: str birthdate: date location: Dict + nickname: str + biography: str class CreateUserSchema(BaseModel): @@ -20,6 +22,8 @@ class CreateUserSchema(BaseModel): photo: Optional[str] = None birthdate: Optional[date] = None location: Optional[Dict] = None + nickname: Optional[str] = None + biography: Optional[str] = None class LoginRequest(BaseModel): @@ -30,3 +34,7 @@ class UpdateUserSchema(BaseModel): name: Optional[str] = None gender: Optional[str] = None photo: Optional[HttpUrl] = None + birthdate: Optional[date] = None + location: Optional[Dict] = None + nickname: Optional[str] = None + biography: Optional[str] = None diff --git a/app/service/Users.py b/app/service/Users.py index b219f17..a9f7cf6 100644 --- a/app/service/Users.py +++ b/app/service/Users.py @@ -20,8 +20,7 @@ def get_all_users(self): return self.user_repository.get_all_users() def create_user(self, user_data: dict): - email = user_data.get("email") - if (not self._validate_location(user_data.get("location"))): + if not self._validate_location(user_data.get("location")): raise InvalidData() return self.user_repository.create_user(**user_data) @@ -81,7 +80,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): return True + if -90 <= location["lat"] <= 90 and \ + -180 <= location["long"] <= 180: + return True return False - -