docbrown/app/controllers/api/v0/follows_controller.rb
Dana Scheider 24641d537a
API: Add route for fetching a user's followed tags (#9108)
* Add route for fetching a user's followed tags

* Move followed tags route to FollowsController instead of TagsController and add JSON view

* Add missing new line

* Change the dots for our linter

Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Molly Struve <mollylbs@gmail.com>
2020-09-18 16:28:42 -05:00

22 lines
645 B
Ruby

module Api
module V0
class FollowsController < ApiController
before_action :authenticate_with_api_key_or_current_user!
def create
user_ids = params[:users].map { |h| h["id"] }
user_ids.each do |user_id|
Users::FollowWorker.perform_async(current_user.id, user_id, "User")
end
render json: { outcome: "followed #{user_ids.count} users" }
end
def tags
@follows = @user.follows_by_type("ActsAsTaggableOn::Tag")
.select(%i[id followable_id followable_type points])
.includes(:followable)
.order(points: :desc)
end
end
end
end