Merge branch 'master' of bitbucket.org:jamkazam/jam-web

This commit is contained in:
Jonathon Wilson 2012-10-14 10:10:42 -06:00
commit f6e21c41df
6 changed files with 84 additions and 1 deletions

View File

@ -0,0 +1,53 @@
class ApiUsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :delete,
:friend_request_index, :friend_request_create,
:friend_index, :friend_destroy]
respond_to :json
def index
@users = User.paginate(page: params[:page])
end
def create
@user = User.new()
@user.creator = current_user
@user.description = params[:description]
@user.save
respond_with @user, responder: ApiResponder, :location => api_user_detail_url(@user)
end
def show
@user = User.find(params[:id])
end
def delete
@user = User.find(params[:id])
@user.delete
respond_with @user, responder: ApiResponder
end
def friend_request_index
end
def friend_request_create
end
def friend_request_show
end
def friend_request_update
end
def friend_index
# 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

@ -0,0 +1,3 @@
collection @users
extends "api_users/show"

View File

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

View File

@ -13,7 +13,7 @@ Rabl.configure do |config|
# config.include_bson_root = true
# config.include_plist_root = true
# config.include_xml_root = false
# config.include_child_root = true
config.include_child_root = false
# config.enable_json_callbacks = false
# config.xml_options = { :dasherize => true, :skip_types => false }
# config.view_paths = []

View File

@ -23,6 +23,7 @@ SampleApp::Application.routes.draw do
match '/client', to: 'clients#index'
scope '/api' do
# music sessions
match '/sessions/:id/participants' => 'api_music_sessions#participant_create', :via => :post
match '/participants/:id' => 'api_music_sessions#participant_show', :via => :get, :as => 'api_session_participant_detail'
match '/participants/:id' => 'api_music_sessions#participant_delete', :via => :delete
@ -31,5 +32,21 @@ SampleApp::Application.routes.draw do
match '/sessions' => 'api_music_sessions#index', :via => :get
match '/sessions' => 'api_music_sessions#create', :via => :post
# users
match '/users' => 'api_users#index', :via => :get
match '/users' => 'api_users#create', :via => :post
match '/users/:id' => 'api_users#show', :via => :get, :as => 'api_user_detail'
match '/users/:id' => 'api_users#edit', :via => :put
match '/users/:id' => 'api_users#destroy', :via => :delete
# friend requests
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_update', :via => :put
# friends
match '/users/:id/friends' => 'api_users#friend_index', :via => :get
match '/users/:id/friends/:friend_id' => 'api_users#friend_destroy', :via => :delete
end
end