diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py
index 972b047..d50fb90 100644
--- a/SE_API/CourseRoutes.py
+++ b/SE_API/CourseRoutes.py
@@ -47,13 +47,12 @@ def create_course(token):
Payload
- JSON Object, Example:
- {
- 'courseName': 'Advance Math',
- 'campusName': 'JCE',
- 'startDate': {'year': 2015, 'month' : 4, 'day' : 3}
- 'endDate': {'year': 2016, 'month' : 5, 'day' : 14}
- 'taskFlag': false
- }
+ {
+ 'courseName': 'Advance Math',
+ 'campusName': 'JCE',
+ 'startDate': {'year': 2015, 'month' : 4, 'day' : 3},
+ 'endDate': {'year': 2016, 'month' : 5, 'day' : 14}
+ }
Response
@@ -75,7 +74,7 @@ def create_course(token):
try:
payload = json.loads(request.data)
except Exception as e:
- return bad_request()
+ return bad_request("incorrect JSON format")
try:
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:
print e
- return bad_request()
+ return bad_request(2)
db.put(course)
+
+ #add course to user course list
+ user.courses_id_list.append(str(course.key().id()))
+ db.put(user)
+
db.save
return Response(response=course.to_JSON(),
status=201,
@@ -149,11 +153,16 @@ def createMessage(token):
return bad_request("here")
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:
print e
return bad_request("there")
+ try:
+ msg['isProject'] = payload['isProject']
+ except Exception as e:
+ pass
+
db.save(msg)
db.save
return created()
@@ -211,6 +220,66 @@ def getCourseByCampusName(name):
status=200,
mimetype="application/json")
+@course_routes.route('/api/courses/getCoursesByUser//', methods=['GET'])
+@auto.doc()
+def getCampusesByUser(token,campusId):
+ """
+ This Call will return an array of all Campuses of a certain User
+
+ Route Parameters
+ - seToken: 'seToken'
+ - campusId: 1234354543
+
+
+ Payload
+ - NONE
+
+
+ Response
+
+ 200 - JSON Array, Example:
+ [
+ {
+ 'title': 'JCE',
+ 'email_ending': '@post.jce.ac.il',
+ 'master_user_id': 123453433341, (User that created the campus)
+ 'avatar_url': 'http://some.domain.com/imagefile.jpg',
+ 'id' : 1234567890
+ },
+ ....
+ {
+ ...
+ }req
+ ]
+
+ 403 - Invalid Token
+ """
+
+ 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/', methods=["GET"])
@auto.doc()
def getMessagesByCourseName(name):
@@ -286,7 +355,7 @@ def deleteCourse(token,courseid):
This Call will delete a specific Course
Route Parameters
- - seToken: 'seToken'
+ - seToken: 'seToken'
- courseid: 'courseid'
diff --git a/models/Message.py b/models/Message.py
index a5dc29f..23019e9 100644
--- a/models/Message.py
+++ b/models/Message.py
@@ -4,13 +4,15 @@ __author__ = 'Aran'
from google.appengine.ext import db
class Message(db.Model):
- courseName = db.StringProperty(required=True)
+ groupId = db.IntegerProperty(required=True)
message = db.StringProperty(required=True)
msgDate = db.DateTimeProperty(required=True)
+ master_id = db.IntegerProperty(required=True)
+ isProject = db.BooleanProperty(default=False)
def to_JSON(self):
data = {
- 'courseName' : self.courseName,
+ 'groupId' : self.groupId,
'message' : self.message,
'date' : {
'year': self.msgDate.year,
@@ -19,6 +21,8 @@ class Message(db.Model):
'hour': self.msgDate.hour,
'minute': self.msgDate.minute
},
- 'id' : self.key().id()
+ 'id' : self.key().id(),
+ 'master_id' : self.master_id,
+ 'isProject' : self.isProject
}
return json.dumps(data)