Пример #1
0
    def put(self, board_id):
        try:
            form = BoardEditNameSchema().load(json.loads(request.data))

            if Board.objects(name=form['name']).first():
                return jsonify(message='이미 존재하는 게시판 이름입니다.'), 409

            find_board = Board.objects(id=board_id).first()
            find_board.update(**form)
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판 이름이 변경되었습니다.'), 200
Пример #2
0
    def delete(self, board_id):
        try:
            find_board = Board.objects(id=board_id).first()
            find_board.soft_delete()
        except ValidationError as err:
            return err

        return jsonify(message='게시판이 삭제되었습니다.'), 200
Пример #3
0
    def get(self, board_id, post_id):
        board = Board.objects(id=board_id, deleted=False).get_or_404()
        find_post = Post.objects(board=board_id, id=post_id, deleted=False).get_or_404()
        find_post.increase_view_count()

        post_detail = PostSchema().dump(find_post)

        return jsonify(post_detail), 200
Пример #4
0
    def post(self):
        try:
            form = BoardCreateSchema().load(json.loads(request.data))

            if Board.objects(name=form['name']).first():
                return jsonify(message='이미 존재하는 게시판 이름입니다.'), 409

            form.save()
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판이 생성되었습니다.'), 200
Пример #5
0
    def post(self, board_id):
        try:
            if not Board.objects(id=board_id, deleted=False).first():
                return jsonify(message="존재하지 않는 게시판입니다"), 404

            form = PostCreateSchema().load(json.loads(request.data))
            form.board = ObjectId(board_id)
            form.writer = ObjectId(g.member_id)

            form.save()
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시글이 작성되었습니다.'), 200
Пример #6
0
    def put(self, board_id, post_id):
        try:
            if not Board.objects(id=board_id, deleted=False).first():
                return jsonify(message="존재하지 않는 게시판입니다"), 404

            form = PostEditSchema().load(json.loads(request.data))

            find_post = Post.objects(id=post_id).first()
            find_post.update_post_modified_time()
            post = Post(**form)
            find_post.update(post)
        except ValidationError as err:
            return jsonify(err.messages), 422

        return jsonify(message='게시판 이름이 변경되었습니다.'), 200
Пример #7
0
 def get(self, board_id):
     find_board = Board.objects(id=board_id).first()
     board_detail = BoardSchema().dump(find_board)
     return jsonify(board_detail), 200
Пример #8
0
 def index(self):
     find_boards = Board.objects(deleted=False).order_by('name').paginate(
         1, 10)
     boards = SimpleBoardSchema().dump(find_boards, many=True)
     return jsonify(boards), 200
Пример #9
0
    def index(self, board_id, page=1):
        board = Board.objects(id=board_id, deleted=False).get_or_404()
        find_posts = Post.objects(board=board_id, deleted=False).paginate(page=page, per_page=10)
        posts = PaginatedPostSchema().dump(find_posts)

        return jsonify(posts), 200
Пример #10
0
 def test_name이_변경된다(self, subject, target_board_id, form):
     board = Board.objects(id=target_board_id).get()
     assert board.name == form['name']
Пример #11
0
 def test_db에_저장된다(self, subject, form):
     board = Board.objects(name=form['name']).get()
     assert board.name == form['name']