Add checkins
This commit is contained in:
40
app/commands/posts/create_checkin.rb
Normal file
40
app/commands/posts/create_checkin.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require "dry/monads"
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Posts
|
||||
class CreateCheckin < Command
|
||||
include Deps["repos.post_repo",
|
||||
"post_utilities.slugify",
|
||||
renderer: "renderers.markdown",
|
||||
add_post_syndication_source: "commands.posts.add_syndication_source"
|
||||
]
|
||||
|
||||
include Dry::Monads[:result]
|
||||
|
||||
def call(post)
|
||||
post_params = prepare_params(params: post)
|
||||
created_post = post_repo.create(post_params)
|
||||
|
||||
post_params[:syndication_sources].each do |url|
|
||||
add_post_syndication_source.call(created_post.id, :swarm, url)
|
||||
end
|
||||
|
||||
# decorated_post = Decorators::Posts::Decorator.new(created_post)
|
||||
|
||||
# send_webmentions.call(post_content: attrs[:content], post_url: decorated_post.permalink)
|
||||
|
||||
Success(created_post)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_params(params:)
|
||||
attrs = params.to_h
|
||||
attrs[:content] = renderer.call(content: attrs[:content])
|
||||
attrs
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -5,14 +5,18 @@ module Adamantium
|
||||
include Deps[
|
||||
"validation.posts.post_contract",
|
||||
"validation.posts.bookmark_contract",
|
||||
"validation.posts.checkin_contract",
|
||||
"commands.posts.create_entry",
|
||||
"commands.posts.create_bookmark"
|
||||
"commands.posts.create_bookmark",
|
||||
"commands.posts.create_checkin"
|
||||
]
|
||||
|
||||
def call(entry_type:)
|
||||
case entry_type
|
||||
in Entities::BookmarkRequest
|
||||
{command: create_bookmark, validation: bookmark_contract}
|
||||
in Entities::CheckinRequest
|
||||
{command: create_checkin, validation: checkin_contract}
|
||||
else
|
||||
{command: create_entry, validation: post_contract}
|
||||
end
|
||||
|
Reference in New Issue
Block a user