* move presenters back to controllers, this is view-logic * use PostService in CommentService * remove iframe route, this is not used anymore * id/guid limit at 16 chars, hex(8) is 16 chars long
32 lines
566 B
Ruby
32 lines
566 B
Ruby
class CommentService
|
|
def initialize(user=nil)
|
|
@user = user
|
|
end
|
|
|
|
def create(post_id, text)
|
|
post = post_service.find(post_id)
|
|
user.comment!(post, text)
|
|
end
|
|
|
|
def destroy(comment_id)
|
|
comment = Comment.find(comment_id)
|
|
if user.owns?(comment) || user.owns?(comment.parent)
|
|
user.retract(comment)
|
|
true
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def find_for_post(post_id)
|
|
post_service.find(post_id).comments.for_a_stream
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :user
|
|
|
|
def post_service
|
|
@post_service ||= PostService.new(user)
|
|
end
|
|
end
|