The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

67 satır
1.5 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::BookmarksController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:bookmarks' }
  4. before_action :require_user!
  5. after_action :insert_pagination_headers
  6. respond_to :json
  7. def index
  8. @statuses = load_statuses
  9. render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
  10. end
  11. private
  12. def load_statuses
  13. cached_bookmarks
  14. end
  15. def cached_bookmarks
  16. cache_collection(
  17. Status.reorder(nil).joins(:bookmarks).merge(results),
  18. Status
  19. )
  20. end
  21. def results
  22. @_results ||= account_bookmarks.paginate_by_id(
  23. limit_param(DEFAULT_STATUSES_LIMIT),
  24. params_slice(:max_id, :since_id, :min_id)
  25. )
  26. end
  27. def account_bookmarks
  28. current_account.bookmarks
  29. end
  30. def insert_pagination_headers
  31. set_pagination_headers(next_path, prev_path)
  32. end
  33. def next_path
  34. api_v1_bookmarks_url pagination_params(max_id: pagination_max_id) if records_continue?
  35. end
  36. def prev_path
  37. api_v1_bookmarks_url pagination_params(min_id: pagination_since_id) unless results.empty?
  38. end
  39. def pagination_max_id
  40. results.last.id
  41. end
  42. def pagination_since_id
  43. results.first.id
  44. end
  45. def records_continue?
  46. results.size == limit_param(DEFAULT_STATUSES_LIMIT)
  47. end
  48. def pagination_params(core_params)
  49. params.slice(:limit).permit(:limit).merge(core_params)
  50. end
  51. end