From a0f1d0c4c33c57bacd51da22343c3da5251a6f7c Mon Sep 17 00:00:00 2001 From: miteruzo Date: Thu, 24 Sep 2026 12:48:29 +0900 Subject: [PATCH] #419 --- .../app/controllers/nico_tags_controller.rb | 6 +++++ backend/config/routes.rb | 2 +- backend/spec/requests/nico_tags_spec.rb | 26 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backend/app/controllers/nico_tags_controller.rb b/backend/app/controllers/nico_tags_controller.rb index ea02a12..6f97dbc 100644 --- a/backend/app/controllers/nico_tags_controller.rb +++ b/backend/app/controllers/nico_tags_controller.rb @@ -71,6 +71,12 @@ class NicoTagsController < ApplicationController }, count: } end + def show + tag = ExternalTag.find(params[:id]) + + render json: external_tag_json(tag) + end + def update return head :unauthorized unless current_user return head :forbidden unless current_user.gte_member? diff --git a/backend/config/routes.rb b/backend/config/routes.rb index 00fc425..0f721d1 100644 --- a/backend/config/routes.rb +++ b/backend/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - resources :nico_tags, path: 'tags/nico', only: [:index, :update] + resources :nico_tags, path: 'tags/nico', only: [:index, :show, :update] scope 'tags/:parent_id/children', controller: :tag_children do post ':child_id', action: :create diff --git a/backend/spec/requests/nico_tags_spec.rb b/backend/spec/requests/nico_tags_spec.rb index b1572dd..243cbd3 100644 --- a/backend/spec/requests/nico_tags_spec.rb +++ b/backend/spec/requests/nico_tags_spec.rb @@ -106,6 +106,32 @@ RSpec.describe 'NicoTags', type: :request do end end + describe 'GET /tags/nico/:id' do + it 'returns the external tag even when an internal tag has the same id' do + internal = create(:tag) + external = create( + :external_tag, + id: internal.id, + name: 'external_detail') + + get "/tags/nico/#{ external.id }" + + expect(response).to have_http_status(:ok) + expect(json).to include( + 'id' => external.id, + 'name' => 'nico:external_detail', + 'category' => 'nico') + end + + it 'returns 404 when the external tag does not exist' do + internal = create(:tag) + + get "/tags/nico/#{ internal.id }" + + expect(response).to have_http_status(:not_found) + end + end + describe 'PATCH /tags/nico/:id' do let(:member) { create(:user, :member) } let(:admin) { create(:user, :admin) }