docbrown/app/controllers/api/v0/followings_controller.rb
John Curcio 157a6f1ef1 Add pagination to followers and following page in dashboard (#258) (#4375) [deploy]
* Add infinite scroll to followers list (#258)

* Refactor fetchNext function for clarity (#258)

* Sepparate following tab into multiple tabs to support infinite scroll (#258)

* Add infinite scroll to following pages (#258)

* Add tests to infinite scroll api

* Refactor dashboard loading text

* Refactor infine scroll function

* Fix duplicated entries problem in infinite scrolling

* Switch randomized attributes to sequential to avoid InvalidRecord error

* Add acceptance tests for infinite scroll

* Remove unused following method

* parameterize limit per page for followers and followings

* Split follows endpoint into followers and followings

* Authenticate user with api key in followers and followings

* Split followers endpoint into users and organizations

* Add redundant html to sublist partial

* Speed up infinite scroll tests

* Refactor api json responses to use partials

* Authenticate api user before follows create

* Resolve conflicts on scrolling js

* Improve partials organization and fix organization username bug

* Improve readability of unauthorized test

* Use let! to create scrolling test data

* Fix not working podcasts link

* Refactor initScrolling to remove linting errors

* Fix codeclimate coding style issue

* Test tags forms and podcasts hyperlinks

* Fix eslint issue with double equals

* Improve before_action usage and readability
2019-11-20 18:21:18 -05:00

51 lines
1.3 KiB
Ruby

module Api
module V0
class FollowingsController < ApiController
before_action :authenticate_with_api_key_or_current_user!
before_action -> { limit_per_page(default: 80, max: 1000) }
def users
@follows = current_user.
follows_by_type("User").
order("created_at DESC").
includes(:followable).
page(params[:page]).
per(@follows_limit)
end
def tags
@followed_tags = current_user.
follows_by_type("ActsAsTaggableOn::Tag").
order("points DESC").
includes(:followable).
page(params[:page]).
per(@follows_limit)
end
def organizations
@followed_organizations = current_user.
follows_by_type("Organization").
order("created_at DESC").
includes(:followable).
page(params[:page]).
per(@follows_limit)
end
def podcasts
@followed_podcasts = current_user.
follows_by_type("Podcast").
order("created_at DESC").
includes(:followable).
page(params[:page]).
per(@follows_limit)
end
private
def limit_per_page(default:, max:)
per_page = (params[:per_page] || default).to_i
@follows_limit = [per_page, max].min
end
end
end
end