band APIs

This commit is contained in:
Brian Smith 2012-10-30 23:28:17 -04:00
parent 8bc6b44ee6
commit 56f27930a8
4 changed files with 40 additions and 4 deletions

View File

@ -4,4 +4,12 @@ class ApiBandsController < ApplicationController
respond_to :json
def index
@bands = Band.paginate(page: params[:page])
end
def show
@band = Band.find(params[:id])
end
end

View File

@ -0,0 +1,4 @@
collection @bands
# do not retrieve all child collections when showing a list of bands
attributes :id, :name, :photo_url, :logo_url

View File

@ -0,0 +1,24 @@
object @band
attributes :id, :name, :website, :biography, :photo_url, :logo_url
unless @band.users.nil? || @band.users.size == 0
child :users => :musicians do
attributes :id, :name, :photo_url
# TODO: figure out how to omit empty arrays
node :instruments do |user|
unless user.instruments.nil? || user.instruments.size == 0
child :musician_instruments => :instruments do
attributes :description, :proficiency_level
end
end
end
end
end
unless @band.genres.nil? || @band.genres.size == 0
child :genres => :genres do
attributes :id, :description
end
end

View File

@ -44,12 +44,12 @@ SampleApp::Application.routes.draw do
match '/users/:id' => 'api_users#destroy', :via => :delete
# bands
=begin
match '/bands' => 'api_bands#index', :via => :get
match '/bands/:id' => 'api_bands#show' :via => :get, :as => 'api_band_detail'
match '/bands/:id' => 'api_bands#show', :via => :get, :as => 'api_band_detail'
=begin
match '/bands' => 'api_bands#create', :via => :post
match '/bands/:id' => 'api_bands#update', :via => :put
match '/bands/:id/members' => 'api_bands#members_index', :via => :get
match '/bands/:id' => 'api_bands#update', :via => :post
match '/bands/:id/musicians' => 'api_bands#musicians_index', :via => :get
=end
# friend requests