Refactor post creation + syndication
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
require "dry/monads"
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Posts
|
||||
class CreateBookmark < Command
|
||||
include Deps["repos.post_repo"]
|
||||
include Deps["repos.post_repo", syndicate: "commands.posts.syndicate"]
|
||||
|
||||
include Dry::Monads[:result]
|
||||
|
||||
def call(bookmark)
|
||||
post_repo.create(bookmark)
|
||||
created_bookmark = post_repo.create(bookmark)
|
||||
|
||||
syndicate.call(bookmark).bind do |result|
|
||||
source, url = result
|
||||
add_post_syndication_source.call(created_bookmark.id, source, url)
|
||||
end
|
||||
|
||||
Success(created_bookmark)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,16 +1,29 @@
|
||||
require "dry/monads"
|
||||
|
||||
module Adamantium
|
||||
module Commands
|
||||
module Posts
|
||||
class CreateEntry < Command
|
||||
include Deps["repos.post_repo",
|
||||
"post_utilities.slugify",
|
||||
renderer: "renderers.markdown"
|
||||
renderer: "renderers.markdown",
|
||||
syndicate: "commands.posts.syndicate",
|
||||
]
|
||||
|
||||
include Dry::Monads[:result]
|
||||
|
||||
def call(post)
|
||||
attrs = post.to_h
|
||||
attrs[:content] = renderer.call(content: attrs[:content])
|
||||
|
||||
post_repo.create(attrs)
|
||||
created_post = post_repo.create(attrs)
|
||||
|
||||
syndicate.call(attrs).bind do |result|
|
||||
source, url = result
|
||||
add_post_syndication_source.call(created_post.id, source, url)
|
||||
end
|
||||
|
||||
Success(created_post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -9,7 +9,9 @@ module Adamantium
|
||||
post = post_repo.fetch!(slug)
|
||||
|
||||
if params.key? :replace
|
||||
post_repo.update(post.id, {content: markdown.call(content: params[:replace][:content].first)})
|
||||
post_repo.update(post.id, {
|
||||
content: markdown.call(content: params[:replace][:content].first)
|
||||
})
|
||||
end
|
||||
|
||||
if params.key? :add
|
||||
@@ -17,7 +19,6 @@ module Adamantium
|
||||
end
|
||||
|
||||
if params.key? :delete
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user