From e934a15e7b72f29a7b758997ac43686a40ab0876 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph@weston.cloud>
Date: Thu, 8 Mar 2018 18:17:54 +0100
Subject: [PATCH] add 'Students' resource for getting student list

---
 zesje/api.py                |  2 ++
 zesje/resources/students.py | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 zesje/resources/students.py

diff --git a/zesje/api.py b/zesje/api.py
index 1b4bf94bd..737ae7ac3 100644
--- a/zesje/api.py
+++ b/zesje/api.py
@@ -4,6 +4,7 @@ from flask_restful import Api
 from .resources.graders import Graders
 from .resources.exams import Exams, ExamConfig
 from .resources.pdfs import Pdfs
+from .resources.students import Students
 
 api_bp = Blueprint(__name__, __name__)
 
@@ -20,3 +21,4 @@ api.add_resource(Graders, '/graders')
 api.add_resource(Exams, '/exams')
 api.add_resource(ExamConfig, '/exams/<int:exam_id>')
 api.add_resource(Pdfs, '/pdfs/<int:exam_id>')
+api.add_resource(Students, '/students')
diff --git a/zesje/resources/students.py b/zesje/resources/students.py
new file mode 100644
index 000000000..24aa37ea4
--- /dev/null
+++ b/zesje/resources/students.py
@@ -0,0 +1,29 @@
+from flask_restful import Resource
+from pony import orm
+
+from ..models import Student
+
+class Students(Resource):
+    """Getting a list of students."""
+
+    @orm.db_session
+    def get(self):
+        """get all students for the course.
+
+        Returns
+        -------
+        list of:
+            id: int
+            first_name: str
+            last_name: str
+            email: str
+        """
+        return [
+            {
+                'id': s.id,
+                'first_name': s.first_name,
+                'last_name': s.last_name,
+                'email': s.email,
+            }
+            for s in Student.select()
+        ]
-- 
GitLab