def get(self): # Local variables return_object = {} # Get parameters parser = reqparse.RequestParser() parser.add_argument('userid', type=str) parser.add_argument('userauthtoken', type=str) args = parser.parse_args() # Check if userid matches authtoken in DB if len(db.session.query(user).filter(user.id == args.userid).filter(user.auth_token == args.userauthtoken).all()) <= 0: return_object['error'] = True return_object['errorMessage'] = 'Who are you, bitch?' return return_object # Get object from DB and serialize them user_books_serialized = [ serialize_model(label) for label in db.session.query(book).filter(book.is_private == False).all() ] return_object['error'] = False return_object['books'] = json.dumps(user_books_serialized) return return_object
def get(self): # Local variables return_object = {} # Get parameters parser = reqparse.RequestParser() parser.add_argument('userid', type=str) parser.add_argument('userauthtoken', type=str) args = parser.parse_args() # Check if parameters are present if (args.userid is None) or (args.userauthtoken is None): return_object['error'] = True return_object['errorMessage'] = 'Parameters not found.' return return_object # Check if userid matches authtoken in DB if len(db.session.query(user).filter(user.id == args.userid).filter(user.auth_token == args.userauthtoken).all()) <= 0: return_object['error'] = True return_object['errorMessage'] = 'Who are you, bitch?' return return_object # Get object from DB and serialize them user_projects_serialized = [ serialize_model(label) for label in db.session.query(project).filter(project.owner_id == args.userid).all() ] return_object['error'] = False return_object['projects'] = json.dumps(user_projects_serialized) return return_object
def get(self): # Function to check if a string si a number def RepresentsInt(s): try: int(s) return True except ValueError: return False # Local variables return_object = {} # Get parameters parser = reqparse.RequestParser() parser.add_argument("userid", type=str) parser.add_argument("userauthtoken", type=str) parser.add_argument("projectid", type=str) args = parser.parse_args() # Check if parameters are present if (args.userid is None) or (args.userauthtoken is None) or (args.projectid is None): return_object["error"] = True return_object["errorMessage"] = "Parameters not found." return return_object # Check if projectid is a number if RepresentsInt(args.projectid) is False: return_object["error"] = True return_object["errorMessage"] = "Project id is not a number" return return_object # Check if userid matches authtoken in DB if ( len( db.session.query(user) .filter(user.id == args.userid) .filter(user.auth_token == args.userauthtoken) .all() ) <= 0 ): return_object["error"] = True return_object["errorMessage"] = "Who are you, bitch?" return return_object # Check if user owns the project if ( len( db.session.query(project) .filter(project.id == args.projectid) .filter(project.owner_id == args.userid) .all() ) <= 0 ): return_object["error"] = True return_object["errorMessage"] = "Project not found." return return_object # Get object from DB and serialize them project_chapters_serialized = [ serialize_model(label) for label in db.session.query(chapter).filter(chapter.project_id == args.projectid).all() ] print("DONE WITH SERIALIZATION") return_object["error"] = False return_object["chapters"] = json.dumps(project_chapters_serialized) return return_object