def delete(self, movie_id=None): logger.info("Received Movie Delete request from : {}".format( session.get("user_id"))) if not movie_id: return error_response(400, "Bad Request") remove_movie(movie_id) return ok_response({}, message="Movie Deleted Successfully")
def post(self): try: get_session_user() except: return error_response(400, "logout called for an invalid session") logout_user() return ok_response({},message="logout successfully")
def post(self): request_data = request.get_json(force=True) logger.info("Received login request") if not validate_login_request(request_data): return error_response(400, "Bad Request") response = validate_user(request_data) if response: return ok_response(response) else: return error_response( 403, "The username or password you entered is incorrect")
def put(self): logger.info("Received Movie Put request from : {}".format( session.get("user_id"))) request_body = request.get_json(force=True) if not validate_movie_put_request(request_body): return error_response(400, "Bad Request") if not update_movie_data(request_body): return error_response(500, message="Internal Server Error") return ok_response({}, message="Movie Updated Successfully")
def get(self, movie_id=None): logger.info("Received Movie Get request from : {}".format( session.get("user_id"))) if movie_id: response = get_movie_json_by_id(movie_id) return ok_response(response) try: params = request.args.to_dict() limit = int(params.get('limit', 20)) offset = int(params.get('offset', 0)) if params.get('genre'): response = get_movies_by_genre(params['genre'], limit, offset) return ok_response(response) elif params.get('search_term'): response = get_movies_by_search_term(params['search_term'], limit, offset) return ok_response(response) else: return error_response(400, "Bad Request") except: return error_response(500, "Internal Server Error")
def post(self): logger.info("Received User Post request from : {}".format( session.get("user_id"))) request_body = request.get_json(force=True) if not validate_user_post_request(request_body): return error_response(400, "Bad Request") if user_exist_with_username(request_body['username']): return error_response(409, message="User Alreay Exist with username") if user_exist_with_email(request_body['email']): return error_response(409, message="User Alreay Exist with email") if not create_user(request_body): return error_response(500, message="Internal Server Error") return ok_response({}, message="User Created Successfully")
def get(self): logger.info("Received Ping request") return ok_response({})