feat: D & D による上位タグ設定(#184) (#186)
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: #186
This commit was merged in pull request #186.
This commit is contained in:
@@ -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
|
||||
@@ -39,6 +39,17 @@ class TagsController < ApplicationController
|
||||
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
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :nico_tags, path: 'tags/nico', only: [:index, :update]
|
||||
|
||||
scope 'tags/:parent_id/children', controller: :tag_children do
|
||||
post ':child_id', action: :create
|
||||
delete ':child_id', action: :destroy
|
||||
end
|
||||
|
||||
resources :tags do
|
||||
collection do
|
||||
get :autocomplete
|
||||
|
||||
Reference in New Issue
Block a user