forked from AdaGold/betsy
-
Notifications
You must be signed in to change notification settings - Fork 15
Petsy Emporium by Katricia, Sigrid, Val, and Aurea in EDGES #16
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
Open
Aurea-Li
wants to merge
281
commits into
Ada-C10:master
Choose a base branch
from
Aurea-Li:old-master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merge after search added
bEtsyAurea: Ways to possibly refactor all the if statements in OrderItems controller
# Add an exception type and an instance method to class Order:
class InventoryError < StandardError; end
def add_item(product, quantity)
Order.transaction do
if quantity > product.stock
raise InventoryError, "Not enough #{product.name} in stock (wanted #{quantity}, have #{product.stock})"
end
item = self.order_items.find_by(product_id: product.id)
if item.nil?
item = self.order_items.new(product: product, quantity: 0)
end
item.quantity += quantity
item.save!
product.stock -= quantity
product.save!
end
end
# Then in the controller action, wrap the call in a begin/rescue block
def create
# ... find or create order and product (maybe do this in a filter?) ...
begin
order.add_item(product, params[:quantity])
rescue StandardError => err
flash[:status] = :error
flash[:result_text] = err.message
return
end
# If we got here, we've successfully updated the cart!
endNote the transaction - that ensures that all the operations either succeed or fail as a group. See https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html Sigrid: The merchant dashboard.
Val: Feedback on OrderItem model tests, the custom methods.
Katricia: DRYing up CSS
Only the person who submitted the PR will get an email about this feedback. Please let the rest of your team know about it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
require pryin our controllers.