Skip to content

Commit 0a97a95

Browse files
committed
Added debug route to create fake report
1 parent 6f0c2b8 commit 0a97a95

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

backend/PyMatcha/routes/api/debug.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
from flask import Blueprint
66
from flask import current_app
77
from flask import jsonify
8+
from flask import request
89
from PyMatcha import redis
910
from PyMatcha.errors import NotFoundError
1011
from PyMatcha.models.report import Report
1112
from PyMatcha.models.view import View
1213
from PyMatcha.success import Success
1314
from PyMatcha.success import SuccessDeleted
1415
from PyMatcha.utils.decorators import debug_token_required
16+
from PyMatcha.utils.decorators import validate_params
1517

1618
debug_bp = Blueprint("debug", __name__)
1719

@@ -94,7 +96,7 @@ def delete_reports():
9496
return "", 204
9597

9698

97-
@debug_bp.route("/debug/reports")
99+
@debug_bp.route("/debug/reports", methods=["GET"])
98100
@debug_token_required
99101
def debug_get_all_reports():
100102
report_list = []
@@ -103,10 +105,26 @@ def debug_get_all_reports():
103105
return jsonify(report_list)
104106

105107

106-
@debug_bp.route("/debug/reports/<uid>")
108+
@debug_bp.route("/debug/reports/<uid>", methods=["GET"])
107109
@debug_token_required
108110
def debug_get_user_reports(uid):
109111
u = get_user(uid)
110112
reports_received = [r.to_dict() for r in u.get_reports_received()]
111113
reports_sent = [r.to_dict() for r in u.get_reports_sent()]
112114
return jsonify({"reports_received": reports_received, "reports_sent": reports_sent}), 200
115+
116+
117+
DEBUG_CREATE_FAKE_REPORT = {"reporter_id": int, "reported_id": int, "reason": str, "details": str}
118+
119+
120+
@debug_bp.route("/debug/reports", methods=["POST"])
121+
@debug_token_required
122+
@validate_params(DEBUG_CREATE_FAKE_REPORT)
123+
def debug_create_report():
124+
data = request.get_json()
125+
reporter_id = data["reporter_id"]
126+
reported_id = data["reported_id"]
127+
reason = data["reason"]
128+
details = data["details"]
129+
Report.create(reported_id=reported_id, reporter_id=reporter_id, reason=reason, details=details)
130+
return "", 204

0 commit comments

Comments
 (0)