Skip to content

Commit

Permalink
[gh-11] - Updated rails delivery mechanism to use the refactored actions
Browse files Browse the repository at this point in the history
  • Loading branch information
brianknapp committed Jul 1, 2013
1 parent 817a4ee commit b2e3db4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
11 changes: 6 additions & 5 deletions delivery/rails_app/app/controllers/application_controller.rb
Expand Up @@ -9,13 +9,14 @@ class ApplicationController < ActionController::Base
protect_from_forgery

def index
# get list of statuses
action = ListStatuses.new StatusJack.new
@statuses = action.execute
# get list of statuses
list_statuses = ListStatuses.new StatusJack.new
@statuses = list_statuses.execute

# get list of users
action = ListUsers.new UserJack.new
users = action.execute
list_users = ListUsers.new UserJack.new
users = list_users.execute

@users = {}
users.each do |user|
@users[user[:id]] = user
Expand Down
44 changes: 17 additions & 27 deletions delivery/rails_app/app/controllers/status_controller.rb
Expand Up @@ -12,56 +12,46 @@ class StatusController < ActionController::Base
protect_from_forgery

def get
input = { :id => params[:id].to_i }
get_status = GetStatus.new StatusJack.new
@status = get_status.execute where_id: params[:id].to_i

action = GetStatus.new StatusJack.new
puts action.inspect
@status = action.execute input

input = { :id => @status[:user_id] }
action = GetUser.new UserJack.new
@user = action.execute input
get_user = GetUser.new UserJack.new
@user = get_user.execute where_id: @status[:user_id]
end

def create
if request.post?
input = { :user_id => params[:user_id].to_i, :text => params[:text] }
action = CreateStatus.new StatusJack.new
@status = action.execute input
create_status = CreateStatus.new StatusJack.new
@status = create_status.execute with_user_id: params[:user_id].to_i, and_text: params[:text]
redirect_to '/'
end
end

def update
if request.get?
input = { :id => params[:id].to_i }
action = GetStatus.new StatusJack.new
@status = action.execute input
get_status = GetStatus.new StatusJack.new
@status = get_status.execute where_id: params[:id].to_i
end

if request.post?
input = { :id => params[:id].to_i, :text => params[:text], :user_id => params[:user_id].to_i }
action = UpdateStatus.new StatusJack.new
@status = action.execute input
update_status = UpdateStatus.new StatusJack.new
@status = update_status.execute for_status_id: params[:id].to_i, with_text: params[:text], and_user_id: params[:user_id].to_i
redirect_to "/status/#{@status[:id]}"
end
end

def remove
if request.get?
input = { :id => params[:id].to_i }
action = GetStatus.new StatusJack.new
@status = action.execute input

input = { :id => @status[:user_id] }
action = GetUser.new UserJack.new
@user = action.execute input
get_status = GetStatus.new StatusJack.new
@status = get_status.execute where_id: params[:id].to_i

get_user = GetUser.new UserJack.new
@user = get_user.execute where_id: @status[:user_id]
end

if request.post?
input = { :id => params[:id].to_i }
action = RemoveStatus.new StatusJack.new
result = action.execute input
remove_status = RemoveStatus.new StatusJack.new
result = remove_status.execute where_id: params[:id].to_i
if result == true
redirect_to '/'
else
Expand Down
10 changes: 4 additions & 6 deletions delivery/rails_app/app/controllers/user_controller.rb
Expand Up @@ -8,16 +8,14 @@ class UserController < ActionController::Base
protect_from_forgery

def get
input = { :id => params[:id].to_i }
action = GetUser.new UserJack.new
@user = action.execute input
get_user = GetUser.new UserJack.new
@user = get_user.execute where_id: params[:id].to_i
end

def sign_up
if request.post?
input = { :handle => params[:handle] }
action = CreateUser.new UserJack.new
@user = action.execute input
create_user = CreateUser.new UserJack.new
@user = create_user.execute with_user_handle: params[:handle]
redirect_to '/'
end
end
Expand Down

0 comments on commit b2e3db4

Please sign in to comment.