Last active
May 8, 2019 20:39
-
-
Save cutalion/4b2860f3ab0f03d9ce92c09efb6ee7ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Пусть админы могут удалять комментарии | |
# и мы уведомляем кого-нибудь, что комментарий был удален | |
class DeleteComment | |
def call(comment) | |
transaction do | |
comment.delete! | |
user.decrement(:comments_count) | |
end | |
send_push 'Comment deleted' | |
send_email 'Comment deleted' | |
end | |
end | |
# Потом у нас появляется бан пользователей | |
# и нам надо удалить все их комментарии | |
# (опустим, что юзер получит сразу пачку уведомлений) | |
class BanUser | |
def call(user) | |
transaction do | |
user.ban! | |
user.comments.each do |comment| | |
DeleteComment.new.call(comment) | |
end | |
end | |
send_email 'Banned!' | |
end | |
end | |
# api | |
# DeleteComment может вызываться, как напрямую, так и опосредованно | |
delete '/comments/:id' do | |
comment = find_comment(params[:id]) | |
DeleteComment.new.call(comment) | |
end | |
post '/users/:id/ban' do | |
user = find_user(params[:id]) | |
BanUser.new.call(user) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment