VRFS-81 more favorites development
This commit is contained in:
parent
3a78928b4f
commit
647ff68c83
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
object @user.favorites
|
||||
|
||||
extends "api_users/favorite_index"
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue