diff --git a/app/controllers/api_bands_controller.rb b/app/controllers/api_bands_controller.rb new file mode 100644 index 000000000..cc4ec602e --- /dev/null +++ b/app/controllers/api_bands_controller.rb @@ -0,0 +1,7 @@ +class ApiBandsController < ApplicationController + + before_filter :signed_in_user, only: [:index, :edit, :update, :delete] + + respond_to :json + +end \ No newline at end of file diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index 3b373fb28..d8b612148 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -16,14 +16,15 @@ class ApiUsersController < ApplicationController end def create - @user = User.new() - @user.email = params[:email] - @user.creator = current_user - @user.description = params[:description] - @user.save + User.save(params) respond_with @user, responder: ApiResponder, :location => api_user_detail_url(@user) end + def update + User.save(params) + respond_with @user, responder: ApiResponder + end + def delete @user = User.find(params[:id]) @user.delete diff --git a/app/views/api_bands/index.rabl b/app/views/api_bands/index.rabl new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/api_bands/show.rabl b/app/views/api_bands/show.rabl new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/api_users/index.rabl b/app/views/api_users/index.rabl index ca9dc66b9..6e0ebdb53 100644 --- a/app/views/api_users/index.rabl +++ b/app/views/api_users/index.rabl @@ -1,3 +1,4 @@ collection @users -extends "api_users/show" +# do not retrieve all child collections when showing a list of users +attributes :id, :name, :email, :online, :musician, :photo_url \ No newline at end of file diff --git a/app/views/api_users/show.rabl b/app/views/api_users/show.rabl index ef2d8a16e..7183ad3ac 100644 --- a/app/views/api_users/show.rabl +++ b/app/views/api_users/show.rabl @@ -1,7 +1,21 @@ object @user -attributes :id, :name, :email, :admin, :online +attributes :id, :name, :email, :online, :musician, :photo_url -child :friends => :friends do - attributes :id, :name, :online +unless @user.friends.nil? || @user.friends.size == 0 + child :friends => :friends do + attributes :id, :name, :online + end +end + +unless @user.bands.nil? || @user.bands.size == 0 + child :bands => :bands do + attributes :id, :name + end +end + +unless @user.instruments.nil? || @user.instruments.size == 0 + child :instruments => :instruments do + attributes :id, :description, :proficiency_level + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4de040efa..73064923c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,15 @@ SampleApp::Application.routes.draw do match '/users/:id' => 'api_users#update', :via => :put 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' => 'api_bands#create', :via => :post + match '/bands/:id' => 'api_bands#update', :via => :put + match '/bands/:id/members' => 'api_bands#members_index', :via => :get +=end + # friend requests match '/users/:id/friend_requests' => 'api_users#friend_request_index', :via => :get match '/friend_requests/:id' => 'api_users#friend_request_show', :via => :get, :as => 'api_friend_request_detail'