auctify 1.1.0 → 1.1.1
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 +7 -0
- data/app/models/auctify/sales_pack.rb +15 -8
- data/app/services/auctify/bids_appender.rb +13 -16
- 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: '09cc89b7f5c014265e0835cc1b54bc021e2208e4e73a064fa16d1b61a297ff50'
|
4
|
+
data.tar.gz: 53be80f491b27a6ff5140c911e0add375f186605425633165a8230e7a7272aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b4f5e66bba941f327b588ca2ce32d0685f2c1a01b00ec6cb6b54bf866194fcbae189ee656f6acd734cbd275f512ddcbf0eb1755a9c54dbc5bf20d1fe3ad8af
|
7
|
+
data.tar.gz: 24a1abc0435f16e54f95abaf3f6eb183fb576ae5e1ce33fd46fcacb658950624cc761a0c3194c4f7788da5d4be16a5773b69a6d4345eef844e3ba8bf44219a31
|
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,13 @@ module Auctify
|
|
216
216
|
bidding_result.current_minimal_bid
|
217
217
|
end
|
218
218
|
|
219
|
+
def minimal_bid_increase_amount_at(price)
|
220
|
+
return Auctify.configuration.require_bids_to_be_rounded_to if bid_steps_ladder.blank?
|
221
|
+
|
222
|
+
_range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
|
223
|
+
increase_step
|
224
|
+
end
|
225
|
+
|
219
226
|
def current_max_price_for(bidder, bids_array: nil)
|
220
227
|
bids_array ||= ordered_applied_bids.with_limit
|
221
228
|
|
@@ -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
|
|
@@ -132,11 +133,14 @@ module Auctify
|
|
132
133
|
end
|
133
134
|
|
134
135
|
def check_max_price_increasing
|
135
|
-
|
136
|
+
return unless changing_own_limit_when_winning?
|
137
|
+
|
138
|
+
bid.errors.add(:bidder, :you_can_only_increase_your_max_price) if bid.max_price.to_i <= winning_bid.max_price.to_i
|
136
139
|
end
|
137
140
|
|
138
141
|
def check_price_minimum
|
139
|
-
|
142
|
+
minimum = changing_own_limit_when_winning? ? current_price : new_current_minimal_bid
|
143
|
+
if bid.price < minimum
|
140
144
|
att = bid.with_limit? ? :max_price : :price
|
141
145
|
bid.errors.add(att,
|
142
146
|
:price_is_bellow_minimal_bid,
|
@@ -145,7 +149,7 @@ module Auctify
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def check_same_bidder
|
148
|
-
return if overbidding_yourself_allowed? ||
|
152
|
+
return if overbidding_yourself_allowed? || changing_own_limit_when_winning?
|
149
153
|
|
150
154
|
if winning_bid.present? && same_bidder?(winning_bid, bid)
|
151
155
|
bid.errors.add(:bidder, :you_cannot_overbid_yourself)
|
@@ -160,7 +164,7 @@ module Auctify
|
|
160
164
|
end
|
161
165
|
|
162
166
|
def solve_winner(winning_bid, new_bid)
|
163
|
-
return if winning_bid.blank? ||
|
167
|
+
return if winning_bid.blank? || changing_own_limit_when_winning?
|
164
168
|
|
165
169
|
solve_limits_fight(winning_bid, new_bid) if new_bid.with_limit? && winning_bid.with_limit?
|
166
170
|
increase_bid_price(winning_bid, new_bid) if new_bid.with_limit? && !winning_bid.with_limit?
|
@@ -206,10 +210,7 @@ module Auctify
|
|
206
210
|
end
|
207
211
|
|
208
212
|
def increase_price(price)
|
209
|
-
|
210
|
-
|
211
|
-
_range, increase_step = bid_steps_ladder.detect { |range, step| range.cover?(price) }
|
212
|
-
price + increase_step
|
213
|
+
price + auction.minimal_bid_increase_amount_at(price)
|
213
214
|
end
|
214
215
|
|
215
216
|
def increase_price_to(overcome:, ceil:)
|
@@ -224,11 +225,7 @@ module Auctify
|
|
224
225
|
[running_price, ceil].min
|
225
226
|
end
|
226
227
|
|
227
|
-
def
|
228
|
-
@bid_steps_ladder ||= auction.bid_steps_ladder
|
229
|
-
end
|
230
|
-
|
231
|
-
def changing_own_limit?
|
228
|
+
def changing_own_limit_when_winning?
|
232
229
|
bid.with_limit? && winning_bid.present? && (winning_bid.bidder == bid.bidder)
|
233
230
|
end
|
234
231
|
|
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.1
|
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
|