VRFS-102 - added routes for likes

This commit is contained in:
Brian Smith 2012-12-03 22:40:40 -05:00
parent a0e526043c
commit f3bf0f061c
10 changed files with 38 additions and 9 deletions

View File

@ -100,6 +100,7 @@ class ApiUsersController < ApiController
id = params[:id]
auth_user(id)
@user = User.find(id)
if !params[:user_id].nil?
User.create_user_following(params[:user_id], id)
respond_with @user, responder: ApiResponder, :location => api_user_following_index_url(@user)
@ -112,7 +113,14 @@ class ApiUsersController < ApiController
def following_destroy
auth_user(params[:id])
User.delete_user_following(params[:user_id], params[:id])
if !params[:user_id].nil?
User.delete_following(params[:user_id], nil, params[:id])
elsif !params[:band_id].nil?
User.delete_following(nil, params[:band_id], params[:id])
end
respond_with responder: ApiResponder, :status => 204
end

View File

@ -1,4 +1,4 @@
collection @bands
# do not retrieve all child collections when showing a list of bands
attributes :id, :name, :city, :state, :country, :photo_url, :logo_url,
attributes :id, :name, :city, :state, :country, :photo_url, :logo_url

View File

@ -6,6 +6,7 @@ node :genres do |recording|
unless recording.genres.nil? || recording.genres.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => recording.genres)
end
end
end

View File

@ -5,5 +5,6 @@ attributes :id, :description, :public
unless @recording.genres.nil? || @recording.genres.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => @recording.genres)
end
end

View File

@ -1,6 +1,6 @@
object @band
attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url, :logo_url, :follower_count
attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url, :logo_url, :liker_count, :follower_count, :recording_count, :session_count
unless @band.users.nil? || @band.users.size == 0
child :users => :musicians do
@ -20,5 +20,6 @@ end
unless @band.genres.nil? || @band.genres.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => @band.genres)
end
end

View File

@ -1,11 +1,12 @@
collection @recordings
attributes :id, :description, :public
attributes :id, :description, :public, :favorite_count
node :genres do |recording|
unless recording.genres.nil? || recording.genres.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => recording.genres)
end
end
end

View File

@ -1,9 +1,12 @@
object @recording
attributes :id, :description, :public
attributes :id, :description, :public, :favorite_count
unless @recording.genres.nil? || @recording.genres.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => @band.genres)
end
end
end
#TODO: show the Users that have added this Recording as a Favorite ONLY IF the owning user has "Better Analytics service level"

View File

@ -1,6 +1,6 @@
object @user
attributes :id, :first_name, :last_name, :city, :state, :country, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :follower_count, :following_count, :favorite_count
attributes :id, :first_name, :last_name, :city, :state, :country, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :follower_count, :following_count, :favorite_count, :recording_count, :session_count
unless @user.friends.nil? || @user.friends.size == 0
child :friends => :friends do
@ -14,6 +14,7 @@ unless @user.bands.nil? || @user.bands.size == 0
child :genres => :genres do
attributes :id, :description
#partial('api_genres/index', :object => @user.bands.genres)
end
end
end

View File

@ -75,7 +75,13 @@ SampleApp::Application.routes.draw do
match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index'
match '/users/:id/band_followings' => 'api_users#band_following_index', :via => :get, :as => 'api_band_following_index'
match '/users/:id/followings' => 'api_users#following_create', :via => :post
match '/users/:id/followings/:user_id' => 'api_users#following_destroy', :via => :delete
match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete
# user likes
match '/users/:id/likes' => 'api_users#like_index', :via => :get, :as => 'api_user_like_index'
match '/users/:id/band_likes' => 'api_users#band_like_index', :via => :get, :as => 'api_band_like_index'
match '/users/:id/likes' => 'api_users#like_create', :via => :post
match '/users/:id/likes' => 'api_users#like_destroy', :via => :delete
# user recordings
match '/users/:id/recordings' => 'api_users#recording_index', :via => :get

View File

@ -43,7 +43,7 @@ describe "User API", :type => :api do
def delete_user_following(authenticated_user, source_user, target_user)
login(authenticated_user.email, authenticated_user.password, 200, true)
delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json"
delete "/api/users/#{source_user.id}/followings.json", { :user_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
return last_response
end
@ -304,6 +304,7 @@ describe "User API", :type => :api do
private_description = "My Private Recording"
last_response = create_user_recording(user, user, private_description, false, ["rock"])
last_response.status.should == 201
private_recording = JSON.parse(last_response.body)
private_recording["description"].should == private_description
private_recording["public"].should == false
@ -416,6 +417,12 @@ describe "User API", :type => :api do
favorites[0]["recording_id"].should == recording["id"]
favorites[0]["description"].should == "My Recording"
favorites[0]["public"].should == true
# get recording
last_response = get_user_recording(user, user, recording["id"])
last_response.status.should == 200
recording_with_favorite = JSON.parse(last_response.body)
recording_with_favorite["favorite_count"].should == 1
end
it "should not allow user to create favorite for another user" do