def get(self, mode, days): auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return {"message": "This method requires an authorization header."}, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 if safe_str_cmp(mode, "now"): error_message, response = ThemeController.get_now() elif safe_str_cmp(mode, "browse"): error_message, response = ThemeController.browse(int(days), client_id) else: return {"message": "Unsupported mode."}, 400 if safe_str_cmp(mode, "browse"): return {"response": response} if error_message: return {"message": error_message}, 500 return {"response": list(map(lambda x: x.json() if x else None, response))}
def post(self): auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 if UserController.not_admin(client_id): return { "message": "Only the priveleged can come here. Get out peasant." }, 400 data = ThemeAdmin.parser.parse_args() error_message = ThemeController.create_theme(data["release_time"], data["theme"], data["theme_inspire"], data["theme_author"]) if error_message: return {"message": error_message}, 400 else: return {"message": "Success!"}, 201
def post(self, mode, key): data = PostList.parser.parse_args() auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 error_message = "Wrong mode or key." if safe_str_cmp(mode, 'id') and safe_str_cmp(key, "please"): error_message, response = PostListController.filter_by_id( data['wanted']) if error_message: return {"message": error_message}, 400 return { "response": list(map(lambda x: x.json() if x else None, response)) }
def get(self, mode, key): auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 error_message = "" if safe_str_cmp(mode, 'theme'): error_message, response = PostListController.filter_by_theme(key) elif safe_str_cmp(mode, 'user'): error_message, response = PostListController.filter_by_writer_id( key) elif safe_str_cmp(mode, 'saved'): error_message, response = PostListController.filter_by_most_saved( key) else: error_message = "Wrong mode. Try theme, user, or saved" if error_message: return {"message": error_message}, 400 return { "response": list(map(lambda x: x.json() if x else None, response)) }
def put(self): #two modes: append or delete #append: #1. increment that post's saved count by one #2. add that post id to the caller user model's saved column #delete: #1. decrement that post's saved count by one #2. delete that post id to the caller user model's saved column auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 data = SavedUpdate.parser.parse_args() mode = data['mode'] postid = data['postid'] if safe_str_cmp(mode, 'append'): # add to user's saved list message = SavedController.append_saved(postid, client_id) if message: return {"message": message}, 500 # increment post's saved count message = SavedController.increment_post_saved(postid) if message: return {"message": message}, 500 elif safe_str_cmp(mode, 'delete'): # delete post from user's saved list message = SavedController.delete_saved(postid, client_id) if message: return {"message": message}, 500 # decrement posts's saved count message = SavedController.decrement_post_saved(postid) if message: return {"message": message}, 500 else: return { "message": "Bad mode. Only append and delete available for this endpoint." }, 400 return {"message": "Success!"}, 200
def get(self, username): """ checks if the request is authorized. Then uses username to give the usermodel in json form. """ auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 error_message, response = UserController.find_by_username(username) if error_message: return {"message": error_message}, 400 else: return {"user": response.json()}
def post(self): data = Post.parser.parse_args() auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return { "message": "This method requires an authorization header." }, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 error_message = PostController.create_post(data['theme'], data['anonymity'], client_id, data['content']) if error_message: return {"message": error_message}, 400 return {"message": "Success!"}, 201
def get(self, year, month, day): auth_header = request.headers.get('Authorization') if auth_header: access_token = auth_header.split(" ")[1] else: return {"message": "This method requires an authorization header."}, 400 error, client_id = auth_by_token(access_token) if error: return {"message": error}, 401 if UserController.not_admin(client_id): return {"message": "Only the priveleged can come here. Get out peasant."}, 401 if safe_str_cmp(day, "all"): error_message, response = ThemeController.get_for_month(year, month) elif day.isdigit(): error_message, response = ThemeController.get_for_day(year, month, int(day)) else: return {"message": "Unsupported mode of get"}, 400 if error_message: return {"message": error_message}, 500 else: return {"response": list(map(lambda x: x.json() if x else "", response))}