Create code posts

This commit is contained in:
2024-03-04 21:34:12 +11:00
parent 4277bde352
commit 56edde6ab5
13 changed files with 155 additions and 53 deletions

View File

@@ -0,0 +1,35 @@
require "dry/monads"
module Micropub
module Commands
module Posts
class CreateCodePost < Adamantium::Command
include Deps["repos.post_repo",
renderer: "renderers.markdown",
syndicate: "commands.posts.syndicate",
]
include Dry::Monads[:result]
def call(post)
post_params = prepare_params(params: post)
created_post = post_repo.create(post_params)
# syndicate.call(created_post.id, post)
# decorated_post = Decorators::Posts::Decorator.new(created_post)
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

View File

@@ -7,10 +7,12 @@ module Micropub
"validation.posts.bookmark_contract",
"validation.posts.checkin_contract",
"validation.posts.book_contract",
"validation.posts.code_contract",
"commands.posts.create_post",
"commands.posts.create_bookmark",
"commands.posts.create_checkin",
"commands.posts.create_book_post"
"commands.posts.create_book_post",
"commands.posts.create_code_post"
]
def call(entry_type:)
@@ -21,6 +23,8 @@ module Micropub
{command: create_checkin, validation: checkin_contract}
in Entities::BookRequest
{command: create_book_post, validation: book_contract}
in Entities::CodeRequest
{command: create_code_post, validation: code_contract}
else
{command: create_post, validation: post_contract}
end