Add reactions to posts
This commit is contained in:
23
slices/main/actions/posts/react.rb
Normal file
23
slices/main/actions/posts/react.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require "digest/sha1"
|
||||
|
||||
module Main
|
||||
module Actions
|
||||
module Posts
|
||||
class React < Action
|
||||
|
||||
include Deps["repos.reaction_repo", "repos.post_repo"]
|
||||
|
||||
def handle(req, res)
|
||||
post = post_repo.fetch!(req.params[:slug])
|
||||
|
||||
reaction_repo.create(post_id: post.id, visitor_identifier: Digest::SHA1.hexdigest(req.ip))
|
||||
|
||||
reaction_count = reaction_repo.count(post_id: post.id)
|
||||
|
||||
res.body = "👍 #{reaction_count}"
|
||||
res.status = 201
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user