added: - memberId list property
This commit is contained in:
parent
7c5115869c
commit
4b89432520
2 changed files with 54 additions and 0 deletions
|
@ -99,6 +99,8 @@ def create_course(token):
|
||||||
print e
|
print e
|
||||||
return bad_request(2)
|
return bad_request(2)
|
||||||
|
|
||||||
|
#add user to course membersId list
|
||||||
|
course.membersId.append(str(user.key().id()))
|
||||||
db.put(course)
|
db.put(course)
|
||||||
|
|
||||||
#add course to user course list
|
#add course to user course list
|
||||||
|
@ -169,6 +171,56 @@ def createMessage(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------
|
||||||
|
# PUT
|
||||||
|
#----------------------------------------------------------
|
||||||
|
|
||||||
|
@course_routes.route('/api/courses/joinCourse/<string:token>/<string:courseId>', methods=["PUT"])
|
||||||
|
@auto.doc()
|
||||||
|
def joinCourse(token, courseId):
|
||||||
|
"""
|
||||||
|
<span class="card-title">This call will add the user (by token) to a specific course</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- seToken: 'seToken'<br>
|
||||||
|
- courseId: 123456789
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- None <br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
202 - Accepted
|
||||||
|
<br>
|
||||||
|
400 - Bad Request
|
||||||
|
<br>
|
||||||
|
403 - Invalid token or not a lecturer
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
return bad_request("Wrong user Token")
|
||||||
|
|
||||||
|
course = Course.get_by_id(int(courseId))
|
||||||
|
if course is None:
|
||||||
|
return bad_request("No such course")
|
||||||
|
|
||||||
|
if user.key().id() in course.membersId:
|
||||||
|
return no_content("User is already member in Project")
|
||||||
|
|
||||||
|
course.membersId.append(str(user.key().id()))
|
||||||
|
user.courses_id_list.append(str(course.key().id()))
|
||||||
|
|
||||||
|
db.put(course)
|
||||||
|
db.put(user)
|
||||||
|
db.save
|
||||||
|
|
||||||
|
return Response(response=course.to_JSON(),
|
||||||
|
status=202,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# GET
|
# GET
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Course(db.Model):
|
||||||
# projects = db.StringListProperty(required=True,default=[])
|
# projects = db.StringListProperty(required=True,default=[])
|
||||||
startDate = db.DateProperty(required=True)
|
startDate = db.DateProperty(required=True)
|
||||||
endDate = db.DateProperty(required=True)
|
endDate = db.DateProperty(required=True)
|
||||||
|
membersId = db.StringListProperty(required=True)
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'courseName' : self.courseName,
|
data = {'courseName' : self.courseName,
|
||||||
|
@ -26,6 +27,7 @@ class Course(db.Model):
|
||||||
'month': self.endDate.month,
|
'month': self.endDate.month,
|
||||||
'day': self.endDate.day,
|
'day': self.endDate.day,
|
||||||
},
|
},
|
||||||
|
'membersId' : self.membersId,
|
||||||
'id' : self.key().id()
|
'id' : self.key().id()
|
||||||
}
|
}
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
Loading…
Reference in a new issue