4040
4141profile_edit_bp = Blueprint ("profile_edit" , __name__ )
4242
43- REQUIRED_PARAMS_EDIT_PROFILE = {
44- "first_name" : str ,
45- "last_name" : str ,
46- "username" : str ,
47- "bio" : str ,
48- "gender" : str ,
49- "orientation" : str ,
50- "birthdate" : str ,
51- "tags" : list ,
52- }
53-
5443
5544@profile_edit_bp .route ("/profile/edit/first_name" , methods = ["PATCH" ])
5645@validate_params ({"first_name" : str })
@@ -97,10 +86,40 @@ def edit_profile_username():
9786 return Success ("Username successfully modified!" )
9887
9988
100- # bio = data["bio"]
89+ @profile_edit_bp .route ("/profile/edit/bio" , methods = ["PATCH" ])
90+ @validate_params ({"bio" : str })
91+ @jwt_required
92+ def edit_profile_bio ():
93+ if not current_user .is_profile_completed :
94+ raise BadRequestError ("The user has not completed his profile." , "Complete your profile and try again." )
95+ data = request .get_json ()
96+ bio = data ["bio" ]
97+ if len (bio ) <= 50 :
98+ raise BadRequestError ("Bio is too short." )
99+ current_user .bio = bio
100+ current_user .save ()
101+ return Success ("Bio successfully modified!" )
102+
103+
104+ @profile_edit_bp .route ("/profile/edit/gender" , methods = ["PATCH" ])
105+ @validate_params ({"gender" : str })
106+ @jwt_required
107+ def edit_profile_gender ():
108+ if not current_user .is_profile_completed :
109+ raise BadRequestError ("The user has not completed his profile." , "Complete your profile and try again." )
110+ data = request .get_json ()
111+ gender = data ["gender" ]
112+ if gender not in ["male" , "female" , "other" ]:
113+ raise BadRequestError ("Gender must be male, female or other." )
114+ current_user .gender = gender
115+ current_user .save ()
116+ return Success ("Gender successfully modified!" )
117+
118+
101119# gender = data["gender"]
102120# orientation = data["orientation"]
103121# birthdate = data["birthdate"]
122+ # TAGS
104123#
105124# try:
106125# birthdate = datetime.datetime.strptime(birthdate, "%d/%m/%Y").date()
@@ -118,10 +137,8 @@ def edit_profile_username():
118137# if orientation not in ["heterosexual", "homosexual", "bisexual", "other"]:
119138# raise BadRequestError("Orientation must be heterosexual, homosexual, bisexual or other.")
120139#
121- # if gender not in ["male", "female", "other"]:
122- # raise BadRequestError("Gender must be male, female or other.")
140+
123141#
124- # current_user.bio = bio
125142# current_user.gender = gender
126143# current_user.orientation = orientation
127144# current_user.birthdate = birthdate
0 commit comments