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})
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)
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')
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})
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})
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})
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')