示例#1
0
def create_board():
    """Create board"""
    data = request.get_json()
    if data:
        user = User.objects(email=get_jwt_identity()).get()
        board = Board(title=data['title'], user=user)
        board.save()
        board_schema = BoardSchema(only=['id', 'title', 'user'])
        board = board_schema.dump(board)
        return response_with(response_code.SUCCESS_201, value={'board': board})
    else:
        return response_with(response_code.BAD_REQUEST_400,
                             message='Could not get JSON or JSON empty')
示例#2
0
def get_all_boards():
    """Get all user's boards"""
    user = User.objects(email=get_jwt_identity()).get()
    boards = Board.objects(user=user).all()
    board_schema = BoardSchema(many=True, only=['id', 'title', 'lists'])
    boards = board_schema.dump(boards)
    return response_with(response_code.SUCCESS_200, value={'boards': boards})
示例#3
0
def delete_board(board_id):
    """
    Delete user
    :param board_id: The ID of board
    """
    board = Board.objects(id=board_id).get()
    board.delete()
    return response_with(response_code.SUCCESS_201)
示例#4
0
def update_board(board_id):
    data = request.get_json()
    if data:
        board = Board.objects(id=board_id).get()
        if data.get('title'):
            if data.get('title'):
                board.update(title=data['title'])
            board = Board.objects(id=board_id).get()
            board_schema = BoardSchema(only=['id', 'title', 'user'])
            board = board_schema.dump(board)
            return response_with(response_code.SUCCESS_201,
                                 value={'board': board})
        else:
            return response_with(response_code.MISSING_PARAMETERS_422,
                                 message='Check you JSON request')
    else:
        return response_with(response_code.BAD_REQUEST_400,
                             message='Could not get JSON or JSON empty')
示例#5
0
def get_board_by_id(board_id):
    """
    Get board by ID
    :param board_id: The ID of board
    """
    board = Board.objects(id=board_id).get()
    board_schema = BoardSchema(only=['id', 'title', 'lists'])
    board = board_schema.dump(board)
    return response_with(response_code.SUCCESS_200, value={'boards': board})
示例#6
0
 def get(self):
     """Getting user's profile"""
     user_email = get_jwt_identity()
     user = User.objects(email=user_email).get()
     boards = Board.objects(user=user).all()
     user_schema = UserSchema(exclude=['password'])
     user = user_schema.dump(user)
     board_schema = BoardSchema(many=True, exclude=['user', 'lists'])
     boards = board_schema.dump(boards)
     user['boards'] = boards
     return response_with(response_code.SUCCESS_200, value={'user': user})
示例#7
0
def get_user_by_id(user_id):
    """
    Getting user's info by ID

    :param user_id: User's ID
    """
    user = User.objects(id=user_id).get()
    boards = Board.objects(user=user).all()
    user_schema = UserSchema(exclude=['password'])
    user = user_schema.dump(user)
    board_schema = BoardSchema(many=True, only=['id', 'title'])
    boards = board_schema.dump(boards)
    user['boards'] = boards
    return response_with(response_code.SUCCESS_200, value={'user': user})
示例#8
0
def create_list():
    """
    Create list of board
    """
    data = request.get_json()
    if data:
        new_list = List(title=data['title'])
        new_list.save()
        board = Board.objects(id=data['id_board']).get()
        board.lists.append(new_list)
        board.save()
        list_schema = ListSchema()
        new_list = list_schema.dump(new_list)
        return response_with(response_code.SUCCESS_201, value={'list': new_list})
    else:
        return response_with(response_code.BAD_REQUEST_400, message='Could not get JSON or JSON empty')