diff --git a/zesje/resources/feedback.py b/zesje/resources/feedback.py index da0def981b5278e20bd07d45d1ec34a15911d153..4d1fcdeaefb964c7538189972fcd61a5c27b9048 100644 --- a/zesje/resources/feedback.py +++ b/zesje/resources/feedback.py @@ -1,6 +1,6 @@ """ REST api for problems """ -from flask_restful import Resource +from flask_restful import Resource, reqparse from pony import orm @@ -35,3 +35,34 @@ class Feedback(Resource): } for fb in FeedbackOption.select(lambda fb: fb.problem == problem) ] + + + post_parser = reqparse.RequestParser() + post_parser.add_argument('name', type=str, required=True) + post_parser.add_argument('description', type=str, required=True) + post_parser.add_argument('score', type=int, required=True) + + @orm.db_session + def post(self, problem_id): + """Post a new feedback option + + Parameters + ---------- + name: str + description: str + score: int + """ + + problem = Problem[problem_id] + + args = self.post_parser.parse_args() + + fb = FeedbackOption(problem = problem, text = args.name, description = args.description, score = args.score) + orm.commit(); + + return { + 'id': fb.id, + 'name': fb.text, + 'description': fb.description, + 'score': fb.score + }