This commit is contained in:
2026-04-19 17:47:22 +09:00
parent f3a2b08359
commit 96307af509
12 changed files with 63 additions and 47 deletions
@@ -38,7 +38,7 @@ class NicoTagsController < ApplicationController
return head :bad_request if linked_tags.any? { |t| t.nico? }
ApplicationRecord.transaction do
record_tag_snapshots!(linked_tags, created_by_user: current_user)
TagVersioning.record_tag_snapshots!(linked_tags, created_by_user: current_user)
tag.linked_tags = linked_tags
tag.save!
@@ -48,13 +48,4 @@ class NicoTagsController < ApplicationController
render json: tag.linked_tags.map { |t| TagRepr.base(t) }, status: :ok
end
private
def record_tag_snapshots! tags, created_by_user:
tags.each do |tag|
event_type = tag.tag_versions.exists? ? :update : :create
TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
end
end
end
+4 -4
View File
@@ -131,7 +131,7 @@ class PostsController < ApplicationController
ApplicationRecord.transaction do
post.save!
tags = Tag.normalise_tags(tag_names)
record_tag_snapshots!(tags, created_by_user: current_user)
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user)
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
@@ -175,10 +175,10 @@ class PostsController < ApplicationController
ApplicationRecord.transaction do
post.update!(title:, original_created_from:, original_created_before:)
normalised_tag = Tag.normalise_tags(tag_names, with_tagme: false)
record_tag_snapshots(normalised_tags, create_by_user: current_user)
normalised_tags = Tag.normalise_tags(tag_names, with_tagme: false)
TagVersioning.record_tag_snapshots!(normalised_tags, created_by_user: current_user)
tags = post.tags.where(category: 'nico').to_a + normalised_tags
tags = post.tags.nico.to_a + normalised_tags
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
PostVersionRecorder.record!(post:, event_type: :update, created_by_user: current_user)
+5 -12
View File
@@ -218,21 +218,14 @@ class TagsController < ApplicationController
tag = Tag.find(params[:id])
if category.present? && tag.nico? != (category == 'nico')
return render json: { error: 'ニコタグのカテゴリ変更はできません.' },
status: :unprocessable_entity
end
ApplicationRecord.transaction do
old_nico = tag.nico?
if category.present?
new_nico = category == 'nico'
if old_nico != new_nico
return render json: { error: 'ニコタグのカテゴリ変更はできません.' },
status: :unprocessable_entity
end
end
tag.tag_name.update!(name:) if name.present?
tag.update!(category:) if category.present?
record_tag_version!(tag, event_type: :update, created_by_user: current_user)
end