auction_fun_core 0.8.7 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +2 -0
- data/CHANGELOG.md +23 -0
- data/Procfile +1 -0
- data/README.md +34 -32
- data/Rakefile +1 -1
- data/i18n/en-US/contracts/contracts.en-US.yml +3 -0
- data/i18n/en-US/mail/application.en-US.yml +7 -0
- data/i18n/en-US/mail/auction_context/pre_auction/auction_start_reminder.en-US.yml +11 -0
- data/i18n/pt-BR/contracts/contracts.pt-BR.yml +3 -0
- data/i18n/pt-BR/mail/application.pt-BR.yml +7 -0
- data/i18n/pt-BR/mail/auction_context/pre_auction/auction_start_reminder.pt-BR.yml +11 -0
- data/lib/auction_fun_core/business/configuration.rb +31 -0
- data/lib/auction_fun_core/business/token_generator.rb +19 -1
- data/lib/auction_fun_core/contracts/application_contract.rb +9 -1
- data/lib/auction_fun_core/contracts/auction_context/create_contract.rb +35 -20
- data/lib/auction_fun_core/contracts/auction_context/post_auction/participant_contract.rb +23 -1
- data/lib/auction_fun_core/contracts/auction_context/post_auction/winner_contract.rb +22 -1
- data/lib/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract.rb +48 -0
- data/lib/auction_fun_core/contracts/auction_context/processor/finish/closed_contract.rb +19 -7
- data/lib/auction_fun_core/contracts/auction_context/processor/finish/penny_contract.rb +19 -7
- data/lib/auction_fun_core/contracts/auction_context/processor/finish/standard_contract.rb +19 -7
- data/lib/auction_fun_core/contracts/auction_context/processor/pause_contract.rb +16 -4
- data/lib/auction_fun_core/contracts/auction_context/processor/start_contract.rb +17 -5
- data/lib/auction_fun_core/contracts/auction_context/processor/unpause_contract.rb +16 -4
- data/lib/auction_fun_core/contracts/bid_context/create_bid_closed_contract.rb +20 -11
- data/lib/auction_fun_core/contracts/bid_context/create_bid_penny_contract.rb +18 -9
- data/lib/auction_fun_core/contracts/bid_context/create_bid_standard_contract.rb +19 -10
- data/lib/auction_fun_core/contracts/staff_context/authentication_contract.rb +18 -4
- data/lib/auction_fun_core/contracts/staff_context/registration_contract.rb +20 -8
- data/lib/auction_fun_core/contracts/user_context/authentication_contract.rb +18 -4
- data/lib/auction_fun_core/contracts/user_context/email_confirmation_contract.rb +17 -2
- data/lib/auction_fun_core/contracts/user_context/phone_confirmation_contract.rb +17 -2
- data/lib/auction_fun_core/contracts/user_context/registration_contract.rb +26 -8
- data/lib/auction_fun_core/entities/auction.rb +48 -4
- data/lib/auction_fun_core/entities/bid.rb +3 -2
- data/lib/auction_fun_core/entities/staff.rb +15 -2
- data/lib/auction_fun_core/entities/user.rb +31 -2
- data/lib/auction_fun_core/events/app.rb +8 -2
- data/lib/auction_fun_core/events/listener.rb +19 -16
- data/lib/auction_fun_core/operations/auction_context/create_operation.rb +25 -9
- data/lib/auction_fun_core/operations/auction_context/post_auction/participant_operation.rb +36 -3
- data/lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb +36 -2
- data/lib/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb +96 -0
- data/lib/auction_fun_core/operations/auction_context/processor/finish/closed_operation.rb +82 -10
- data/lib/auction_fun_core/operations/auction_context/processor/finish/penny_operation.rb +81 -10
- data/lib/auction_fun_core/operations/auction_context/processor/finish/standard_operation.rb +81 -12
- data/lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb +36 -1
- data/lib/auction_fun_core/operations/auction_context/processor/unpause_operation.rb +36 -1
- data/lib/auction_fun_core/relations/auctions.rb +178 -97
- data/lib/auction_fun_core/relations/bids.rb +18 -0
- data/lib/auction_fun_core/repos/auction_context/auction_repository.rb +40 -11
- data/lib/auction_fun_core/repos/bid_context/bid_repository.rb +27 -5
- data/lib/auction_fun_core/repos/staff_context/staff_repository.rb +63 -21
- data/lib/auction_fun_core/repos/user_context/user_repository.rb +69 -25
- data/lib/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer.rb +7 -1
- data/lib/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer.rb +7 -1
- data/lib/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer.rb +35 -0
- data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/participant.html.erb +1 -1
- data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/winner.html.erb +1 -1
- data/lib/auction_fun_core/services/mail/templates/auction_context/pre_auction/auction_start_reminder.html.erb +192 -0
- data/lib/auction_fun_core/services/mail/user_context/registration_mailer.rb +6 -0
- data/lib/auction_fun_core/version.rb +1 -1
- data/lib/auction_fun_core/workers/application_job.rb +10 -0
- data/lib/auction_fun_core/workers/operations/auction_context/post_auction/participant_operation_job.rb +7 -2
- data/lib/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job.rb +6 -2
- data/lib/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job.rb +44 -0
- data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job.rb +6 -3
- data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job.rb +6 -3
- data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job.rb +6 -2
- data/lib/auction_fun_core/workers/operations/auction_context/processor/start_operation_job.rb +6 -3
- data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job.rb +12 -7
- data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job.rb +11 -5
- data/lib/auction_fun_core/workers/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_job.rb +48 -0
- data/lib/auction_fun_core/workers/services/mail/user_context/registration_mailer_job.rb +8 -6
- data/system/providers/background_job.rb +6 -0
- metadata +10 -2
@@ -5,13 +5,29 @@ module AuctionFunCore
|
|
5
5
|
module AuctionContext
|
6
6
|
module PostAuction
|
7
7
|
##
|
8
|
-
# Operation class for
|
8
|
+
# Operation class for managing winners in auctions.
|
9
9
|
#
|
10
10
|
class WinnerOperation < AuctionFunCore::Operations::Base
|
11
11
|
include Import["repos.user_context.user_repository"]
|
12
12
|
include Import["contracts.auction_context.post_auction.winner_contract"]
|
13
13
|
include Import["workers.services.mail.auction_context.post_auction.winner_mailer_job"]
|
14
14
|
|
15
|
+
##
|
16
|
+
# Executes the winner operation with the provided attributes.
|
17
|
+
#
|
18
|
+
# @param attributes [Hash] The attributes for the winner operation.
|
19
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
20
|
+
# @option attributes winner_id [Integer] The winning user ID
|
21
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
22
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# attributes = { auction_id: 123, winner_id: 123 }
|
26
|
+
#
|
27
|
+
# AuctionFunCore::Operations::AuctionContext::PostAuction::WinnerOperation.call(attributes) do |result|
|
28
|
+
# result.success { |auction| puts "Winner operation completed successfully! #{auction.to_h}" }
|
29
|
+
# result.failure { |failure| puts "Failed auction winner operation: #{failure.errors.to_h}"}
|
30
|
+
# end
|
15
31
|
def self.call(attributes, &block)
|
16
32
|
operation = new.call(attributes)
|
17
33
|
|
@@ -20,7 +36,12 @@ module AuctionFunCore
|
|
20
36
|
Dry::Matcher::ResultMatcher.call(operation, &block)
|
21
37
|
end
|
22
38
|
|
23
|
-
##
|
39
|
+
##
|
40
|
+
# Executes the winner operation.
|
41
|
+
#
|
42
|
+
# @param attributes [Hash] The attributes for the winner operation.
|
43
|
+
# @return [Dry::Monads::Result] The result of the operation.
|
44
|
+
#
|
24
45
|
def call(attributes)
|
25
46
|
auction, winner = yield validate_contract(attributes)
|
26
47
|
|
@@ -33,6 +54,12 @@ module AuctionFunCore
|
|
33
54
|
|
34
55
|
private
|
35
56
|
|
57
|
+
##
|
58
|
+
# Validates the contract with the provided attributes.
|
59
|
+
#
|
60
|
+
# @param attributes [Hash] The attributes to validate.
|
61
|
+
# @return [Dry::Monads::Result] The result of the validation.
|
62
|
+
#
|
36
63
|
def validate_contract(attributes)
|
37
64
|
contract = winner_contract.call(attributes)
|
38
65
|
|
@@ -41,6 +68,13 @@ module AuctionFunCore
|
|
41
68
|
Success([contract.context[:auction], contract.context[:winner]])
|
42
69
|
end
|
43
70
|
|
71
|
+
##
|
72
|
+
# Sends winner email with auction statistics and payment instructions.
|
73
|
+
#
|
74
|
+
# @param auction_id [Integer] The ID of the auction.
|
75
|
+
# @param winner_id [Integer] The ID of the winner.
|
76
|
+
# @return [Dry::Monads::Result] The result of sending the email.
|
77
|
+
#
|
44
78
|
def send_winner_email_with_statistics_and_payment_instructions(auction_id, winner_id)
|
45
79
|
Success(winner_mailer_job.class.perform_async(auction_id, winner_id))
|
46
80
|
end
|
data/lib/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuctionFunCore
|
4
|
+
module Operations
|
5
|
+
module AuctionContext
|
6
|
+
module PreAuction
|
7
|
+
##
|
8
|
+
# Operation class for sending a reminder email to a participant about the start of an auction.
|
9
|
+
#
|
10
|
+
class AuctionStartReminderOperation < AuctionFunCore::Operations::Base
|
11
|
+
include Import["repos.bid_context.bid_repository"]
|
12
|
+
include Import["contracts.auction_context.pre_auction.auction_start_reminder_contract"]
|
13
|
+
include Import["workers.services.mail.auction_context.pre_auction.auction_start_reminder_mailer_job"]
|
14
|
+
|
15
|
+
##
|
16
|
+
# Executes the auction start reminder operation with the provided attributes.
|
17
|
+
#
|
18
|
+
# @param attributes [Hash] The attributes for the auction start reminder operation.
|
19
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
20
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
21
|
+
#
|
22
|
+
def self.call(attributes, &block)
|
23
|
+
operation = new.call(attributes)
|
24
|
+
|
25
|
+
return operation unless block
|
26
|
+
|
27
|
+
Dry::Matcher::ResultMatcher.call(operation, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Executes the auction start reminder operation.
|
32
|
+
#
|
33
|
+
# @param attributes [Hash] The attributes for the auction start reminder operation.
|
34
|
+
# @return [Dry::Monads::Result] The result of the operation.
|
35
|
+
#
|
36
|
+
def call(attributes)
|
37
|
+
auction = yield validate_contract(attributes)
|
38
|
+
participant_ids = yield collect_current_auction_participants(auction.id)
|
39
|
+
|
40
|
+
bid_repository.transaction do |_t|
|
41
|
+
participant_ids.each do |participant_id|
|
42
|
+
yield send_auction_start_reminder_mailer_job(auction.id, participant_id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Success([auction, participant_ids])
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
##
|
52
|
+
# Validates the contract with the provided attributes.
|
53
|
+
#
|
54
|
+
# @param attributes [Hash] The attributes to validate.
|
55
|
+
# @option auction_id [Integer] The ID of the auction.
|
56
|
+
# @return [Dry::Monads::Result] The result of the validation.
|
57
|
+
#
|
58
|
+
def validate_contract(attributes)
|
59
|
+
contract = auction_start_reminder_contract.call(attributes)
|
60
|
+
|
61
|
+
return Failure(contract.errors.to_h) if contract.failure?
|
62
|
+
|
63
|
+
Success(contract.context[:auction])
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Collects the participant IDs for the current auction.
|
68
|
+
#
|
69
|
+
# @param auction_id [Integer] The ID of the auction.
|
70
|
+
# @return [Dry::Monads::Result] The result of collecting the participant IDs.
|
71
|
+
#
|
72
|
+
def collect_current_auction_participants(auction_id)
|
73
|
+
Success(
|
74
|
+
AuctionFunCore::Application[:container]
|
75
|
+
.relations[:bids]
|
76
|
+
.participants(auction_id)
|
77
|
+
.one
|
78
|
+
.participant_ids.to_a
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Sends the auction start reminder email to a participant.
|
84
|
+
#
|
85
|
+
# @param auction_id [Integer] The ID of the auction.
|
86
|
+
# @param participant_id [Integer] The ID of the participant.
|
87
|
+
# @return [Dry::Monads::Result] The result of sending the email.
|
88
|
+
#
|
89
|
+
def send_auction_start_reminder_mailer_job(auction_id, participant_id)
|
90
|
+
Success(auction_start_reminder_mailer_job.class.perform_async(auction_id, participant_id))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -7,7 +7,7 @@ module AuctionFunCore
|
|
7
7
|
module Finish
|
8
8
|
##
|
9
9
|
# Operation class for finalizing a closed auction.
|
10
|
-
# By default, this
|
10
|
+
# By default, this changes the auction status from 'running' to 'finished'.
|
11
11
|
#
|
12
12
|
class ClosedOperation < AuctionFunCore::Operations::Base
|
13
13
|
include Import["repos.auction_context.auction_repository"]
|
@@ -15,7 +15,21 @@ module AuctionFunCore
|
|
15
15
|
include Import["workers.operations.auction_context.post_auction.winner_operation_job"]
|
16
16
|
include Import["workers.operations.auction_context.post_auction.participant_operation_job"]
|
17
17
|
|
18
|
-
|
18
|
+
##
|
19
|
+
# Executes the closed operation with the provided attributes.
|
20
|
+
#
|
21
|
+
# @param attributes [Hash] The attributes for the closed operation.
|
22
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
23
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
24
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# attributes = { auction_id: 123 }
|
28
|
+
#
|
29
|
+
# AuctionFunCore::Operations::AuctionContext::Processor::Finish::ClosedOperation.call(attributes) do |result|
|
30
|
+
# result.success { |auction| puts "Finished closed auction sucessfully! #{auction.to_h}" }
|
31
|
+
# result.failure { |failure| puts "Failed to finished closed auction: #{failure.errors.to_h}"}
|
32
|
+
# end
|
19
33
|
def self.call(attributes, &block)
|
20
34
|
operation = new.call(attributes)
|
21
35
|
|
@@ -24,10 +38,27 @@ module AuctionFunCore
|
|
24
38
|
Dry::Matcher::ResultMatcher.call(operation, &block)
|
25
39
|
end
|
26
40
|
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# @
|
41
|
+
##
|
42
|
+
# Performs the closing of a closed auction.
|
43
|
+
#
|
44
|
+
# @param attributes [Hash] The attributes for the closed operation.
|
45
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
46
|
+
# @return [Dry::Monads::Result] The result of the operation.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# attributes = { auction_id: 123 }
|
50
|
+
#
|
51
|
+
# operation = AuctionFunCore::Operations::AuctionContext::Processor::Finish::ClosedOperation.call(attributes)
|
52
|
+
#
|
53
|
+
# if operation.success?
|
54
|
+
# auction = operation.success
|
55
|
+
# puts "Finished closed auction sucessfully! #{auction.to_h}"
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# if operation.failure?
|
59
|
+
# failure = operation.failure
|
60
|
+
# puts "Failed to finished closed auction: #{failure.errors.to_h}"
|
61
|
+
# end
|
31
62
|
def call(attributes)
|
32
63
|
auction = yield validate_contract(attributes)
|
33
64
|
summary = yield load_closed_auction_winners_and_participants(auction.id)
|
@@ -50,10 +81,13 @@ module AuctionFunCore
|
|
50
81
|
|
51
82
|
private
|
52
83
|
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @
|
84
|
+
##
|
85
|
+
# Validates the contract with the provided attributes.
|
86
|
+
#
|
87
|
+
# @param attributes [Hash] The attributes to validate.
|
88
|
+
# @option auction_id [Integer] The ID of the auction.
|
89
|
+
# @return [Dry::Monads::Result] The result of the validation.
|
90
|
+
#
|
57
91
|
def validate_contract(attributes)
|
58
92
|
contract = closed_contract.call(attributes)
|
59
93
|
|
@@ -62,12 +96,25 @@ module AuctionFunCore
|
|
62
96
|
Success(contract.context[:auction])
|
63
97
|
end
|
64
98
|
|
99
|
+
##
|
100
|
+
# Loads the winners and participants of the closed auction.
|
101
|
+
#
|
102
|
+
# @param auction_id [Integer] The ID of the auction.
|
103
|
+
# @return [Dry::Monads::Result] The result of loading the winners and participants.
|
104
|
+
#
|
65
105
|
def load_closed_auction_winners_and_participants(auction_id)
|
66
106
|
summary = relation.load_closed_auction_winners_and_participants(auction_id).first
|
67
107
|
|
68
108
|
Success(summary)
|
69
109
|
end
|
70
110
|
|
111
|
+
##
|
112
|
+
# Updates the attributes of the finished auction.
|
113
|
+
#
|
114
|
+
# @param auction [Auction] The auction object.
|
115
|
+
# @param summary [Summary] The summary of winners and participants.
|
116
|
+
# @return [Dry::Monads::Result] The result of updating the attributes.
|
117
|
+
#
|
71
118
|
def update_finished_auction(auction, summary)
|
72
119
|
attrs = {status: "finished"}
|
73
120
|
attrs[:winner_id] = summary.winner_id if summary.winner_id.present?
|
@@ -75,20 +122,45 @@ module AuctionFunCore
|
|
75
122
|
Success(attrs)
|
76
123
|
end
|
77
124
|
|
125
|
+
##
|
126
|
+
# Retrieves the relation.
|
127
|
+
#
|
128
|
+
# @return [ROM::Relation] The relation object.
|
129
|
+
#
|
78
130
|
def relation
|
79
131
|
AuctionFunCore::Application[:container].relations[:auctions]
|
80
132
|
end
|
81
133
|
|
134
|
+
##
|
135
|
+
# Executes the winner operation asynchronously.
|
136
|
+
#
|
137
|
+
# @param auction_id [Integer] The ID of the auction.
|
138
|
+
# @param winner_id [Integer] The ID of the winner.
|
139
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
140
|
+
#
|
82
141
|
def winner_operation(auction_id, winner_id)
|
83
142
|
return Success() if winner_id.blank?
|
84
143
|
|
85
144
|
Success(winner_operation_job.class.perform_async(auction_id, winner_id))
|
86
145
|
end
|
87
146
|
|
147
|
+
##
|
148
|
+
# Executes the participant operation asynchronously.
|
149
|
+
#
|
150
|
+
# @param auction_id [Integer] The ID of the auction.
|
151
|
+
# @param participant_id [Integer] The ID of the participant.
|
152
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
153
|
+
#
|
88
154
|
def participant_operation(auction_id, participant_id)
|
89
155
|
Success(participant_operation_job.class.perform_async(auction_id, participant_id))
|
90
156
|
end
|
91
157
|
|
158
|
+
##
|
159
|
+
# Publishes the auction finish event.
|
160
|
+
#
|
161
|
+
# @param auction [ROM::Struct::Auction] The auction object.
|
162
|
+
# @return [void]
|
163
|
+
#
|
92
164
|
def publish_auction_finish_event(auction)
|
93
165
|
Application[:event].publish("auctions.finished", auction.to_h)
|
94
166
|
end
|
@@ -7,7 +7,7 @@ module AuctionFunCore
|
|
7
7
|
module Finish
|
8
8
|
##
|
9
9
|
# Operation class for finalizing a penny auction.
|
10
|
-
# By default, this
|
10
|
+
# By default, this changes the auction status from 'running' to 'finished'.
|
11
11
|
#
|
12
12
|
class PennyOperation < AuctionFunCore::Operations::Base
|
13
13
|
include Import["repos.auction_context.auction_repository"]
|
@@ -15,7 +15,21 @@ module AuctionFunCore
|
|
15
15
|
include Import["workers.operations.auction_context.post_auction.winner_operation_job"]
|
16
16
|
include Import["workers.operations.auction_context.post_auction.participant_operation_job"]
|
17
17
|
|
18
|
-
|
18
|
+
##
|
19
|
+
# Executes the penny operation with the provided attributes.
|
20
|
+
#
|
21
|
+
# @param attributes [Hash] The attributes for the penny operation.
|
22
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
23
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
24
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# attributes = { auction_id: 123 }
|
28
|
+
#
|
29
|
+
# AuctionFunCore::Operations::AuctionContext::Processor::Finish::PennyOperation.call(attributes) do |result|
|
30
|
+
# result.success { |auction| puts "Finished penny auction sucessfully! #{auction.to_h}" }
|
31
|
+
# result.failure { |failure| puts "Failed to finished penny auction: #{failure.errors.to_h}"}
|
32
|
+
# end
|
19
33
|
def self.call(attributes, &block)
|
20
34
|
operation = new.call(attributes)
|
21
35
|
|
@@ -24,10 +38,27 @@ module AuctionFunCore
|
|
24
38
|
Dry::Matcher::ResultMatcher.call(operation, &block)
|
25
39
|
end
|
26
40
|
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# @
|
41
|
+
##
|
42
|
+
# Performs the closing of a penny auction.
|
43
|
+
#
|
44
|
+
# @param attributes [Hash] The attributes for the penny operation.
|
45
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
46
|
+
# @return [Dry::Monads::Result] The result of the operation.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# attributes = { auction_id: 123 }
|
50
|
+
#
|
51
|
+
# operation = AuctionFunCore::Operations::AuctionContext::Processor::Finish::PennyOperation.call(attributes)
|
52
|
+
#
|
53
|
+
# if operation.success?
|
54
|
+
# auction = operation.success
|
55
|
+
# puts "Finished penny auction sucessfully! #{auction.to_h}"
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# if operation.failure?
|
59
|
+
# failure = operation.failure
|
60
|
+
# puts "Failed to finished penny auction: #{failure.errors.to_h}"
|
61
|
+
# end
|
31
62
|
def call(attributes)
|
32
63
|
auction = yield validate_contract(attributes)
|
33
64
|
summary = yield load_penny_auction_winners_and_participants(auction.id)
|
@@ -50,10 +81,12 @@ module AuctionFunCore
|
|
50
81
|
|
51
82
|
private
|
52
83
|
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @
|
84
|
+
##
|
85
|
+
# Validates the contract with the provided attributes.
|
86
|
+
#
|
87
|
+
# @param attributes [Hash] The attributes to validate.
|
88
|
+
# @return [Dry::Monads::Result] The result of the validation.
|
89
|
+
#
|
57
90
|
def validate_contract(attributes)
|
58
91
|
contract = penny_contract.call(attributes)
|
59
92
|
|
@@ -62,12 +95,25 @@ module AuctionFunCore
|
|
62
95
|
Success(contract.context[:auction])
|
63
96
|
end
|
64
97
|
|
98
|
+
##
|
99
|
+
# Loads the winners and participants of the penny auction.
|
100
|
+
#
|
101
|
+
# @param auction_id [Integer] The ID of the auction.
|
102
|
+
# @return [Dry::Monads::Result] The result of loading the winners and participants.
|
103
|
+
#
|
65
104
|
def load_penny_auction_winners_and_participants(auction_id)
|
66
105
|
summary = relation.load_penny_auction_winners_and_participants(auction_id).first
|
67
106
|
|
68
107
|
Success(summary)
|
69
108
|
end
|
70
109
|
|
110
|
+
##
|
111
|
+
# Updates the attributes of the finished auction.
|
112
|
+
#
|
113
|
+
# @param auction [ROM::Struct::Auction] The auction object.
|
114
|
+
# @param summary [ROM::OpenStruct] The summary of winners and participants.
|
115
|
+
# @return [Dry::Monads::Result] The result of updating the attributes.
|
116
|
+
#
|
71
117
|
def update_finished_auction(auction, summary)
|
72
118
|
attrs = {status: "finished"}
|
73
119
|
attrs[:winner_id] = summary.winner_id if summary.winner_id.present?
|
@@ -75,20 +121,45 @@ module AuctionFunCore
|
|
75
121
|
Success(attrs)
|
76
122
|
end
|
77
123
|
|
124
|
+
##
|
125
|
+
# Retrieves the relation.
|
126
|
+
#
|
127
|
+
# @return [ROM::Relation] The relation object.
|
128
|
+
#
|
78
129
|
def relation
|
79
130
|
AuctionFunCore::Application[:container].relations[:auctions]
|
80
131
|
end
|
81
132
|
|
133
|
+
##
|
134
|
+
# Executes the winner operation asynchronously.
|
135
|
+
#
|
136
|
+
# @param auction_id [Integer] The ID of the auction.
|
137
|
+
# @param winner_id [Integer] The ID of the winner.
|
138
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
139
|
+
#
|
82
140
|
def winner_operation(auction_id, winner_id)
|
83
141
|
return Success() if winner_id.blank?
|
84
142
|
|
85
143
|
Success(winner_operation_job.class.perform_async(auction_id, winner_id))
|
86
144
|
end
|
87
145
|
|
146
|
+
##
|
147
|
+
# Executes the participant operation asynchronously.
|
148
|
+
#
|
149
|
+
# @param auction_id [Integer] The ID of the auction.
|
150
|
+
# @param participant_id [Integer] The ID of the participant.
|
151
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
152
|
+
#
|
88
153
|
def participant_operation(auction_id, participant_id)
|
89
154
|
Success(participant_operation_job.class.perform_async(auction_id, participant_id))
|
90
155
|
end
|
91
156
|
|
157
|
+
##
|
158
|
+
# Publishes the auction finish event.
|
159
|
+
#
|
160
|
+
# @param auction [ROM::Struct::Auction] The auction object.
|
161
|
+
# @return [void]
|
162
|
+
#
|
92
163
|
def publish_auction_finish_event(auction)
|
93
164
|
Application[:event].publish("auctions.finished", auction.to_h)
|
94
165
|
end
|
@@ -7,7 +7,7 @@ module AuctionFunCore
|
|
7
7
|
module Finish
|
8
8
|
##
|
9
9
|
# Operation class for finalizing a standard auction.
|
10
|
-
# By default, this
|
10
|
+
# By default, this changes the auction status from 'running' to 'finished'.
|
11
11
|
#
|
12
12
|
class StandardOperation < AuctionFunCore::Operations::Base
|
13
13
|
include Import["repos.auction_context.auction_repository"]
|
@@ -15,7 +15,21 @@ module AuctionFunCore
|
|
15
15
|
include Import["workers.operations.auction_context.post_auction.winner_operation_job"]
|
16
16
|
include Import["workers.operations.auction_context.post_auction.participant_operation_job"]
|
17
17
|
|
18
|
-
|
18
|
+
##
|
19
|
+
# Executes the standard operation with the provided attributes.
|
20
|
+
#
|
21
|
+
# @param attributes [Hash] The attributes for the standard operation.
|
22
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
23
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
24
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# attributes = { auction_id: 123 }
|
28
|
+
#
|
29
|
+
# AuctionFunCore::Operations::AuctionContext::Processor::Finish::StandardOperation.call(attributes) do |result|
|
30
|
+
# result.success { |auction| puts "Finished standard auction sucessfully! #{auction.to_h}" }
|
31
|
+
# result.failure { |failure| puts "Failed to finished standard auction: #{failure.errors.to_h}"}
|
32
|
+
# end
|
19
33
|
def self.call(attributes, &block)
|
20
34
|
operation = new.call(attributes)
|
21
35
|
|
@@ -24,12 +38,27 @@ module AuctionFunCore
|
|
24
38
|
Dry::Matcher::ResultMatcher.call(operation, &block)
|
25
39
|
end
|
26
40
|
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# @param
|
31
|
-
# @option auction_id [Integer]
|
32
|
-
# @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
|
41
|
+
##
|
42
|
+
# Performs the closing of a standard auction.
|
43
|
+
#
|
44
|
+
# @param attributes [Hash] The attributes for the standard operation.
|
45
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
46
|
+
# @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure] The result of the operation.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# attributes = { auction_id: 123 }
|
50
|
+
#
|
51
|
+
# operation = AuctionFunCore::Operations::AuctionContext::Processor::Finish::StandardOperation.call(attributes)
|
52
|
+
#
|
53
|
+
# if operation.success?
|
54
|
+
# auction = operation.success
|
55
|
+
# puts "Finished standard auction sucessfully! #{auction.to_h}"
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# if operation.failure?
|
59
|
+
# failure = operation.failure
|
60
|
+
# puts "Failed to finished standard auction: #{failure.errors.to_h}"
|
61
|
+
# end
|
33
62
|
def call(attributes)
|
34
63
|
auction = yield validate_contract(attributes)
|
35
64
|
summary = yield load_standard_auction_winners_and_participants(auction.id)
|
@@ -52,10 +81,12 @@ module AuctionFunCore
|
|
52
81
|
|
53
82
|
private
|
54
83
|
|
55
|
-
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# @
|
84
|
+
##
|
85
|
+
# Validates the contract with the provided attributes.
|
86
|
+
#
|
87
|
+
# @param attributes [Hash] The attributes to validate.
|
88
|
+
# @return [Dry::Monads::Result] The result of the validation.
|
89
|
+
#
|
59
90
|
def validate_contract(attributes)
|
60
91
|
contract = standard_contract.call(attributes)
|
61
92
|
|
@@ -64,12 +95,25 @@ module AuctionFunCore
|
|
64
95
|
Success(contract.context[:auction])
|
65
96
|
end
|
66
97
|
|
98
|
+
##
|
99
|
+
# Loads the winners and participants of the standard auction.
|
100
|
+
#
|
101
|
+
# @param auction_id [Integer] The ID of the auction.
|
102
|
+
# @return [Dry::Monads::Result] The result of loading the winners and participants.
|
103
|
+
#
|
67
104
|
def load_standard_auction_winners_and_participants(auction_id)
|
68
105
|
summary = relation.load_standard_auction_winners_and_participants(auction_id).first
|
69
106
|
|
70
107
|
Success(summary)
|
71
108
|
end
|
72
109
|
|
110
|
+
##
|
111
|
+
# Updates the attributes of the finished auction.
|
112
|
+
#
|
113
|
+
# @param auction [Auction] The auction object.
|
114
|
+
# @param summary [Summary] The summary of winners and participants.
|
115
|
+
# @return [Dry::Monads::Result] The result of updating the attributes.
|
116
|
+
#
|
73
117
|
def update_finished_auction(auction, summary)
|
74
118
|
attrs = {status: "finished"}
|
75
119
|
attrs[:winner_id] = summary.winner_id if summary.winner_id.present?
|
@@ -77,20 +121,45 @@ module AuctionFunCore
|
|
77
121
|
Success(attrs)
|
78
122
|
end
|
79
123
|
|
124
|
+
##
|
125
|
+
# Retrieves the relation.
|
126
|
+
#
|
127
|
+
# @return [ROM::Relation] The relation object.
|
128
|
+
#
|
80
129
|
def relation
|
81
130
|
AuctionFunCore::Application[:container].relations[:auctions]
|
82
131
|
end
|
83
132
|
|
133
|
+
##
|
134
|
+
# Executes the winner operation asynchronously.
|
135
|
+
#
|
136
|
+
# @param auction_id [Integer] The ID of the auction.
|
137
|
+
# @param winner_id [Integer] The ID of the winner.
|
138
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
139
|
+
#
|
84
140
|
def winner_operation(auction_id, winner_id)
|
85
141
|
return Success() if winner_id.blank?
|
86
142
|
|
87
143
|
Success(winner_operation_job.class.perform_async(auction_id, winner_id))
|
88
144
|
end
|
89
145
|
|
146
|
+
##
|
147
|
+
# Executes the participant operation asynchronously.
|
148
|
+
#
|
149
|
+
# @param auction_id [Integer] The ID of the auction.
|
150
|
+
# @param participant_id [Integer] The ID of the participant.
|
151
|
+
# @return [Dry::Monads::Result] The result of executing the operation.
|
152
|
+
#
|
90
153
|
def participant_operation(auction_id, participant_id)
|
91
154
|
Success(participant_operation_job.class.perform_async(auction_id, participant_id))
|
92
155
|
end
|
93
156
|
|
157
|
+
##
|
158
|
+
# Publishes the auction finish event.
|
159
|
+
#
|
160
|
+
# @param auction [ROM::Struct::Auction] The auction object.
|
161
|
+
# @return [void]
|
162
|
+
#
|
94
163
|
def publish_auction_finish_event(auction)
|
95
164
|
Application[:event].publish("auctions.finished", auction.to_h)
|
96
165
|
end
|
@@ -12,7 +12,21 @@ module AuctionFunCore
|
|
12
12
|
include Import["repos.auction_context.auction_repository"]
|
13
13
|
include Import["contracts.auction_context.processor.pause_contract"]
|
14
14
|
|
15
|
-
|
15
|
+
##
|
16
|
+
# Executes the pause operation with the provided attributes.
|
17
|
+
#
|
18
|
+
# @param attributes [Hash] The attributes for the pause operation.
|
19
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
20
|
+
# @yield [Dry::Matcher::Evaluator] The block to handle the result of the operation.
|
21
|
+
# @return [Dry::Matcher::Evaluator] The result of the operation.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# attributes = { auction_id: 123 }
|
25
|
+
#
|
26
|
+
# AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation.call(attributes) do |result|
|
27
|
+
# result.success { |auction| puts "Paused auction sucessfully! #{auction.to_h}" }
|
28
|
+
# result.failure { |failure| puts "Failed to pause auction: #{failure.errors.to_h}"}
|
29
|
+
# end
|
16
30
|
def self.call(attributes, &block)
|
17
31
|
operation = new.call(attributes)
|
18
32
|
|
@@ -21,6 +35,27 @@ module AuctionFunCore
|
|
21
35
|
Dry::Matcher::ResultMatcher.call(operation, &block)
|
22
36
|
end
|
23
37
|
|
38
|
+
##
|
39
|
+
# Performing an auction pause
|
40
|
+
#
|
41
|
+
# @param attributes [Hash] The attributes for the pause operation.
|
42
|
+
# @option attributes auction_id [Integer] The ID of the auction.
|
43
|
+
# @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure] The result of the operation.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# attributes = { auction_id: 123 }
|
47
|
+
#
|
48
|
+
# operation = AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation.call(attributes)
|
49
|
+
#
|
50
|
+
# if operation.success?
|
51
|
+
# auction = operation.success
|
52
|
+
# puts "Paused auction sucessfully! #{auction.to_h}"
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# if operation.failure?
|
56
|
+
# failure = operation.failure
|
57
|
+
# puts "Failed to pause auction: #{failure.errors.to_h}"
|
58
|
+
# end
|
24
59
|
def call(attributes)
|
25
60
|
attrs = yield validate(attributes)
|
26
61
|
|