def post(self): authorize(request) content = request.get_json() email = content.get('email') if email is None: abort(400, 'Required email field is empty') exist = db.exist_email(email) username = db.get_username(email) if exist is None: abort(500, 'Database screwed up') return {"exist": exist, "displayname": username}
def patch(self): email = authorize(request) # Get payload and set variables uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r, 2) # Get payload and set variables content = request.get_json() info = content.get('info') if info is None: abort(400, 'Required info is empty') description = info.get('description') city = info.get('city') tripstart = info.get('tripstart') tripend = info.get('tripend') jsonblob = content.get('blob') if description is None or city is None or tripstart is None or tripend is None: abort(400, 'Required field inside info is empty') payload = (description, city, tripstart, tripend, json.dumps(jsonblob).encode('utf-8')) try: db.patch_trip(uuid_r, payload) except Exception as e: abort(500, 'We screwed up') return
def get(self): email = authorize(request) # Get payload and set variables uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r) result = db.get_trip(uuid_r) if result is None: abort(404, 'Resource is not available') blob = result[4].decode('utf-8') return { "info": { "description": result[0], "city": result[1], "tripstart": result[2], "tripend": result[3], "modifieddate": result[5] }, "blob": json.loads(blob) }
def patch(self): # Only owner can do this # Modify access permission for user on that trip email = authorize(request) uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r, 0) # Get payload and set variables content = request.get_json() requester_email = content.get("email") permission = content.get("permission") if requester_email is None or permission is None: abort(400, "Bad request") if requester_email == email: abort(403, "You are not allowed to modify your own permission") if not isinstance(permission, int): abort(400, "Permission is not integer") if permission < 1 or permission > 3: abort(403, "Permission number is not allowed") try: db.patch_user_trip(requester_email, uuid_r, permission) except Exception as e: abort(400, "Bad request: " + str(e)) return
def post(self): email = authorize(request) # Get payload and set variables content = request.get_json() info = content.get('info') if info is None: abort(400, 'Required info field is empty') description = info.get('description') city = info.get('city') tripstart = info.get('tripstart') tripend = info.get('tripend') jsonblob = content.get('blob') if description is None or city is None or tripstart is None or tripend is None: abort(400, 'Required field inside info is empty') payload = (description, city, tripstart, tripend, json.dumps(jsonblob).encode('utf-8')) uuid_r = None try: uuid_r = db.post_trip(email, payload) except Exception as e: abort(500, 'We screwed up') if uuid_r is None: abort(500, 'Yes, we screwed up') return {"uuid": uuid_r}
def delete(self): email = authorize(request) uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r, 0) try: db.delete_trip(uuid_r) except Exception as e: abort(500, 'We screwed up') return
def get(self): # All users can see this # List users of the trip email = authorize(request) uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r) result = db.get_user_trip(uuid_r) if result is None: abort(404, 'Resource is not available') return result
def delete(self): # Only owner can do this # Delete user from the trip email = authorize(request) uuid_r = request.args.get('uuid') if uuid_r is None: abort(400, 'Need the uuid') authorize_access(email, uuid_r, 0) content = request.get_json() requester_email = content.get("email") if requester_email is None: abort(400, "Bad request") try: db.delete_user_trip(requester_email, uuid_r) except Exception as e: abort(400, "Bad request: " + str(e)) return
def get(self): email = authorize(request) trips = db.retrieve_trips(email) return {"trips": trips}