summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-07-07 18:54:35 -0400
committerDavid Gay <david@davidgay.org>2021-07-07 18:54:35 -0400
commite63703a412ff146b028e68baa100837b58f0c200 (patch)
tree2fe7a9744387839ed9883fc44d1c4c80b3f9388e /app
parent81a6eaa28ac1129fe0a218b6459dbee45ac8459e (diff)
Consolidate identical bazaar postings
Diffstat (limited to 'app')
-rw-r--r--app/controllers/bazaar_controller.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/bazaar_controller.rb b/app/controllers/bazaar_controller.rb
index d51a419..4ba858a 100644
--- a/app/controllers/bazaar_controller.rb
+++ b/app/controllers/bazaar_controller.rb
@@ -11,15 +11,25 @@ class BazaarController < ApplicationController
if params[:buy_order] == "1"
BazaarOrder.transaction do
current_char.shift_item("vestige", (-price_each * quantity))
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: true)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: true)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted buy order for #{item.name} at #{price_each} vg each."
end
else
BazaarOrder.transaction do
current_char.shift_item(item, -quantity)
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: false)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: false)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted sell order for #{item.name} at #{price_each} vg each."
end
end