Add auto tagger for posts
This commit is contained in:
20
slices/admin/commands/auto_tagging/create.rb
Normal file
20
slices/admin/commands/auto_tagging/create.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module Admin
|
||||
module Commands
|
||||
module AutoTagging
|
||||
class Create
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.auto_tagging_repo"]
|
||||
|
||||
def call(title_contains:, body_contains:, tag_id:)
|
||||
Failure() if !title_contains.empty? && !body_contains.empty?
|
||||
|
||||
result = auto_tagging_repo.create(title_contains: title_contains,
|
||||
body_contains: body_contains,
|
||||
tag_id: tag_id)
|
||||
|
||||
Success(result.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
slices/admin/commands/auto_tagging/tag.rb
Normal file
31
slices/admin/commands/auto_tagging/tag.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
module Admin
|
||||
module Commands
|
||||
module AutoTagging
|
||||
class Tag
|
||||
include Dry::Monads[:result]
|
||||
include Deps["repos.post_repo", "repos.auto_tagging_repo"]
|
||||
|
||||
def call(auto_tag_id: nil)
|
||||
auto_taggings = if auto_tag_id
|
||||
auto_tagging_repo.find(auto_tag_id)
|
||||
else
|
||||
auto_tagging_repo.all
|
||||
end
|
||||
|
||||
auto_taggings.each do |auto_tagging|
|
||||
posts = auto_tagging.title_only? ?
|
||||
post_repo.by_title(title_contains: auto_tagging.title_contains) :
|
||||
post_repo.by_content(body_contains: auto_tagging.body_contains)
|
||||
|
||||
posts.each do |post|
|
||||
post_repo.tag_post(post_id: post.id,
|
||||
tag_id: auto_tagging.tag_id)
|
||||
end
|
||||
end
|
||||
|
||||
Success()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user