Skip to content

Commit

Permalink
Add Show List
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMitchell committed Oct 6, 2022
1 parent 09abf35 commit 56db7f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/controllers/api/v1/shows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Api::V1::ShowsController < ApplicationController
respond_to :json
protect_from_forgery with: :null_session

def index
@group = Group.find_by!(token: params[:group_token])
end

def show
@group = Group.find_by!(token: params[:group_token])
@show = Show.includes(episodes: [staff: [:position, member: [:group]]]).find(@group.priority_show_search!(URI.decode_www_form_component(params[:name])).id)
Expand Down
9 changes: 9 additions & 0 deletions app/views/api/v1/shows/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
json.shows @group.shows.visible do |show|
json.id show.id
json.name show.name
json.status show.status

json.terms show.terms do |term|
json.name term.name
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace :api do
namespace :v1 do
resources :groups, only: [:index, :show], param: :token do
resources :shows, only: [:show], param: :name do
resources :shows, only: [:index, :show], param: :name do
patch 'episodes', to: 'episodes#update'
patch 'staff', to: 'staff#update'
end
Expand Down
9 changes: 9 additions & 0 deletions test/controllers/api/v1/shows_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ class Api::V1::ShowsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_equal "Saenai Heroine no Sodatekata ♭", response.parsed_body["name"]
end

test "should return a list of visible shows" do
group = Group.find_by(name: 'Cartel')
get api_v1_group_shows_url(group.token), as: :json
assert_response :success
show = response.parsed_body["shows"].first
assert_equal("Visible Show", show["name"])
assert_equal([{"name" => "public"}], show["terms"])
end
end

0 comments on commit 56db7f5

Please sign in to comment.