auctify 1.1.0 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/app/controllers/auctify/api/v1/auctions_controller.rb +21 -10
- data/app/jobs/auctify/ensure_auctions_closing_job.rb +1 -1
- data/app/models/auctify/sale/auction.rb +8 -0
- data/app/models/auctify/sales_pack.rb +15 -8
- data/app/services/auctify/bids_appender.rb +13 -17
- data/lib/auctify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14832525cab9835407bccb94056500037fe39da17a9ea311f7053ce4adf48255
|
4
|
+
data.tar.gz: 522647a33fa236dd02c2980ecde719508bd83f21db2c0ffa38d1d77ce104d002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803112a2c554cb95f1eb818911ea4a92d4377306ba936ac5190101f8463a5378d225a5c260a50e01e8cc0f379ddd87b1d57902d186a8469c7baa34dee991f23a
|
7
|
+
data.tar.gz: ee8f293dbba3adc69a730d208b4973ebf7d9609d326bca03eda616ca668edfb792b2d4d9b09bef211a5c08db221da2befcd507d9d3f0844c5d8de1e774db46d8
|
data/README.md
CHANGED
@@ -121,6 +121,9 @@ end
|
|
121
121
|
```
|
122
122
|
|
123
123
|
3. ### Configure
|
124
|
+
Enqueuing of `BiddingCloserJob` (for each auction) is done by peridically performed `Auctify::EnsureAuctionsClosingJob`.
|
125
|
+
This is up to You how you run it, but interval between runs must be shorter than `Auctify.configuration.auction_prolonging_limit_in_seconds`.
|
126
|
+
|
124
127
|
- optional
|
125
128
|
```ruby
|
126
129
|
Auctify.configure do |config|
|
@@ -17,20 +17,14 @@ module Auctify
|
|
17
17
|
def bids
|
18
18
|
if params[:confirmation] == "1"
|
19
19
|
if @auction.bid!(new_bid)
|
20
|
-
if params[:dont_confirm_bids] == "1"
|
21
|
-
# use SQL update in case of some obscure invalid attributes
|
22
|
-
current_user.bidder_registrations
|
23
|
-
.where(auction: @auction)
|
24
|
-
.update_all(dont_confirm_bids: true)
|
25
|
-
end
|
26
|
-
|
27
20
|
@auction.reload
|
28
21
|
|
29
|
-
|
30
|
-
overbid_by_limit = winning_bid_id && new_bid.id && winning_bid_id != new_bid.id
|
22
|
+
store_dont_confirm_bids
|
31
23
|
|
32
|
-
render_record @auction, success: true, overbid_by_limit: overbid_by_limit
|
24
|
+
render_record @auction, success: true, overbid_by_limit: overbid_by_limit?(new_bid)
|
33
25
|
else
|
26
|
+
store_dont_confirm_bids
|
27
|
+
|
34
28
|
render_record @auction, bid: new_bid, status: 400
|
35
29
|
end
|
36
30
|
else
|
@@ -68,6 +62,23 @@ module Auctify
|
|
68
62
|
overbid_by_limit: overbid_by_limit).show
|
69
63
|
}, status: status
|
70
64
|
end
|
65
|
+
|
66
|
+
def store_dont_confirm_bids
|
67
|
+
if params[:dont_confirm_bids] == "1"
|
68
|
+
# use SQL update in case of some obscure invalid attributes
|
69
|
+
bidder_regs = current_user.bidder_registrations.where(auction: @auction)
|
70
|
+
bidder_regs.update_all(dont_confirm_bids: true) if bidder_regs.present?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def overbid_by_limit?(new_bid)
|
75
|
+
winning_bid = @auction&.winning_bid
|
76
|
+
return false unless winning_bid
|
77
|
+
return false if new_bid.id.blank? || winning_bid.id.blank?
|
78
|
+
return false if winning_bid.registration_id == new_bid.registration_id # do not notify bidder about overbidding itself
|
79
|
+
|
80
|
+
winning_bid != new_bid
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
@@ -9,7 +9,7 @@ module Auctify
|
|
9
9
|
.where("currently_ends_at <= ?", Time.current + checking_period_to_future)
|
10
10
|
auctions.each do |auction|
|
11
11
|
if auction.currently_ends_at <= Time.current
|
12
|
-
Auctify::BiddingCloserJob.
|
12
|
+
Auctify::BiddingCloserJob.perform_later(auction_id: auction.id)
|
13
13
|
else
|
14
14
|
Auctify::BiddingCloserJob.set(wait_until: auction.currently_ends_at).perform_later(auction_id: auction.id)
|
15
15
|
end
|
@@ -216,6 +216,14 @@ module Auctify
|
|
216
216
|
bidding_result.current_minimal_bid
|
217
217
|
end
|
218
218
|
|
219
|
+
def minimal_bid_increase_amount_at(price, respect_first_bid: true)
|
220
|
+
return 0 if respect_first_bid && ordered_applied_bids.blank? # first bid can equal opening price
|
221
|
+
return Auctify.configuration.require_bids_to_be_rounded_to if bid_steps_ladder.blank?
|
222
|
+
|
223
|
+
_range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
|
224
|
+
increase_step
|
225
|
+
end
|
226
|
+
|
219
227
|
def current_max_price_for(bidder, bids_array: nil)
|
220
228
|
bids_array ||= ordered_applied_bids.with_limit
|
221
229
|
|
@@ -45,17 +45,24 @@ module Auctify
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def dates_to_label
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
return "" unless start_date && end_date
|
49
|
+
|
50
|
+
date_strings = []
|
51
|
+
if start_date.year == end_date.year
|
52
|
+
if start_date.month == end_date.month
|
53
|
+
# all inside same month
|
54
|
+
date_strings << start_date.strftime("%-d.")
|
55
55
|
else
|
56
|
-
|
56
|
+
# all inside same year
|
57
|
+
date_strings << start_date.strftime("%-d. %-m.")
|
57
58
|
end
|
59
|
+
else
|
60
|
+
# crossing years border
|
61
|
+
date_strings << start_date.strftime("%-d. %-m. %Y")
|
58
62
|
end
|
63
|
+
|
64
|
+
date_strings << end_date.strftime("%-d. %-m. %Y")
|
65
|
+
date_strings.join(" – ")
|
59
66
|
end
|
60
67
|
|
61
68
|
def shift_sales_by_minutes!(shift_in_minutes)
|
@@ -46,8 +46,8 @@ module Auctify
|
|
46
46
|
def set_price_for_limit_bid
|
47
47
|
return unless bid.price.blank? && bid.with_limit?
|
48
48
|
|
49
|
-
if
|
50
|
-
bid.price = winning_bid.price
|
49
|
+
if changing_own_limit_when_winning?
|
50
|
+
bid.price = [bid.max_price, winning_bid.price].min
|
51
51
|
elsif bid.max_price <= new_current_minimal_bid
|
52
52
|
bid.price = bid.max_price
|
53
53
|
else
|
@@ -59,7 +59,8 @@ module Auctify
|
|
59
59
|
@approved_bid ||= begin
|
60
60
|
bid.valid?
|
61
61
|
check_bidder
|
62
|
-
|
62
|
+
check_max_price_increasing
|
63
|
+
check_price_minimum
|
63
64
|
check_same_bidder
|
64
65
|
check_auction_state
|
65
66
|
|
@@ -95,7 +96,6 @@ module Auctify
|
|
95
96
|
|
96
97
|
def new_current_minimal_bid
|
97
98
|
return current_price if first_bid?
|
98
|
-
|
99
99
|
increase_price(current_price)
|
100
100
|
end
|
101
101
|
|
@@ -132,11 +132,14 @@ module Auctify
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def check_max_price_increasing
|
135
|
-
|
135
|
+
return unless changing_own_limit_when_winning?
|
136
|
+
|
137
|
+
bid.errors.add(:bidder, :you_can_only_increase_your_max_price) if bid.max_price.to_i <= winning_bid.max_price.to_i
|
136
138
|
end
|
137
139
|
|
138
140
|
def check_price_minimum
|
139
|
-
|
141
|
+
minimum = changing_own_limit_when_winning? ? current_price : new_current_minimal_bid
|
142
|
+
if bid.price < minimum
|
140
143
|
att = bid.with_limit? ? :max_price : :price
|
141
144
|
bid.errors.add(att,
|
142
145
|
:price_is_bellow_minimal_bid,
|
@@ -145,7 +148,7 @@ module Auctify
|
|
145
148
|
end
|
146
149
|
|
147
150
|
def check_same_bidder
|
148
|
-
return if overbidding_yourself_allowed? ||
|
151
|
+
return if overbidding_yourself_allowed? || changing_own_limit_when_winning?
|
149
152
|
|
150
153
|
if winning_bid.present? && same_bidder?(winning_bid, bid)
|
151
154
|
bid.errors.add(:bidder, :you_cannot_overbid_yourself)
|
@@ -160,7 +163,7 @@ module Auctify
|
|
160
163
|
end
|
161
164
|
|
162
165
|
def solve_winner(winning_bid, new_bid)
|
163
|
-
return if winning_bid.blank? ||
|
166
|
+
return if winning_bid.blank? || changing_own_limit_when_winning?
|
164
167
|
|
165
168
|
solve_limits_fight(winning_bid, new_bid) if new_bid.with_limit? && winning_bid.with_limit?
|
166
169
|
increase_bid_price(winning_bid, new_bid) if new_bid.with_limit? && !winning_bid.with_limit?
|
@@ -206,10 +209,7 @@ module Auctify
|
|
206
209
|
end
|
207
210
|
|
208
211
|
def increase_price(price)
|
209
|
-
|
210
|
-
|
211
|
-
_range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
|
212
|
-
price + increase_step
|
212
|
+
price + auction.minimal_bid_increase_amount_at(price, respect_first_bid: false)
|
213
213
|
end
|
214
214
|
|
215
215
|
def increase_price_to(overcome:, ceil:)
|
@@ -224,11 +224,7 @@ module Auctify
|
|
224
224
|
[running_price, ceil].min
|
225
225
|
end
|
226
226
|
|
227
|
-
def
|
228
|
-
@bid_steps_ladder ||= auction.bid_steps_ladder
|
229
|
-
end
|
230
|
-
|
231
|
-
def changing_own_limit?
|
227
|
+
def changing_own_limit_when_winning?
|
232
228
|
bid.with_limit? && winning_bid.present? && (winning_bid.bidder == bid.bidder)
|
233
229
|
end
|
234
230
|
|
data/lib/auctify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auctify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- foton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|