added getCoursesByUser function, some added parameters to Messages, and now adding a student to a created course
This commit is contained in:
parent
330304cd4c
commit
b7b44df479
2 changed files with 87 additions and 14 deletions
|
@ -47,13 +47,12 @@ def create_course(token):
|
||||||
<br>
|
<br>
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
- JSON Object, Example: <br>
|
- JSON Object, Example: <br>
|
||||||
{<br>
|
{<br>
|
||||||
'courseName': 'Advance Math',<br>
|
'courseName': 'Advance Math',<br>
|
||||||
'campusName': 'JCE',<br>
|
'campusName': 'JCE',<br>
|
||||||
'startDate': {'year': 2015, 'month' : 4, 'day' : 3}<br>
|
'startDate': {'year': 2015, 'month' : 4, 'day' : 3},<br>
|
||||||
'endDate': {'year': 2016, 'month' : 5, 'day' : 14}<br>
|
'endDate': {'year': 2016, 'month' : 5, 'day' : 14}<br>
|
||||||
'taskFlag': false<br>
|
}<br>
|
||||||
}<br>
|
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Response</b>
|
<b>Response</b>
|
||||||
|
@ -75,7 +74,7 @@ def create_course(token):
|
||||||
try:
|
try:
|
||||||
payload = json.loads(request.data)
|
payload = json.loads(request.data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return bad_request()
|
return bad_request("incorrect JSON format")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start_date = datetime.date(payload['startDate']['year'],payload['startDate']['month'],payload['startDate']['day'])
|
start_date = datetime.date(payload['startDate']['year'],payload['startDate']['month'],payload['startDate']['day'])
|
||||||
|
@ -98,9 +97,14 @@ def create_course(token):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return bad_request()
|
return bad_request(2)
|
||||||
|
|
||||||
db.put(course)
|
db.put(course)
|
||||||
|
|
||||||
|
#add course to user course list
|
||||||
|
user.courses_id_list.append(str(course.key().id()))
|
||||||
|
db.put(user)
|
||||||
|
|
||||||
db.save
|
db.save
|
||||||
return Response(response=course.to_JSON(),
|
return Response(response=course.to_JSON(),
|
||||||
status=201,
|
status=201,
|
||||||
|
@ -149,11 +153,16 @@ def createMessage(token):
|
||||||
return bad_request("here")
|
return bad_request("here")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msg = Message(courseName=payload['courseName'], message=payload['message'], msgDate=datetime.datetime.now())
|
msg = Message(groupId=payload['groupId'], message=payload['message'], msgDate=datetime.datetime.now(), master_id=user.key().id())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return bad_request("there")
|
return bad_request("there")
|
||||||
|
|
||||||
|
try:
|
||||||
|
msg['isProject'] = payload['isProject']
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
db.save(msg)
|
db.save(msg)
|
||||||
db.save
|
db.save
|
||||||
return created()
|
return created()
|
||||||
|
@ -211,6 +220,66 @@ def getCourseByCampusName(name):
|
||||||
status=200,
|
status=200,
|
||||||
mimetype="application/json")
|
mimetype="application/json")
|
||||||
|
|
||||||
|
@course_routes.route('/api/courses/getCoursesByUser/<string:token>/<string:campusId>', methods=['GET'])
|
||||||
|
@auto.doc()
|
||||||
|
def getCampusesByUser(token,campusId):
|
||||||
|
"""
|
||||||
|
<span class="card-title">This Call will return an array of all Campuses of a certain User</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- seToken: 'seToken'<br>
|
||||||
|
- campusId: 1234354543<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- NONE <br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
200 - JSON Array, Example:<br>
|
||||||
|
[<br>
|
||||||
|
{
|
||||||
|
'title': 'JCE',<br>
|
||||||
|
'email_ending': '@post.jce.ac.il',<br>
|
||||||
|
'master_user_id': 123453433341, (User that created the campus)<br>
|
||||||
|
'avatar_url': 'http://some.domain.com/imagefile.jpg',<br>
|
||||||
|
'id' : 1234567890<br>
|
||||||
|
},<br>
|
||||||
|
....<br>
|
||||||
|
{<br>
|
||||||
|
...<br>
|
||||||
|
}req<br>
|
||||||
|
]<br>
|
||||||
|
<br>
|
||||||
|
403 - Invalid Token<br>
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
return bad_request("Bad user Token")
|
||||||
|
|
||||||
|
campus = Campus.get_by_id(int(campusId))
|
||||||
|
if campus is None:
|
||||||
|
return bad_request("No such Campus")
|
||||||
|
|
||||||
|
|
||||||
|
arr = []
|
||||||
|
for i in user['courses_id_list']:
|
||||||
|
course = Course.get_by_id(int(i))
|
||||||
|
if course.courseName == campus.title:
|
||||||
|
arr.append(dict(json.loads(course.to_JSON())))
|
||||||
|
|
||||||
|
if len(arr) != 0:
|
||||||
|
return Response(response=json.dumps(arr),
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
else:
|
||||||
|
return Response(response=[],
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
@course_routes.route('/api/courses/getMessagesByCourseName/<string:name>', methods=["GET"])
|
@course_routes.route('/api/courses/getMessagesByCourseName/<string:name>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def getMessagesByCourseName(name):
|
def getMessagesByCourseName(name):
|
||||||
|
@ -286,7 +355,7 @@ def deleteCourse(token,courseid):
|
||||||
<span class="card-title">This Call will delete a specific Course</span>
|
<span class="card-title">This Call will delete a specific Course</span>
|
||||||
<br>
|
<br>
|
||||||
<b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
- seToken: 'seToken'<br>
|
||||||
- courseid: 'courseid'
|
- courseid: 'courseid'
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -4,13 +4,15 @@ __author__ = 'Aran'
|
||||||
from google.appengine.ext import db
|
from google.appengine.ext import db
|
||||||
|
|
||||||
class Message(db.Model):
|
class Message(db.Model):
|
||||||
courseName = db.StringProperty(required=True)
|
groupId = db.IntegerProperty(required=True)
|
||||||
message = db.StringProperty(required=True)
|
message = db.StringProperty(required=True)
|
||||||
msgDate = db.DateTimeProperty(required=True)
|
msgDate = db.DateTimeProperty(required=True)
|
||||||
|
master_id = db.IntegerProperty(required=True)
|
||||||
|
isProject = db.BooleanProperty(default=False)
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {
|
data = {
|
||||||
'courseName' : self.courseName,
|
'groupId' : self.groupId,
|
||||||
'message' : self.message,
|
'message' : self.message,
|
||||||
'date' : {
|
'date' : {
|
||||||
'year': self.msgDate.year,
|
'year': self.msgDate.year,
|
||||||
|
@ -19,6 +21,8 @@ class Message(db.Model):
|
||||||
'hour': self.msgDate.hour,
|
'hour': self.msgDate.hour,
|
||||||
'minute': self.msgDate.minute
|
'minute': self.msgDate.minute
|
||||||
},
|
},
|
||||||
'id' : self.key().id()
|
'id' : self.key().id(),
|
||||||
|
'master_id' : self.master_id,
|
||||||
|
'isProject' : self.isProject
|
||||||
}
|
}
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
Loading…
Reference in a new issue