File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 178178from PyMatcha .routes .api .recommendations import recommendations_bp
179179from PyMatcha .routes .api .profile .images import images_bp
180180from PyMatcha .routes .api .search import search_bp
181+ from PyMatcha .routes .api .profile .block import profile_block_bp
181182
182183logging .debug ("Registering Flask blueprints" )
183184application .register_blueprint (user_bp )
195196application .register_blueprint (recommendations_bp )
196197application .register_blueprint (images_bp )
197198application .register_blueprint (search_bp )
199+ application .register_blueprint (profile_block_bp )
198200
199201if application .debug :
200202 logging .debug ("Registering debug route" )
Original file line number Diff line number Diff line change 3030
3131@profile_block_bp .route ("/profile/block/<uid>" , methods = ["POST" ])
3232@jwt_required
33- def report_profile (uid ):
33+ def block_profile (uid ):
3434 try :
3535 u = get_user (uid )
3636 except NotFoundError :
3737 raise NotFoundError (f"User { uid } not found." )
3838 if current_user .id == u .id :
3939 raise BadRequestError ("Cannot block yourself." )
40- Block .create (blocker_id = current_user .id , blocked_id = u .id )
40+ try :
41+ Block .get_multi (blocker_id = current_user .id , blocked_id = u .id )
42+ except NotFoundError :
43+ Block .create (blocker_id = current_user .id , blocked_id = u .id )
44+ return Success (f"Successfully blocked { u .email } ." )
45+ else :
46+ return BadRequestError ("You already blocked this user." )
47+
4148
42- return Success (f"Successfully blocked { u .email } ." )
49+ @profile_block_bp .route ("/profile/unblock/<uid>" , methods = ["POST" ])
50+ @jwt_required
51+ def unblock_profile (uid ):
52+ try :
53+ u = get_user (uid )
54+ except NotFoundError :
55+ raise NotFoundError (f"User { uid } not found." )
56+ try :
57+ block = Block .get_multi (blocker_id = current_user .id , blocked_id = u .id )
58+ except NotFoundError :
59+ raise BadRequestError ("You didn't block this user." )
60+ else :
61+ block .delete ()
62+ return Success ("Unblock successful." )
You can’t perform that action at this time.
0 commit comments