예제 #1
0
def boards():
    """
    All the boards
    """
    method = request.method

    if method == 'GET':
        user_id = session.get('user_id')
        if user_id:
            return data_manager.get_boards_data(user_id)
        return data_manager.get_boards_data(user_id)

    if method == 'POST':
        board_details = request.json
        user_id = session['user_id']
        new_board = data_manager.add_new_board(board_details['title'],
                                               board_details['board_private'],
                                               user_id)
        return {
            'status': 200,
            'board_id': new_board['id'],
            'board_private': new_board['board_private'],
            'user_id': user_id
        }

    if method == 'PUT':
        board_data = request.json
        data_manager.update_title('boards', board_data['boardId'],
                                  board_data['title'])
        return {'status': 200}

    board_id = request.json
    data_manager.delete_record('boards', board_id)
    return {'status': 200}
예제 #2
0
def cards():
    """
    All cards that belongs to a board
    param board_id: id of the parent board
    """
    method = request.method

    if method == 'GET':
        board_id = request.args.get('boardId')
        return data_manager.get_cards_data(board_id)

    if method == 'POST':
        new_card_data = request.json
        attributes = data_manager.add_new_card(new_card_data)
        return {'status': 200, 'id': attributes["id"]}

    if method == 'PUT':
        card_data = request.json
        data_manager.update_title('cards', card_data['cardId'],
                                  card_data['title'])
        return {'status': 200}

    card_id = request.json
    data_manager.delete_record('cards', card_id)
    return {'status': 200}
예제 #3
0
def delete_answer(answer_id):
    data_manager.delete_record('comment',
                               clause='WHERE',
                               condition=['answer_id', '=', answer_id])
    data_manager.delete_record('answer',
                               clause='WHERE',
                               condition=['id', '=', answer_id])
    return redirect('/')
예제 #4
0
def delete_comment(id_):
    comment_row = data_manager.select_sql(table='comment',
                                          clause='WHERE',
                                          condition=['id', '=', id_])
    if comment_row[0]['answer_id'] is None:
        redirect_table = 'question'
        redirect_id = comment_row[0]['question_id']
    else:
        redirect_table = 'answer'
        redirect_id = comment_row[0]['answer_id']
    data_manager.delete_record(table='comment',
                               clause='WHERE',
                               condition=['id', '=', id_])
    return redirect(f'/{redirect_table}/{redirect_id}')
예제 #5
0
def delete_question(question_id):
    data_manager.delete_record('comment',
                               clause='WHERE',
                               condition=['question_id', '=', question_id])
    data_manager.delete_record('answer',
                               clause='WHERE',
                               condition=['question_id', '=', question_id])
    data_manager.delete_record('question',
                               clause='WHERE',
                               condition=['id', '=', question_id])
    return redirect('/')
예제 #6
0
def delete_card(card_id: int):
    return data_manager.delete_record(table='cards', clause='WHERE', condition=['id', '=', card_id])
def delete_record(table_name, _id):
    data_manager.delete_record(table_name, _id)
    return "HTTP/1.1 200 OK"