Skip to content

Commit 516c84a

Browse files
committed
Added unblock route
1 parent a3e0b9b commit 516c84a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

backend/PyMatcha/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
from PyMatcha.routes.api.recommendations import recommendations_bp
179179
from PyMatcha.routes.api.profile.images import images_bp
180180
from PyMatcha.routes.api.search import search_bp
181+
from PyMatcha.routes.api.profile.block import profile_block_bp
181182

182183
logging.debug("Registering Flask blueprints")
183184
application.register_blueprint(user_bp)
@@ -195,6 +196,7 @@
195196
application.register_blueprint(recommendations_bp)
196197
application.register_blueprint(images_bp)
197198
application.register_blueprint(search_bp)
199+
application.register_blueprint(profile_block_bp)
198200

199201
if application.debug:
200202
logging.debug("Registering debug route")

backend/PyMatcha/routes/api/profile/block.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,33 @@
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.")

0 commit comments

Comments
 (0)