Add auto tagger for posts

This commit is contained in:
2023-05-06 19:58:59 +10:00
parent c4bd903e74
commit 9f8359d782
25 changed files with 424 additions and 2 deletions

View 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

View 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