-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipes-StarMart #64
base: master
Are you sure you want to change the base?
Pipes-StarMart #64
Conversation
…essions_controller
…ed Irene and Bianca as legit merchants and gave them products and seed data
bEtsyWhat We're Looking For
IMPORTANT: Whoever submitted the PR (and thus will get the notification about this feedback) should share this with their teammates. |
@merchant = Merchant.find_by(id: expected_merchant_id) | ||
|
||
if @login_merchant && @login_merchant.id == @merchant.id | ||
unless @merchant |
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.
The format of this method is a little strange to me - I think you might be able to design a cleaner interface.
Also, line 53 (unless @merchant
) will never happen, because if the @merchant
is nil
the the call to @merchant.id
on line 52 will produce an error.
|
||
before_action only:[:show] do | ||
@try_merchant = Merchant.find_by(id: params[:id]) | ||
restrict_merchant(@try_merchant) |
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.
If you're restricting the URI parameter to only be the ID of the logged in merchant, then why have a parameterized URI at all? It would probably make more sense to always show the logged in merchant's details.
# TODO: TAKE ALOOK AT THIS. WHAT IS THE MERCHANT ID COMING FROM? SESSIONS? ALREADY A @LOGIN_MERCHANT | ||
before_action only:[:index] do | ||
restrict_merchant(params[:merchant_id]) | ||
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.
I very much agree with that TODO - by my reading, restrict_merchant
checks that the argument matches the logged in merchant's ID, which in this case will always be true.
order.products.each do |item| | ||
order.order_items.each do |order_item| | ||
item.inventory -= order_item.quantity | ||
item.save |
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 would be a good bit of work to do in the Model, possibly as a custom method on Order
.
end | ||
|
||
def create | ||
if @login_merchant |
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 have this if @login_merchant
many times in this controller, would it be possible to DRY this up with a filter?
|
||
resources :orders, only: [:show, :index] do | ||
resources :payments, only: [:index, :new, :create] | ||
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.
I'm not sure why the payments
routes are nested under orders
here. Seems to me that the routes for a payments ought not to be parameterized at all, but instead take cart info from the session
.
|
||
def order_items_params | ||
params.permit(:quantity, :product_id) | ||
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 helper method is never called! Be careful what you copy-paste!
bEtsy
Congratulations! You're submitting your assignment! These comprehension questions should be answered by all members of your team, not by a single teammate.
Comprehension Questions