def get_book_by_id(book_id):
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    response = models.books.get_book_by_id(get_user_id_by_token(token), book_id)
    return response.response_message, response.response_code
def list_all_category():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    response = models.category.list_all_category(get_user_id_by_token(token))
    return response.response_message, response.response_code
def list_all_category():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    response = models.category.list_all_category(get_user_id_by_token(token))
    return response.response_message, response.response_code
def add_book():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'bookname' not in jsondata:
        return makeResponse(JSONResponseProvideAtLeastBookName)

    bookname = ""
    author = ""
    publisher = ""
    publish_date = ""
    price = 0
    ISBN = ""
    tags = []
    cover_image_url = ""
    category_id = []

    if 'bookname' in jsondata:
        bookname = jsondata['bookname']
    if 'author' in jsondata:
        author = jsondata['author']
    if 'publisher' in jsondata:
        publisher = jsondata['publisher']
    if 'publish_date' in jsondata:
        publish_date = jsondata['publish_date']
    if 'price' in jsondata:
        price = jsondata['price']
    if 'ISBN' in jsondata:
        ISBN = jsondata['ISBN']
    if 'tags' in jsondata:
        tags = jsondata['tags']
    if 'cover_image_url' in jsondata:
        cover_image_url = jsondata['cover_image_url']
    if 'category_id' in jsondata:
        category_id = jsondata['category_id']

    if not isfloat(price):
        return makeResponse(JSONResponsePriceNotNumber)

    user_id = get_user_id_by_token(request.headers.get('Token'))

    response = models.books.add_book(user_id, bookname, author, publisher, publish_date, price, ISBN, tags, cover_image_url, category_id)
    return response.response_message, response.response_code
def add_books_to_category(category_id):
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'books' not in jsondata:
        return makeResponse(JSONResponseProvideNecessaryInfo)

    user_id = get_user_id_by_token(request.headers.get('Token'))
    books = jsondata['books']
    response = models.category.add_books_to_category(user_id, category_id, books)
    return response.response_message, response.response_code
def update_category(category_id):
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'category_name' not in jsondata:
        makeResponse(JSONResponseProvideNecessaryInfo)
    category_name = jsondata['category_name']

    user_id = get_user_id_by_token(request.headers.get('Token'))

    response = models.category.update_category(user_id, category_id, category_name)
    return response.response_message, response.response_code
def del_category():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    ErrorResponse = checkUserErrorByToken(token)
    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)

    user_id = get_user_id_by_token(request.headers.get('Token'))
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'category_id' not in jsondata:
        return makeResponse(JSONResponseProvideNecessaryInfo)
    category_id = jsondata['category_id']

    response = models.category.del_category(user_id, category_id)
    return response.response_message, response.response_code
def add_user():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)

    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'username' not in jsondata or 'password' not in jsondata or 'email' not in jsondata:
        return makeResponse(JSONResponseProvideNecessaryInfo)
    username = jsondata['username']
    password = jsondata['password']
    email = jsondata['email']
    head_image_url = ""
    if 'head_image_url' in jsondata:
        head_image_url = jsondata['head_image_url']
    response = models.users.add_user(username, password, email, head_image_url, token)
    return response.response_message, response.response_code
def add_user():
    token = request.headers.get('Token')
    ErrorResponse = isErrorToken(token)

    if ErrorResponse is not None:
        return makeResponse(ErrorResponse)
    jsondata = request.get_json()
    if not jsondata:
        return makeResponse(JSONResponseInvalidJSON)
    if 'username' not in jsondata or 'password' not in jsondata or 'email' not in jsondata:
        return makeResponse(JSONResponseProvideNecessaryInfo)
    username = jsondata['username']
    password = jsondata['password']
    email = jsondata['email']
    head_image_url = ""
    if 'head_image_url' in jsondata:
        head_image_url = jsondata['head_image_url']
    response = models.users.add_user(username, password, email, head_image_url,
                                     token)
    return response.response_message, response.response_code