Exemplo n.º 1
0
def submit_review():
    if request.method == "POST":
        data = json.loads(request.data)

        if is_valid_data(
                data,
            ['reviewId', 'bookId', 'revTitle', 'content', 'score', 'language'
             ]):
            review_id = data['reviewId']
            book_id = data['bookId']
            review_title = data['revTitle']
            content = data['content']
            score = data['score']
            language = data['language']

            user_id = current_user.id

            # If admin
            if database_helper.is_admin(user_id):
                if database_helper.is_own_review(user_id, review_id):
                    if database_helper.has_reviewed(user_id, book_id):
                        database_helper.update_review(user_id, review_id,
                                                      book_id, review_title,
                                                      content, score, language)
                    else:
                        database_helper.submit_review(book_id, review_title,
                                                      content, score, language,
                                                      user_id)
                else:
                    user_id = database_helper.get_review_writer(review_id)
                    database_helper.update_review(user_id, review_id, book_id,
                                                  review_title, content, score,
                                                  language)

            # If not admin
            else:
                if not database_helper.has_reviewed(user_id, book_id):
                    database_helper.submit_review(book_id, review_title,
                                                  content, score, language,
                                                  user_id)
                else:
                    if database_helper.is_own_review(user_id, review_id):
                        database_helper.update_review(user_id, review_id,
                                                      book_id, review_title,
                                                      content, score, language)
                    else:
                        abort(401)
            return json.dumps({'bookId': book_id})
        else:
            abort(400)
Exemplo n.º 2
0
def submit_review():
    if request.method == "POST":
        data = json.loads(request.data)

        if is_valid_data(data, ['reviewId', 'bookId', 'revTitle', 'content', 'score', 'language']):
            review_id = data['reviewId']
            book_id = data['bookId']
            review_title = data['revTitle']
            content = data['content']
            score = data['score']
            language = data['language']

            user_id = current_user.id

            # If admin
            if database_helper.is_admin(user_id):
                if database_helper.is_own_review(user_id, review_id):
                    if database_helper.has_reviewed(user_id, book_id):
                        database_helper.update_review(user_id, review_id, book_id, review_title, content, score, language)
                    else:
                        database_helper.submit_review(book_id, review_title, content, score, language, user_id)
                else:
                    user_id = database_helper.get_review_writer(review_id)
                    database_helper.update_review(user_id, review_id, book_id, review_title, content, score, language)

            # If not admin
            else:
                if not database_helper.has_reviewed(user_id, book_id):
                    database_helper.submit_review(book_id, review_title, content, score, language, user_id)
                else:
                    if database_helper.is_own_review(user_id, review_id):
                        database_helper.update_review(user_id, review_id, book_id, review_title, content, score, language)
                    else:
                        abort(401)
            return json.dumps({'bookId': book_id})
        else:
            abort(400)
Exemplo n.º 3
0
def get_title_data():
    if request.method == "GET":
        id = request.args.get('id')
        data = database_helper.get_title_data(id)
        if data is None:
            abort(404)

        has_reviewed = True
        user_id = None
        if current_user.is_authenticated():
            user_id = current_user.id
            has_reviewed = database_helper.has_reviewed(user_id, id)
        data['hasReviewed'] = has_reviewed
        data['user'] = user_id
        return json.dumps({'data': data})
Exemplo n.º 4
0
def get_title_data():
    if request.method == "GET":
        id = request.args.get('id')
        data = database_helper.get_title_data(id)
        if data is None:
            abort(404)

        has_reviewed = True
        user_id = None
        if current_user.is_authenticated():
            user_id = current_user.id
            has_reviewed = database_helper.has_reviewed(user_id, id)
        data['hasReviewed'] = has_reviewed
        data['user'] = user_id
        return json.dumps({'data': data})