Merge branch 'master' of bitbucket.org:jamkazam/jam-web
This commit is contained in:
commit
f8604cb7f3
|
|
@ -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
|
||||
|
||||
|
|
@ -43,4 +44,25 @@ class ApiBandsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# FOLLOWERS
|
||||
def follower_index
|
||||
# NOTE: follower_index.rabl template references the followers property
|
||||
@band = Band.find(params[:id])
|
||||
end
|
||||
|
||||
# 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
|
||||
|
|
@ -21,7 +21,7 @@ class ApiUsersController < ApplicationController
|
|||
# check for errors
|
||||
if @user.errors.nil? || @user.errors.size == 0
|
||||
respond_with @user, responder: ApiResponder, :location => api_user_detail_url(@user)
|
||||
|
||||
|
||||
else
|
||||
raise ActiveRecord::Rollback
|
||||
response.status = :unprocessable_entity
|
||||
|
|
@ -49,6 +49,44 @@ class ApiUsersController < ApplicationController
|
|||
respond_with @user, responder: ApiResponder
|
||||
end
|
||||
|
||||
# FOLLOWERS
|
||||
def follower_index
|
||||
# NOTE: follower_index.rabl template references the followers property
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
# 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
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
object @band.followers
|
||||
|
||||
attributes :follower_id => :user_id
|
||||
|
||||
node :name do |follower|
|
||||
follower.user.name
|
||||
end
|
||||
|
||||
node :city do |follower|
|
||||
follower.user.city
|
||||
end
|
||||
|
||||
node :state do |follower|
|
||||
follower.user.state
|
||||
end
|
||||
|
||||
node :country do |follower|
|
||||
follower.user.country
|
||||
end
|
||||
|
||||
node :musician do |follower|
|
||||
follower.user.musician
|
||||
end
|
||||
|
||||
node :photo_url do |follower|
|
||||
follower.user.photo_url
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
object @band.followings
|
||||
|
||||
extends "api_bands/following_index"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
collection @bands
|
||||
|
||||
# do not retrieve all child collections when showing a list of bands
|
||||
attributes :id, :name, :photo_url, :logo_url
|
||||
attributes :id, :name, :city, :state, :country, :photo_url, :logo_url,
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
object @band
|
||||
|
||||
attributes :id, :name, :website, :biography, :photo_url, :logo_url
|
||||
attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url, :logo_url, :follower_count
|
||||
|
||||
unless @band.users.nil? || @band.users.size == 0
|
||||
child :users => :musicians do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
object @user.followers
|
||||
|
||||
attributes :follower_id => :user_id
|
||||
|
||||
node :name do |follower|
|
||||
follower.user.name
|
||||
end
|
||||
|
||||
node :city do |follower|
|
||||
follower.user.city
|
||||
end
|
||||
|
||||
node :state do |follower|
|
||||
follower.user.state
|
||||
end
|
||||
|
||||
node :country do |follower|
|
||||
follower.user.country
|
||||
end
|
||||
|
||||
node :musician do |follower|
|
||||
follower.user.musician
|
||||
end
|
||||
|
||||
node :photo_url do |follower|
|
||||
follower.user.photo_url
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
object @user.followings
|
||||
|
||||
extends "api_users/following_index"
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
object @user.followings
|
||||
|
||||
attributes :user_id
|
||||
|
||||
node :name do |following|
|
||||
following.user.name
|
||||
end
|
||||
|
||||
node :city do |following|
|
||||
following.user.city
|
||||
end
|
||||
|
||||
node :state do |following|
|
||||
following.user.state
|
||||
end
|
||||
|
||||
node :country do |following|
|
||||
following.user.country
|
||||
end
|
||||
|
||||
node :musician do |following|
|
||||
following.user.musician
|
||||
end
|
||||
|
||||
node :photo_url do |following|
|
||||
following.user.photo_url
|
||||
end
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
object @user.friends
|
||||
|
||||
attributes :id, :name, :email, :online
|
||||
attributes :id, :name, :city, :state, :country, :email, :online
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
collection @users
|
||||
|
||||
# do not retrieve all child collections when showing a list of users
|
||||
attributes :id, :name, :email, :online, :musician, :photo_url
|
||||
attributes :id, :name, :city, :state, :country, :email, :online, :musician, :photo_url
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
object @user
|
||||
|
||||
attributes :id, :name, :email, :online, :photo_url
|
||||
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
|
||||
|
|
|
|||
|
|
@ -43,28 +43,6 @@ SampleApp::Application.routes.draw do
|
|||
match '/users/:id' => 'api_users#update', :via => :post
|
||||
match '/users/:id' => 'api_users#destroy', :via => :delete
|
||||
|
||||
# bands
|
||||
match '/bands' => 'api_bands#index', :via => :get
|
||||
match '/bands/:id' => 'api_bands#show', :via => :get, :as => 'api_band_detail'
|
||||
match '/bands' => 'api_bands#create', :via => :post
|
||||
match '/bands/:id' => 'api_bands#update', :via => :post
|
||||
=begin
|
||||
match '/bands/:id/followers' => 'api_bands#followers_index', :via => :get
|
||||
|
||||
# followers
|
||||
match '/users/:id/followers' => 'api_users#followers_index', :via => :get
|
||||
|
||||
# followings
|
||||
match '/users/:id/followings' => 'api_users#followings_index', :via => :get
|
||||
match '/users/:id/followings' => 'api_users#followings_create', :via => :post
|
||||
match '/users/:id/followings/:user_id' => 'api_users#followings_destroy', :via => :delete
|
||||
|
||||
# favorites
|
||||
match '/users/:id/favorites' => 'api_users#favorites_index', :via => :get
|
||||
match '/users/:id/favorites' => 'api_users#favorites_create', :via => :post
|
||||
match '/users/:id/favorites/:recording_id' => 'api_users#favorites_destroy', :via => :delete
|
||||
=end
|
||||
|
||||
# friend requests
|
||||
match '/users/:id/friend_requests' => 'api_users#friend_request_index', :via => :get
|
||||
match '/friend_requests/:id' => 'api_users#friend_request_show', :via => :get, :as => 'api_friend_request_detail'
|
||||
|
|
@ -75,13 +53,38 @@ SampleApp::Application.routes.draw do
|
|||
match '/users/:id/friends' => 'api_users#friend_index', :via => :get
|
||||
match '/users/:id/friends/:friend_id' => 'api_users#friend_destroy', :via => :delete
|
||||
|
||||
# user followers
|
||||
match '/users/:id/followers' => 'api_users#follower_index', :via => :get
|
||||
|
||||
# user followings
|
||||
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
|
||||
|
||||
# favorites
|
||||
match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get
|
||||
match '/users/:id/favorites' => 'api_users#favorite_create', :via => :post
|
||||
match '/users/:id/favorites/:recording_id' => 'api_users#favorite_destroy', :via => :delete
|
||||
|
||||
# bands
|
||||
match '/bands' => 'api_bands#index', :via => :get
|
||||
match '/bands/:id' => 'api_bands#show', :via => :get, :as => 'api_band_detail'
|
||||
match '/bands' => 'api_bands#create', :via => :post
|
||||
match '/bands/:id' => 'api_bands#update', :via => :post
|
||||
|
||||
# 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
|
||||
match '/invitations' => 'api_invitations#index', :via => :get
|
||||
match '/invitations' => 'api_invitations#create', :via => :post
|
||||
|
||||
|
||||
# invitations
|
||||
match '/instruments/:id' => 'api_instruments#show', :via => :get, :as => 'api_instrument_detail'
|
||||
match '/instruments' => 'api_instruments#index', :via => :get
|
||||
|
|
|
|||
Loading…
Reference in New Issue