Add tags in edit endpoint
This commit is contained in:
@@ -13,7 +13,7 @@ module Adamantium
|
|||||||
end
|
end
|
||||||
|
|
||||||
if params.key? :add
|
if params.key? :add
|
||||||
|
post_repo.tag_post(post.id, params[:add][:category])
|
||||||
end
|
end
|
||||||
|
|
||||||
if params.key? :delete
|
if params.key? :delete
|
||||||
|
@@ -27,6 +27,24 @@ module Adamantium
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_post(post_id:, tags:)
|
||||||
|
tags.each do |tag_name|
|
||||||
|
next if tag_name == ""
|
||||||
|
|
||||||
|
tag = post.tags.where(label: tag_name).one ||
|
||||||
|
post
|
||||||
|
.tags
|
||||||
|
.changeset(:create, {label: tag_name, slug: tag_name.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "")})
|
||||||
|
.commit
|
||||||
|
|
||||||
|
posts.post_tags.changeset(:create, {
|
||||||
|
post_id: post_id,
|
||||||
|
tag_id: tag[:id]
|
||||||
|
})
|
||||||
|
.commit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def post_listing(limit: nil)
|
def post_listing(limit: nil)
|
||||||
posts
|
posts
|
||||||
.where(post_type: "post")
|
.where(post_type: "post")
|
||||||
|
Reference in New Issue
Block a user