Added account featured tags API (#11817)
This commit is contained in:
parent
c6ad9aae69
commit
cb37bd63dc
3 changed files with 42 additions and 0 deletions
22
app/controllers/api/v1/accounts/featured_tags_controller.rb
Normal file
22
app/controllers/api/v1/accounts/featured_tags_controller.rb
Normal file
|
@ -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
|
19
app/serializers/rest/account_featured_tag_serializer.rb
Normal file
19
app/serializers/rest/account_featured_tag_serializer.rb
Normal file
|
@ -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
|
|
@ -430,6 +430,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
|
||||
|
|
Loading…
Reference in a new issue