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
