Skip to content

Commit

Permalink
add bio and nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
feijooso committed Apr 3, 2024
1 parent e50ffb7 commit fb3b117
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/docker/tablas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/exceptions/UserException.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
super().__init__(
status_code=status_code,
detail="Invalid user data was provided"
)
2 changes: 2 additions & 0 deletions app/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions app/repository/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions app/schemas/Schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class UserSchema(BaseModel):
photo: str
birthdate: date
location: Dict
nickname: str
biography: str


class CreateUserSchema(BaseModel):
Expand All @@ -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):
Expand All @@ -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
9 changes: 4 additions & 5 deletions app/service/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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


0 comments on commit fb3b117

Please sign in to comment.