diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index fc5bf90..943f8bf 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -145,7 +145,9 @@ def joinProject(token, projectId): return bad_request("User is already member in Project") project.membersId.append(str(user.key().id())) + user.projects_id_list.append(str(project.key().id())) + db.put(user) db.put(project) db.save diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index ee3bee6..a7ec923 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -353,7 +353,7 @@ def getTaskComponents(token, taskId): @task_routes.route('/api/tasks/getAllUserTasks/', methods=["GET"]) @auto.doc() -def getAllTasksByUser(token): +def getAllUserTasks(token): """ >This Call will return an array of all of the User's Tasks
@@ -491,70 +491,81 @@ def getAllTasksByUser(token): -# @task_routes.route('/api/tasks/getUserFullTasksById//', methods=["GET"]) -# @auto.doc() -# def getFullTasksById(token, taskId): -# """ -# >This Call will return an array of all components for a given task -#
-# Route Parameters
-# - SeToken: token
-# - taskId: 1234567890 -#
-#
-# Payload
-# - NONE -#
-#
-# Response -#
-# 200 - JSON Example:
-# -# [ -# {
-# 'taskId' : 7589454894, -# 'userId' : -1, -# 'type' : 'kindOfType', -# 'label' : 'kindOfLabel', -# 'isMandatory' : true, -# 'order' : 2 -# }
-# {
-# 'taskId' : 7589454894, -# 'userId' : yossi, -# 'type' : 'otherKindOfType', -# 'label' : 'otherKindOfLabel', -# 'isMandatory' : false, -# 'order' : 4 -# }
-# ] -#
-#
-# """ -# 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") -# -# taskCompQuery = TaskComponent.all() -# taskCompQuery.filter("taskId = ", task.key().id()) -# -# if task.isPersonal: -# taskCompQuery.filter("userId = ", user.key().id()) -# else: -# taskCompQuery.filter("userId = ", user.key().id()) -# -# if taskCompQuery.count() == 0: -# #create componenets and Score for user -# -# -# for i in taskCompQuery.run(): -# print i.to_JSON() -# -# return no_content() +@task_routes.route('/api/tasks/getUserTaskById//', methods=["GET"]) +@auto.doc() +def getUserTaskById(token, taskId): + """ + >This Call will return an array of all components for a given task +
+ Route Parameters
+ - SeToken: token
+ - taskId: 1234567890 +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + [ + {
+ 'taskId' : 7589454894, + 'userId' : -1, + 'type' : 'kindOfType', + 'label' : 'kindOfLabel', + 'isMandatory' : true, + 'order' : 2 + }
+ {
+ 'taskId' : 7589454894, + 'userId' : yossi, + 'type' : 'otherKindOfType', + 'label' : 'otherKindOfLabel', + 'isMandatory' : false, + 'order' : 4 + }
+ ] +
+
+ """ + 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") + + + taskCompQuery = TaskComponent.all() + taskCompQuery.filter("taskId = ", task.key().id()) + + if task.isPersonal: + taskCompQuery.filter("userId = ", user.key().id()) + else: + taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project + + #check if never created a personalized task and if so, create it + if taskCompQuery.count() == 0: + taskCompQuery = TaskComponent.all().filter("taskId = ", task.key().id()).filter("userId = ", -1) + for tc in taskCompQuery.run(): + tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order) + db.put(tcNew) + + grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id()) + db.put(grade) + + + + + + + + db.save + return no_content() diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index 09de2df..1e8440c 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -322,16 +322,15 @@ def getUserById(token, id): if u is None: return no_content('No user Found') + for index, c in enumerate(u.campuses_id_list): c = json.loads(Campus.get_by_id(int(c)).to_JSON()) u.campuses_id_list[index] = c - return Response(response=u.to_JSON(), + return Response(response=u.to_JSON(), status=200, mimetype="application/json") # Real response! - return no_content("No User Found") - @user_routes.route('/api/users/getUsersByCampus//', methods=["GET"]) @@ -579,6 +578,7 @@ def removeUserFromCampus(token, userId, campusId): if requestingUser.key().id() != userToRemove.key().id(): return forbidden("No permission to delete user") + #remove campus from user campus list try: userToRemove.campuses_id_list.remove(campusId) except Exception as e: @@ -646,6 +646,13 @@ def removeUserFromCourse(token, userId, courseId): except Exception as e: return bad_request("user is not listed to this course") + #remove user from all projects in course + projects = Project.all().filter("courseId =", course.key().id()) + for p in projects: + if p.key().id() in userToRemove.projects_id_list: + userToRemove.projects_id_list.remove(p.key().id()) + p.membersId.remove(userToRemove.key().id()) + db.put(p) db.put(userToRemove)