From 680f9c0c4dc70a05d67bd52b6555aa6748917148 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Wed, 3 Dec 2025 08:12:04 -0500 Subject: [PATCH] Add top-level API index support for tags --- app/controllers/tags_controller.rb | 5 +++++ app/views/tags/_tag.json.jbuilder | 5 +++++ app/views/tags/index.json.jbuilder | 1 + config/routes.rb | 2 ++ test/controllers/api_test.rb | 8 ++++++++ 5 files changed, 21 insertions(+) create mode 100644 app/controllers/tags_controller.rb create mode 100644 app/views/tags/_tag.json.jbuilder create mode 100644 app/views/tags/index.json.jbuilder diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 000000000..2dc468f0d --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,5 @@ +class TagsController < ApplicationController + def index + @tags = Current.account.tags.all.alphabetically + end +end diff --git a/app/views/tags/_tag.json.jbuilder b/app/views/tags/_tag.json.jbuilder new file mode 100644 index 000000000..c8a7ffe40 --- /dev/null +++ b/app/views/tags/_tag.json.jbuilder @@ -0,0 +1,5 @@ +json.cache! tag do + json.(tag, :id, :title) + json.created_at tag.created_at.utc + json.url cards_url(tag_ids: [ tag ]) +end diff --git a/app/views/tags/index.json.jbuilder b/app/views/tags/index.json.jbuilder new file mode 100644 index 000000000..9b85a42e4 --- /dev/null +++ b/app/views/tags/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @tags, partial: 'tags/tag', as: :tag diff --git a/config/routes.rb b/config/routes.rb index bf9c8c3b3..19358cb9d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,6 +94,8 @@ Rails.application.routes.draw do end end + resources :tags, only: :index + namespace :notifications do resource :settings resource :unsubscribe diff --git a/test/controllers/api_test.rb b/test/controllers/api_test.rb index d5bb0514f..994a7ebd6 100644 --- a/test/controllers/api_test.rb +++ b/test/controllers/api_test.rb @@ -48,6 +48,14 @@ class ApiTest < ActionDispatch::IntegrationTest assert_equal "My new card", @response.parsed_body["title"] end + test "get tags" do + tags = users(:david).account.tags.all.alphabetically + + get tags_path(format: :json), env: @davids_bearer_token + assert_equal tags.count, @response.parsed_body.count + assert_equal tags.pluck(:title), @response.parsed_body.pluck("title") + end + test "get users" do get users_path(format: :json), env: @davids_bearer_token assert_equal users(:david).account.users.active.count, @response.parsed_body.count