docbrown/app/controllers/concerns/api/podcast_episodes_controller.rb
Fernando Valverde 8c836430ca
API V1 transition (#17835)
* API Articles v0-v1 restructure

* Remove unused helper

* Bulk move API controllers into concerns + add V1 controllers

* Extract API routes + some fixes

* Fix v1 api_controller authenticate! + add more article_controller specs

* Completed spec/requests/api/v1/articles_spec.rb

* specs up to listings

* All v1 specs except for 9 skips

* mime_types cleanup + authenticate! relocation

Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
2022-06-23 14:26:00 -06:00

25 lines
701 B
Ruby

module Api
module PodcastEpisodesController
extend ActiveSupport::Concern
def index
page = params[:page]
per_page = (params[:per_page] || 30).to_i
num = [per_page, 1000].min
if params[:username]
podcast = Podcast.available.find_by!(slug: params[:username])
relation = podcast.podcast_episodes.reachable
else
relation = PodcastEpisode.includes(:podcast).reachable
end
@podcast_episodes = relation
.select(:id, :slug, :title, :podcast_id)
.order(published_at: :desc)
.page(page).per(num)
set_surrogate_key_header PodcastEpisode.table_key, @podcast_episodes.map(&:record_key)
end
end
end