-
Notifications
You must be signed in to change notification settings - Fork 57
1608 extract checkout object #1667
base: master
Are you sure you want to change the base?
Conversation
1c87731
to
bd43812
Compare
resolves #1608 --create manage route for managing users' reservations --extract checkin/checkout functionality to manage controller --extract as much functionality to checkoutHelper service object as possible --replace set_reservation before action with ||= --put repeated before_action into application controller
80003de
to
a4ab639
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good overall, except for the missing tests
Left a few suggestions to make a new form object and to restructure your current service object a bit
return unless @user.role == 'banned' | ||
flash[:error] = 'This user is banned and cannot check out equipment.' | ||
params[:banned] = true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be renamed -- it does more than set the user
before_action :set_user, only: [:show, :checkout] | ||
before_action :set_reservation, only: [:send_receipt] | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should swap the order of the public
and private
sections
# Overdue validation | ||
return unless handle_overdue_reservations | ||
true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all these checks can live inside a service object -- check out these examples from vesta:
service object, controller method, and handle_action
you can probably do something very similar by adding a less-generalized handle_action
to this controller
render :show, layout: 'application' | ||
end | ||
|
||
def checkout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this process should also live in a service object (example)
end | ||
|
||
CheckoutHelper.update_tos(@user) | ||
CheckoutHelper.send_checkout_receipts(checked_out_reservations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these methods belong in the batch/bulk service object
prep_receipt_page(check_in_set: [], check_out_set: checked_out_reservations) | ||
end | ||
|
||
def checkin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the above -- this method should live inside a service object
end | ||
|
||
# for editing reservations; not for checkout or check-in | ||
def update # rubocop:disable all | ||
@reservation = Reservation.find(params[:id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to just call reservation
, right?
@@ -0,0 +1,3 @@ | |||
# frozen_string_literal: true | |||
class Manage < ActiveRecord::Base | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a form object that handles all of the checks and bulk processing that you currently have in the controller (example)
@@ -0,0 +1,3 @@ | |||
# frozen_string_literal: true | |||
class Manage < ActiveRecord::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to inherit from ActiveRecord::Base
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this should probably be renamed to something that implies that this is for reservations only
@@ -0,0 +1,67 @@ | |||
# frozen_string_literal: true | |||
class CheckoutHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really good but needs a bit of reorganizing:
- The only methods on
self
should becheck_in!
andcheck_out!
, which should read like this:
def self.check_out!(**params)
new(**params).check_out!
end
- There should be an
initialize
method that sets some instance variables so you don't have to pass them around. It should use keyword args. - Any method that can raise an un-rescued exception should end in a
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be tested!
resolves #1608
--create manage route for managing users' reservations
--extract checkin/checkout functionality to manage controller
--extract as much functionality to checkoutHelper service object as possible