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