Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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}
Ejemplo n.º 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}
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 8
0
    def get(self, post_id):
        post = Post.get_one(post_id)
        if not post:
            raise InvalidUsage(404, 'Post not found')

        return post