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,33 @@
module Admin
module Repos
class AutoTaggingRepo < Adamantium::Repo[:auto_taggings]
commands :create
def find(id)
auto_taggings
.where(id: id)
.map_to(Admin::Entities::AutoTagging)
.to_a
end
def all
auto_taggings
.map_to(Admin::Entities::AutoTagging)
.to_a
end
def listing
auto_taggings
.combine(:tag)
.map_to(Admin::Entities::AutoTagging::WithTag)
.to_a
end
def delete(id:)
auto_taggings
.where(id: id)
.delete
end
end
end
end

View File

@@ -0,0 +1,37 @@
module Admin
module Repos
class PostRepo < Adamantium::Repo[:posts]
def tag_post(post_id:, tag_id:)
return if posts
.post_tags
.where(
post_id: post_id,
tag_id: tag_id
).count > 0
posts
.post_tags
.changeset(:create, {
post_id: post_id,
tag_id: tag_id
})
.commit
end
def by_title(title_contains:)
posts
.where(post_type: "post")
.published
.where(Sequel.ilike(:name, "%#{title_contains}%")).to_a
end
def by_content(body_contains:)
posts
.where(post_type: "post")
.published
.where(Sequel.ilike(:content, "%#{body_contains}%")).to_a
end
end
end
end

View File

@@ -5,7 +5,6 @@ module Admin
def delete(tag_id:)
post_tags.where(tag_id: tag_id).delete
end
end
end
end

View File

@@ -2,6 +2,11 @@ module Admin
module Repos
class TagRepo < Adamantium::Repo[:tags]
def list
tags
.order(Sequel.function(:lower, :label))
.to_a
end
def list_with_posts
tags
.combine(:posts)
.order(Sequel.function(:lower, :label))