added ability to create band followers

This commit is contained in:
Brian Smith 2012-11-06 07:15:02 -05:00
parent b8571b612d
commit 453bc2b117
7 changed files with 41 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
object @band.followings
extends "api_bands/following_index"

View File

@ -0,0 +1,3 @@
object @user.followings
extends "api_users/following_index"

View File

@ -1,3 +1,3 @@
object @user.friends
attributes :id, :name, :email, :online, :city, :state, :country
attributes :id, :name, :city, :state, :country, :email, :online

View File

@ -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

View File

@ -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