diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index a55cf018d..472efa7b8 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -66,7 +66,8 @@ class ApiUsersController < ApiController raise ActiveRecord::Rollback response.status = :unprocessable_entity respond_with @user - end + end + # FRIENDS end def delete @@ -75,13 +76,13 @@ class ApiUsersController < ApiController respond_with @user, responder: ApiResponder end - # FOLLOWERS + ###################### FOLLOWERS ######################## def follower_index # NOTE: follower_index.rabl template references the followers property @user = User.find(params[:id]) end - # FOLLOWINGS + ###################### FOLLOWINGS ####################### def following_index @user = User.find(params[:id]) @@ -89,7 +90,6 @@ class ApiUsersController < ApiController end def following_create - if !params[:user_id].nil? @follower = UserFollower.new() @follower.user_id = params[:user_id] @@ -112,7 +112,29 @@ class ApiUsersController < ApiController respond_with responder: ApiResponder end - # FRIENDS + ###################### FAVORITES ######################## + def favorite_index + @user = User.find(params[:id]) + + # TODO: get band followings and merge (@user.band_followings) + end + + def favorite_create + @follower = UserFavorite.new() + @follower.user_id = params[:user_id] + @follower.follower_id = params[:id] + + @follower.save + @user = User.find(params[:id]) + respond_with @user, responder: ApiResponder, :location => api_favorite_index_url(@user) + end + + def favorite_destroy + JamRuby::UserFavorite.delete_all "(user_id = '#{params[:id]}' AND recording_id = '#{params[:recording_id]}')" + respond_with responder: ApiResponder + end + + ###################### FRIENDS ########################## def friend_request_index # get all outgoing and incoming friend requests @friend_requests = FriendRequest.where("(friend_id='#{params[:id]}' OR user_id='#{params[:id]}') AND accepted is null") @@ -164,6 +186,7 @@ class ApiUsersController < ApiController respond_with responder: ApiResponder end + ###################### AUTHORIZATION #################### def auth_session_create @user = User.authenticate(params[:email], params[:password]) @@ -179,6 +202,4 @@ class ApiUsersController < ApiController sign_out render :json => { :success => true }, :status => 200 end - - end \ No newline at end of file diff --git a/app/views/api_users/favorite_create.rabl b/app/views/api_users/favorite_create.rabl new file mode 100644 index 000000000..4e83898ba --- /dev/null +++ b/app/views/api_users/favorite_create.rabl @@ -0,0 +1,3 @@ +object @user.favorites + +extends "api_users/favorite_index" \ No newline at end of file diff --git a/app/views/api_users/favorite_index.rabl b/app/views/api_users/favorite_index.rabl new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index 4d9db6c94..a803ef322 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,7 +82,7 @@ SampleApp::Application.routes.draw do match '/users/:id/recordings/:recording_id' => 'api_users#recording_delete', :via => :delete # favorites - match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get + match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index' match '/users/:id/favorites' => 'api_users#favorite_create', :via => :post match '/users/:id/favorites/:recording_id' => 'api_users#favorite_destroy', :via => :delete diff --git a/spec/requests/users_api_spec.rb b/spec/requests/users_api_spec.rb index 194b68ce2..519c3f31d 100644 --- a/spec/requests/users_api_spec.rb +++ b/spec/requests/users_api_spec.rb @@ -14,9 +14,9 @@ describe "User API", :type => :api do UserMailer.deliveries.clear end - def login(user) + def login(login_user) # login as fan - post '/api/auth_session.json', { :email => user.email, :password => user.password }.to_json, "CONTENT_TYPE" => 'application/json' + post '/api/auth_session.json', { :email => login_user.email, :password => login_user.password }.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should == 200 JSON.parse(last_response.body).should == { "success" => true } end @@ -73,5 +73,15 @@ describe "User API", :type => :api do updated_user["musician"].should == true updated_user["first_name"].should == "Brian" end + + it "allows user to add followings" do + end + + it "can get followers" do + end + + it "allows user to delete followings" do + end + end end