diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 594975c..02d460e 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -205,6 +205,64 @@ def getCampusesByUser(token): status=200, mimetype="application/json") +@campus_routes.route('/api/campuses/getCampusesByUserID/', defaults={'token': None, 'id': None}) +@campus_routes.route('/api/campuses/getCampusesByUserID//', methods=['GET']) +@auto.doc() +def getCampusesByUserID(token, id): + """ + This Call will return an array of all Campuses of a certain User By ID +
+ Route Parameters
+ - token: 'seToken' of requesting user + - The ID of Wanted User Campuses +
+
+ 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 forbidden("Invalid Token") + + user = get_user_by_id(int(id)) + if user is None: + return no_content("No User") + + arr = [] + for i in user.campuses_id_list: + campus = Campus.get_by_id(int(i)) + arr.append(dict(json.loads(campus.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") + #---------------------------------------------------------- # DELETE #----------------------------------------------------------