Created
December 20, 2015 23:25
-
-
Save pcote/3c37f6fc4d5b6353d9f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| def validate_json(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| json_data = request.get_json() | |
| if "exercise_id" not in json_data or "score" not in json_data: | |
| abort(400) | |
| return func(*args, **kwargs) | |
| return wrapper | |
| @app.route("/addscore", methods=["POST"]) | |
| @validate_json | |
| def add_score(): | |
| json_data = request.get_json() | |
| exercise_id = json_data.get("exercise_id") | |
| score = json_data.get("score") | |
| model.add_attempt(exercise_id, score) | |
| return jsonify(dict(result="success")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment