【再掲】feat: D & D による上位タグ設定(#184) (#211)

#184 修正

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge remote-tracking branch 'origin/main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

Merge remote-tracking branch 'origin/main' into feature/184

Merge branch 'main' into feature/184

Merge remote-tracking branch 'origin/main' into feature/184

Merge remote-tracking branch 'origin/main' into feature/184

Merge branch 'main' into feature/184

Merge branch 'main' into feature/184

#184

#184

#184

#184

#184

#184

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #211
This commit was merged in pull request #211.
This commit is contained in:
2026-01-18 00:52:21 +09:00
parent dd838fdf80
commit 16ecbd1fc9
7 changed files with 536 additions and 69 deletions
@@ -0,0 +1,27 @@
class TagChildrenController < ApplicationController
def create
return head :unauthorized unless current_user
return head :forbidden unless current_user.admin?
parent_id = params[:parent_id]
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children << Tag.find(child_id) rescue nil
head :no_content
end
def destroy
return head :unauthorized unless current_user
return head :forbidden unless current_user.admin?
parent_id = params[:parent_id]
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children.delete(Tag.find(child_id)) rescue nil
head :no_content
end
end
@@ -44,4 +44,18 @@ class TagsController < ApplicationController
head :not_found
end
end
def update
return head :unauthorized unless current_user
return head :forbidden unless current_user.member?
tag = Tag.find(params[:id])
attrs = { name: params[:name].presence,
category: params[:category].presence }.compact
tag.update!(attrs) if attrs.present?
render json: tag
end
end
+6 -1
View File
@@ -1,7 +1,12 @@
Rails.application.routes.draw do
resources :nico_tags, path: 'tags/nico', only: [:index, :update]
resources :tags, only: [:index, :show] do
scope 'tags/:parent_id/children', controller: :tag_children do
post ':child_id', action: :create
delete ':child_id', action: :destroy
end
resources :tags, only: [:index, :show, :update] do
collection do
get :autocomplete
get 'name/:name', action: :show_by_name