diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index de1d5f3..d950433 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -693,6 +693,7 @@ def getAllUserTasks(token): course = Course.get_by_id(int(c)) dic['courseName'] = course.courseName dic['courseId'] = course.key().id() + dic['master_id'] = course.master_id courseTasks = Task.all().filter("courseId = ", course.key().id()) taskArr = [] for t in courseTasks.run(): @@ -755,6 +756,247 @@ def getAllUserTasks(token): status=200, mimetype="application/json") +@task_routes.route('/api/tasks/getUsersStateByTask//', methods=["GET"]) +@auto.doc() +def getUsersStateByTask(token, taskId): + """ + >This Call will return an array of all of the User's Tasks +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ [
+ {
+ "courseName": "Advance Math",
+ "courseId": 4762397176758272,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 4762397176758272,
+ "title": "task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5888297083600896
+ }
+ ],
+ "projectTasks": []
+ },
+ {
+ "courseName": "Bad Math",
+ "courseId": 5659598665023488,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5096648711602176
+ },
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task4",
+ "description": "pls fddfsdfdsk",
+ "id": 5167017455779840
+ }
+ ],
+ "projectTasks": [
+ {
+ "grade": 12,
+ "isPersonal": false,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task3",
+ "description": "pls fddfsdfdsk",
+ "id": 5237386199957504
+ }
+ ]
+ }
+ ]
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + return bad_request("Bad task id") + + course = Course.get_by_id(task.courseId) + + arr = [] + if task.isPersonal: + for u in enumerate(course.membersId): + user = User.get_by_id(int(u)) + userDic = dict(json.loads(user.to_JSON())) + grade = TaskGrade.all().filter("taskId = ", task.key().id()).filter("userId = ", user.key().id()) + for g in grade.run(): + userDic['grade'] = json.loads(g.to_JSON()) + if grade.count() == 0: + userDic['grade'] = {'taskId': taskId, 'userId': user.key().id(), 'grade': None} + arr.append(userDic) + + else: + projects = Project.all().filter("courseId = ", course.key().id()) + for project in projects.run(): + projDic = dict(json.loads(project.to_JSON())) + grade = TaskGrade.all().filter("taskId = ", task.key().id()).filter("userId = ", project.key().id()) + for g in grade.run(): + projDic['grade'] = json.loads(g.to_JSON()) + if grade.count() == 0: + projDic['grade'] = {'taskId': taskId, 'userId': user.key().id(), 'grade': None} + arr.append(projDic) + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + +@task_routes.route('/api/tasks/isTaskSubmitted///', methods=["GET"]) +@auto.doc() +def isTaskSubmitted(token, taskId, groupId): + """ + >This Call will return an array of all of the User's Tasks +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ [
+ {
+ "courseName": "Advance Math",
+ "courseId": 4762397176758272,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 4762397176758272,
+ "title": "task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5888297083600896
+ }
+ ],
+ "projectTasks": []
+ },
+ {
+ "courseName": "Bad Math",
+ "courseId": 5659598665023488,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5096648711602176
+ },
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task4",
+ "description": "pls fddfsdfdsk",
+ "id": 5167017455779840
+ }
+ ],
+ "projectTasks": [
+ {
+ "grade": 12,
+ "isPersonal": false,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task3",
+ "description": "pls fddfsdfdsk",
+ "id": 5237386199957504
+ }
+ ]
+ }
+ ]
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + return bad_request("Bad task id") + + res = {} + + grade = TaskGrade.all().filter("taskId = ", task.key().id()).filter("userId = ", int(groupId)) + if grade.count() == 0: + res['submitted'] = False + else: + res['submitted'] = True + + + + return Response(response=res, + status=200, + mimetype="application/json") # @task_routes.route('/api/tasks/getAllUngradedTasks///', methods=["GET"]) # @auto.doc()