docbrown/app/controllers/api/v0/podcast_episodes_controller.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

32 lines
953 B
Ruby

module Api
module V0
class PodcastEpisodesController < ApiController
# before_action :set_cache_control_headers, only: [:index, :show]
caches_action :index,
cache_path: Proc.new { |c| c.params.permit! },
expires_in: 10.minutes
respond_to :json
caches_action :show,
cache_path: Proc.new { |c| c.params.permit! },
expires_in: 10.minutes
respond_to :json
before_action :cors_preflight_check
after_action :cors_set_access_control_headers
def index
@page = params[:page]
if params[:username]
@podcast = Podcast.find_by_slug(params[:username]) || not_found
@podcast_episodes = @podcast.
podcast_episodes.order("published_at desc").
page(@page).
per(30)
else
@podcast_episodes = PodcastEpisode.order("published_at desc").page(@page).per(30)
end
end
end
end
end