docbrown/app/controllers/api/v0/videos_controller.rb
rhymes 1df24046d8
Small API controllers refactoring (#6021) [deploy]
* TagsController inherits from ApiController
* Let ApiController inherit from ActionController::Base to have its own lifecycle
* Remove unused method
* Use only one respond_to :json for the entire API
* ApiController inherits from ActionController::Base
* Use Pundit only where needed
2020-02-12 11:51:42 -05:00

24 lines
732 B
Ruby

module Api
module V0
class VideosController < ApiController
before_action :cors_preflight_check
after_action :cors_set_access_control_headers
before_action :set_cache_control_headers, only: %i[index]
def index
page = params[:page]
per_page = (params[:per_page] || 24).to_i
num = [per_page, 1000].min
@video_articles = Article.with_video.
includes([:user]).
select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds).
order("hotness_score DESC").
page(page).per(num)
set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key)
end
end
end
end