class FeedGet(Resource): decorators = [ limiter.limit("10/minute", error_message="Too many posts requests (10 per minute).") ] @api.doc("Get Posts IDs", responses={200: "Post IDs successfully sent to client."}) @jwt_required def get(self): """ Return posts IDs from the Database. """ return Feed.get_activity() decorators = [ limiter.limit("25/minute", error_message="Too many posts requests (25 per minute).") ] @api.expect(_feed, validate=True) @api.doc( "Get the posts data", responses={200: "Post data successfully sent to the client."}, ) @jwt_required def post(self): """ Get the posts data from the Database. """ # Get the id array data = request.get_json() id_array = data["post_ids"] # Get the current user current_user = load_user(get_jwt_identity()) return Feed.get_posts_info(id_array, current_user)
class AuthRegister(Resource): """ User registration endpoint User registers then receives the user's information and access_token """ decorators = [ limiter.limit( "5/day", error_message="You may only use registry route 5 times a day.") ] @api.doc("Auth registration endpoint") @api.expect(auth_register, validate=True) def post(self): """ Register to Konishi """ # Grab the json data register_data = request.get_json() return Auth.register(register_data)
class AuthLogin(Resource): """ User login endpoint User logins then receives an access token. """ decorators = [ limiter.limit( "5/minute", error_message="You have exceeded max login attempts (5/minute).") ] @api.doc("Auth login endpoint") @api.expect(auth_login, validate=True) def post(self): """ Login using email and password """ # Grab the json data login_data = request.get_json() return Auth.login_user(login_data)
class PostCreate(Resource): decorators = [ limiter.limit("5/minute", error_message="5 posts per minute exceeded.") ] @api.expect(_post, validate=True) @api.doc( "Create a new post.", responses={ 201: "Post created", 401: "Something went wrong during the process" }, ) @jwt_required def post(self): """ Creates new post """ data = request.get_json() current_user = load_user(get_jwt_identity()) return PostService.create(data, current_user)