From 2c002e87ec8d16ff64ee746e9a40b000df43fc30 Mon Sep 17 00:00:00 2001
From: Roosted7 <thomasroos@live.nl>
Date: Thu, 22 Mar 2018 22:42:36 +0100
Subject: [PATCH] Get api for feedback(options)

---
 zesje/api.py                |  3 +++
 zesje/resources/feedback.py | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 zesje/resources/feedback.py

diff --git a/zesje/api.py b/zesje/api.py
index 2d1d4ce5a..3c33101e3 100644
--- a/zesje/api.py
+++ b/zesje/api.py
@@ -8,6 +8,7 @@ from .resources.students import Students
 from .resources.submissions import Submissions
 from .resources import signature
 from .resources.problems import Problems
+from .resources.feedback import Feedback
 
 api_bp = Blueprint(__name__, __name__)
 
@@ -29,6 +30,8 @@ api.add_resource(Submissions,
                  '/submissions/<int:exam_id>',
                  '/submissions/<int:exam_id>/<int:submission_id>')
 api.add_resource(Problems, '/problems/<int:exam_id>')
+api.add_resource(Feedback, '/feedback/<int:problem_id>')
+
 
 # Other resources that don't return JSON
 # It is possible to get flask_restful to work with these, but not
diff --git a/zesje/resources/feedback.py b/zesje/resources/feedback.py
new file mode 100644
index 000000000..d59824a12
--- /dev/null
+++ b/zesje/resources/feedback.py
@@ -0,0 +1,35 @@
+""" REST api for problems """
+
+from flask_restful import Resource
+
+from pony import orm
+
+from ..models import Problem, FeedbackOption
+
+class Feedback(Resource):
+    """ List of feedback options of a problem """
+
+    @orm.db_session
+    def get(self, problem_id):
+        """get list of feedback connected to a specific problem
+
+        Returns
+        -------
+        list of:
+            id: int
+            name: str
+            description: str
+            score: int
+        """
+
+        problem = Problem[problem_id]
+
+        return [
+            {
+                'id': fb.id,
+                'name': fb.text,
+                'description': fb.description,
+                'score': fb.score
+            }
+            for fb in FeedbackOption.select(lambda fb: fb.problem == problem)
+        ]
-- 
GitLab