diff --git a/app/controllers/api_bands_controller.rb b/app/controllers/api_bands_controller.rb index 2dbb118b5..28f55ece6 100644 --- a/app/controllers/api_bands_controller.rb +++ b/app/controllers/api_bands_controller.rb @@ -1,6 +1,7 @@ class ApiBandsController < ApplicationController - before_filter :signed_in_user, only: [:index, :show, :create, :update] + before_filter :signed_in_user, only: [:index, :show, :create, :update, + :following_create, :following_destroy] respond_to :json @@ -51,9 +52,17 @@ class ApiBandsController < ApplicationController # FOLLOWINGS def following_create + @follower = BandFollower.new() + @follower.user_id = params[:follower_id] + @follower.follower_id = params[:id] + @follower.save + @user = User.find(params[:follower_id]) + respond_with @user, responder: ApiResponder, :location => api_following_index_url(@user) end def following_destroy + JamRuby::BandFollower.delete_all "(user_id = '#{params[:user_id]}' AND band_id = '#{params[:id]}')" + respond_with responder: ApiResponder end end \ No newline at end of file diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index 415d04326..be2e23f2a 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -58,12 +58,32 @@ class ApiUsersController < ApplicationController # FOLLOWINGS def following_index @user = User.find(params[:id]) + + # TODO: get band followings and merge (@user.band_followings) end def following_create + + if !params[:user_id].nil? + @follower = UserFollower.new() + @follower.user_id = params[:user_id] + @follower.follower_id = params[:id] + + elsif !params[:band_id].nil? + @follower = BandFollower.new() + @follower.band_id = params[:band_id] + @follower.follower_id = params[:id] + end + + @follower.save + @user = User.find(params[:id]) + respond_with @user, responder: ApiResponder, :location => api_following_index_url(@user) end def following_destroy + JamRuby::UserFollower.delete_all "(user_id = '#{params[:user_id]}' AND follower_id = '#{params[:id]}')" + #JamRuby::BandFollower.delete_all "(ban_id = '#{params[:band_id]}' AND follower_id = '#{params[:id]}')" + respond_with responder: ApiResponder end # FRIENDS diff --git a/app/views/api_bands/following_create.rabl b/app/views/api_bands/following_create.rabl new file mode 100644 index 000000000..94be1bebd --- /dev/null +++ b/app/views/api_bands/following_create.rabl @@ -0,0 +1,3 @@ +object @band.followings + +extends "api_bands/following_index" \ No newline at end of file diff --git a/app/views/api_users/following_create.rabl b/app/views/api_users/following_create.rabl new file mode 100644 index 000000000..c95a073e0 --- /dev/null +++ b/app/views/api_users/following_create.rabl @@ -0,0 +1,3 @@ +object @user.followings + +extends "api_users/following_index" \ No newline at end of file diff --git a/app/views/api_users/friend_index.rabl b/app/views/api_users/friend_index.rabl index 0cd06ecb0..3e5c75cd2 100644 --- a/app/views/api_users/friend_index.rabl +++ b/app/views/api_users/friend_index.rabl @@ -1,3 +1,3 @@ object @user.friends -attributes :id, :name, :email, :online, :city, :state, :country \ No newline at end of file +attributes :id, :name, :city, :state, :country, :email, :online \ No newline at end of file diff --git a/app/views/api_users/show.rabl b/app/views/api_users/show.rabl index eacc39299..a4589cac9 100644 --- a/app/views/api_users/show.rabl +++ b/app/views/api_users/show.rabl @@ -1,6 +1,6 @@ object @user -attributes :id, :name, :email, :online, :photo_url, :city, :state, :country, :friend_count, :follower_count, :following_count +attributes :id, :name, :city, :state, :country, :email, :online, :photo_url, :friend_count, :follower_count, :following_count unless @user.friends.nil? || @user.friends.size == 0 child :friends => :friends do diff --git a/config/routes.rb b/config/routes.rb index 9a5dccea3..20edb8667 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,7 +57,7 @@ SampleApp::Application.routes.draw do match '/users/:id/followers' => 'api_users#follower_index', :via => :get # user followings - match '/users/:id/followings' => 'api_users#following_index', :via => :get + match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_following_index' match '/users/:id/followings' => 'api_users#following_create', :via => :post match '/users/:id/followings/:user_id' => 'api_users#following_destroy', :via => :delete @@ -74,11 +74,11 @@ SampleApp::Application.routes.draw do # band followers match '/bands/:id/followers' => 'api_bands#follower_index', :via => :get - +=begin # band followings match '/bands/:id/followings' => 'api_bands#following_create', :via => :post match '/bands/:id/followings/:user_id' => 'api_bands#following_destroy', :via => :delete - +=end # invitations match '/invitations/:id' => 'api_invitations#show', :via => :get, :as => 'api_invitation_detail' match '/invitations/:id' => 'api_invitations#delete', :via => :delete