Skip to content

Commit

Permalink
update user
Browse files Browse the repository at this point in the history
  • Loading branch information
rashikaqureshi committed Jul 31, 2020
1 parent e72328f commit 8c83b56
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions app/api/dao/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
return messages.USER_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND

username = data.get("username", None)
name = data.get("name",None)

if username:
user_with_same_username = UserModel.find_by_username(username)

Expand All @@ -224,8 +224,17 @@ def update_user_profile(user_id: int, data: Dict[str, str]):

user.username = username

if "name" in data and data["name"]:
user.name = data["name"]
if "name" in data:
if data["name"]:
user.name = data["name"]
else:
return messages.NAME_FIELD_IS_MISSING,HTTPStatus.OK

if "username" in data:
if data["username"]:
user.username = data["username"]
else:
return messages.USERNAME_FIELD_IS_MISSING,HTTPStatus.OK

if "bio" in data:
if data["bio"]:
Expand Down Expand Up @@ -293,14 +302,14 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
if "available_to_mentor" in data:
user.available_to_mentor = data["available_to_mentor"]

if not username and not name:
return messages.USER_AND_USERNAME_FIELD_IS_MISSING,HTTPStatus.OK
# if not username and not name:
# return messages.USER_AND_USERNAME_FIELD_IS_MISSING,HTTPStatus.OK

if not username:
return messages.USERNAME_FIELD_IS_MISSING,HTTPStatus.OK
# if not username:
# return messages.USERNAME_FIELD_IS_MISSING,HTTPStatus.OK

if not name :
return messages.NAME_FIELD_IS_MISSING,HTTPStatus.OK
# if not name :
# return messages.NAME_FIELD_IS_MISSING,HTTPStatus.OK
user.save_to_db()

return messages.USER_SUCCESSFULLY_UPDATED, HTTPStatus.OK
Expand Down

0 comments on commit 8c83b56

Please sign in to comment.