From 0ec3c44ef5560db89ec59c3e896debd4fe269f1d Mon Sep 17 00:00:00 2001 From: noellabo <noel.yoshiba@gmail.com> Date: Fri, 13 Sep 2019 16:17:08 +0900 Subject: [PATCH] Added account featured tags API --- .../v1/accounts/featured_tags_controller.rb | 22 +++++++++++++++++++ .../rest/account_featured_tag_serializer.rb | 19 ++++++++++++++++ config/routes.rb | 1 + 3 files changed, 42 insertions(+) create mode 100644 app/controllers/api/v1/accounts/featured_tags_controller.rb create mode 100644 app/serializers/rest/account_featured_tag_serializer.rb diff --git a/app/controllers/api/v1/accounts/featured_tags_controller.rb b/app/controllers/api/v1/accounts/featured_tags_controller.rb new file mode 100644 index 0000000000..d6277261d4 --- /dev/null +++ b/app/controllers/api/v1/accounts/featured_tags_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class Api::V1::Accounts::FeaturedTagsController < Api::BaseController + before_action :set_account + before_action :set_featured_tags + + respond_to :json + + def index + render json: @featured_tags, each_serializer: REST::AccountFeaturedTagSerializer + end + + private + + def set_account + @account = Account.find(params[:account_id]) + end + + def set_featured_tags + @featured_tags = @account.featured_tags + end +end diff --git a/app/serializers/rest/account_featured_tag_serializer.rb b/app/serializers/rest/account_featured_tag_serializer.rb new file mode 100644 index 0000000000..d8d5fd68c5 --- /dev/null +++ b/app/serializers/rest/account_featured_tag_serializer.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class REST::AccountFeaturedTagSerializer < ActiveModel::Serializer + include RoutingHelper + + attributes :id, :name, :url + + def id + object.tag.id.to_s + end + + def name + "##{object.name}" + end + + def url + short_account_tag_url(object.account, object.tag) + end +end diff --git a/config/routes.rb b/config/routes.rb index 0e13d8cb2b..96562d5fc2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -383,6 +383,7 @@ Rails.application.routes.draw do resources :following, only: :index, controller: 'accounts/following_accounts' resources :lists, only: :index, controller: 'accounts/lists' resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs' + resources :featured_tags, only: :index, controller: 'accounts/featured_tags' member do post :follow -- GitLab