band APIs
This commit is contained in:
parent
8bc6b44ee6
commit
56f27930a8
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue