added /friends subresource for user API

This commit is contained in:
Brian Smith 2012-10-14 00:29:49 -04:00
parent a36eec81c5
commit 1fa514b2bd
4 changed files with 17 additions and 11 deletions

View File

@ -1,6 +1,8 @@
class ApiUsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
before_filter :signed_in_user, only: [:index, :edit, :update, :delete,
:friend_request_index, :friend_request_create,
:friend_index, :friend_destroy]
respond_to :json
@ -33,16 +35,19 @@ class ApiUsersController < ApplicationController
def friend_request_create
end
def friend_request_show
end
def friend_request_update
end
def friend_index
end
def friend_create
end
def friend_show
# NOTE: friend_index.rabl template references the friends property
@user = User.find(params[:id])
end
def friend_destroy
JamRuby::Friendship.delete_all "(user_id = '#{params[:id]}' AND friend_id = '#{params[:friend_id]}') OR (user_id = '#{params[:friend_id]}' AND friend_id = '#{params[:id]}')"
end
end

View File

@ -0,0 +1,3 @@
object @user.friends
attributes :id, :name, :online

View File

@ -1,6 +1,6 @@
object @user
attributes :id, :name, :email, :admin
attributes :id, :name, :email, :admin, :online
child :friends => :friends do
attributes :id, :name, :online

View File

@ -43,12 +43,10 @@ SampleApp::Application.routes.draw do
match '/users/:id/friend_requests' => 'api_users#friend_request_index', :via => :get
match '/users/:id/friend_requests' => 'api_users#friend_request_create', :via => :post
match '/users/:id/friends/:friend_request_id' => 'api_users#friend_request_show', :via => :get, :as => 'api_user_friend_request_detail'
match '/users/:id/friends/:friend_request_id' => 'api_users#friend_request_edit', :via => :put
match '/users/:id/friends/:friend_request_id' => 'api_users#friend_request_update', :via => :put
# friends
match '/users/:id/friends' => 'api_users#friend_index', :via => :get
match '/users/:id/friends' => 'api_users#friend_create', :via => :post
match '/users/:id/friends/:friend_id' => 'api_users#friend_show', :via => :get, :as => 'api_user_friend_detail'
match '/users/:id/friends/:friend_id' => 'api_users#friend_destroy', :via => :delete
end
end