Add auto tagger for posts
This commit is contained in:
37
slices/admin/repos/post_repo.rb
Normal file
37
slices/admin/repos/post_repo.rb
Normal 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
|
Reference in New Issue
Block a user