Пример #1
0
    def delete(self, post_id):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')
        post.unfavorite(current_user)

        return post
Пример #2
0
    def get(self, post_id):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')
        comments = post.comments. \
            order_by(Comment.created_at.desc())

        return comments
Пример #3
0
    def post(self, post_id, data):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')
        comment = Comment(post_id=post.id, author_id=current_user.id, **data)
        comment.save()

        return comment
Пример #4
0
    def delete(self, post_id):
        user = current_user
        post = Post.get_one(post_id)

        if not post:
            raise InvalidUsage(404, 'Post not found')
        if post.owner_id != user.id:
            raise InvalidUsage(403, 'Permission denied')

        post.delete()
        return {'deleted': post.id}
Пример #5
0
    def delete(self, post_id, comment_id):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')
        comment = post.comments.filter_by(id=comment_id).first()
        if not comment:
            raise InvalidUsage(404, 'Comment not found')
        if comment.author_id != current_user.id:
            raise InvalidUsage(403, 'Permission denied')
        comment.delete()

        return {'deleted': comment.id}
Пример #6
0
    def put(self, post_id, comment_id, data):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')
        comment = post.comments.filter_by(id=comment_id).first()
        if not comment:
            raise InvalidUsage(404, 'Comment not found')
        if comment.author_id != current_user.id:
            raise InvalidUsage(403, 'Permission denied')
        comment.update(**data)

        return comment
Пример #7
0
    def put(self, post_id, data):
        user = current_user
        post = Post.get_one(post_id)

        if not post:
            raise InvalidUsage(404, 'Post not found')
        if user.id != post.owner_id:
            raise InvalidUsage(403, 'Permission denied')

        post.update(**data)

        return post
Пример #8
0
    def get(self, post_id):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')

        return post