auction_fun_core 0.8.7 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +2 -0
  3. data/CHANGELOG.md +29 -0
  4. data/Procfile +1 -0
  5. data/README.md +34 -32
  6. data/Rakefile +1 -1
  7. data/auction_fun_core.gemspec +1 -1
  8. data/i18n/en-US/contracts/contracts.en-US.yml +3 -0
  9. data/i18n/en-US/mail/application.en-US.yml +7 -0
  10. data/i18n/en-US/mail/auction_context/pre_auction/auction_start_reminder.en-US.yml +11 -0
  11. data/i18n/pt-BR/contracts/contracts.pt-BR.yml +3 -0
  12. data/i18n/pt-BR/mail/application.pt-BR.yml +7 -0
  13. data/i18n/pt-BR/mail/auction_context/pre_auction/auction_start_reminder.pt-BR.yml +11 -0
  14. data/lib/auction_fun_core/business/configuration.rb +31 -0
  15. data/lib/auction_fun_core/business/token_generator.rb +19 -1
  16. data/lib/auction_fun_core/contracts/application_contract.rb +9 -1
  17. data/lib/auction_fun_core/contracts/auction_context/create_contract.rb +35 -20
  18. data/lib/auction_fun_core/contracts/auction_context/post_auction/participant_contract.rb +23 -1
  19. data/lib/auction_fun_core/contracts/auction_context/post_auction/winner_contract.rb +22 -1
  20. data/lib/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract.rb +48 -0
  21. data/lib/auction_fun_core/contracts/auction_context/processor/finish/closed_contract.rb +19 -7
  22. data/lib/auction_fun_core/contracts/auction_context/processor/finish/penny_contract.rb +19 -7
  23. data/lib/auction_fun_core/contracts/auction_context/processor/finish/standard_contract.rb +19 -7
  24. data/lib/auction_fun_core/contracts/auction_context/processor/pause_contract.rb +16 -4
  25. data/lib/auction_fun_core/contracts/auction_context/processor/start_contract.rb +17 -5
  26. data/lib/auction_fun_core/contracts/auction_context/processor/unpause_contract.rb +16 -4
  27. data/lib/auction_fun_core/contracts/bid_context/create_bid_closed_contract.rb +20 -11
  28. data/lib/auction_fun_core/contracts/bid_context/create_bid_penny_contract.rb +18 -9
  29. data/lib/auction_fun_core/contracts/bid_context/create_bid_standard_contract.rb +19 -10
  30. data/lib/auction_fun_core/contracts/staff_context/authentication_contract.rb +18 -4
  31. data/lib/auction_fun_core/contracts/staff_context/registration_contract.rb +20 -8
  32. data/lib/auction_fun_core/contracts/user_context/authentication_contract.rb +18 -4
  33. data/lib/auction_fun_core/contracts/user_context/email_confirmation_contract.rb +17 -2
  34. data/lib/auction_fun_core/contracts/user_context/phone_confirmation_contract.rb +17 -2
  35. data/lib/auction_fun_core/contracts/user_context/registration_contract.rb +26 -8
  36. data/lib/auction_fun_core/entities/auction.rb +48 -4
  37. data/lib/auction_fun_core/entities/bid.rb +3 -2
  38. data/lib/auction_fun_core/entities/staff.rb +15 -2
  39. data/lib/auction_fun_core/entities/user.rb +31 -2
  40. data/lib/auction_fun_core/events/app.rb +8 -2
  41. data/lib/auction_fun_core/events/listener.rb +19 -16
  42. data/lib/auction_fun_core/operations/auction_context/create_operation.rb +25 -9
  43. data/lib/auction_fun_core/operations/auction_context/post_auction/participant_operation.rb +36 -3
  44. data/lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb +36 -2
  45. data/lib/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb +96 -0
  46. data/lib/auction_fun_core/operations/auction_context/processor/finish/closed_operation.rb +82 -10
  47. data/lib/auction_fun_core/operations/auction_context/processor/finish/penny_operation.rb +81 -10
  48. data/lib/auction_fun_core/operations/auction_context/processor/finish/standard_operation.rb +81 -12
  49. data/lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb +36 -1
  50. data/lib/auction_fun_core/operations/auction_context/processor/unpause_operation.rb +36 -1
  51. data/lib/auction_fun_core/relations/auctions.rb +178 -97
  52. data/lib/auction_fun_core/relations/bids.rb +18 -0
  53. data/lib/auction_fun_core/repos/auction_context/auction_repository.rb +40 -11
  54. data/lib/auction_fun_core/repos/bid_context/bid_repository.rb +27 -5
  55. data/lib/auction_fun_core/repos/staff_context/staff_repository.rb +63 -21
  56. data/lib/auction_fun_core/repos/user_context/user_repository.rb +69 -25
  57. data/lib/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer.rb +7 -1
  58. data/lib/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer.rb +7 -1
  59. data/lib/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer.rb +35 -0
  60. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/participant.html.erb +1 -1
  61. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/winner.html.erb +1 -1
  62. data/lib/auction_fun_core/services/mail/templates/auction_context/pre_auction/auction_start_reminder.html.erb +192 -0
  63. data/lib/auction_fun_core/services/mail/user_context/registration_mailer.rb +6 -0
  64. data/lib/auction_fun_core/version.rb +1 -1
  65. data/lib/auction_fun_core/workers/application_job.rb +10 -0
  66. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/participant_operation_job.rb +7 -2
  67. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job.rb +6 -2
  68. data/lib/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job.rb +44 -0
  69. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job.rb +6 -3
  70. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job.rb +6 -3
  71. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job.rb +6 -2
  72. data/lib/auction_fun_core/workers/operations/auction_context/processor/start_operation_job.rb +6 -3
  73. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job.rb +12 -7
  74. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job.rb +11 -5
  75. data/lib/auction_fun_core/workers/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_job.rb +48 -0
  76. data/lib/auction_fun_core/workers/services/mail/user_context/registration_mailer_job.rb +8 -6
  77. data/spec/auction_fun_core/contracts/auction_context/create_contract_spec.rb +158 -0
  78. data/spec/auction_fun_core/contracts/auction_context/post_auction/participant_contract_spec.rb +77 -0
  79. data/spec/auction_fun_core/contracts/auction_context/post_auction/winner_contract_spec.rb +76 -0
  80. data/spec/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract_spec.rb +48 -0
  81. data/spec/auction_fun_core/contracts/auction_context/processor/finish/closed_contract_spec.rb +59 -0
  82. data/spec/auction_fun_core/contracts/auction_context/processor/finish/penny_contract_spec.rb +59 -0
  83. data/spec/auction_fun_core/contracts/auction_context/processor/finish/standard_contract_spec.rb +59 -0
  84. data/spec/auction_fun_core/contracts/auction_context/processor/pause_contract_spec.rb +39 -0
  85. data/spec/auction_fun_core/contracts/auction_context/processor/start_contract_spec.rb +59 -0
  86. data/spec/auction_fun_core/contracts/auction_context/processor/unpause_contract_spec.rb +39 -0
  87. data/spec/auction_fun_core/contracts/bid_context/create_bid_closed_contract_spec.rb +130 -0
  88. data/spec/auction_fun_core/contracts/bid_context/create_bid_penny_contract_spec.rb +118 -0
  89. data/spec/auction_fun_core/contracts/bid_context/create_bid_standard_contract_spec.rb +154 -0
  90. data/spec/auction_fun_core/contracts/staff_context/authentication_contract_spec.rb +89 -0
  91. data/spec/auction_fun_core/contracts/staff_context/registration_contract_spec.rb +24 -0
  92. data/spec/auction_fun_core/contracts/user_context/authentication_contract_spec.rb +89 -0
  93. data/spec/auction_fun_core/contracts/user_context/email_confirmation_contract_spec.rb +54 -0
  94. data/spec/auction_fun_core/contracts/user_context/phone_confirmation_contract_spec.rb +54 -0
  95. data/spec/auction_fun_core/contracts/user_context/registration_contract_spec.rb +27 -0
  96. data/spec/auction_fun_core/entities/auction_spec.rb +75 -0
  97. data/spec/auction_fun_core/entities/bid_spec.rb +7 -0
  98. data/spec/auction_fun_core/entities/staff_spec.rb +38 -0
  99. data/spec/auction_fun_core/entities/user_spec.rb +106 -0
  100. data/spec/auction_fun_core/operations/auction_context/create_operation_spec.rb +126 -0
  101. data/spec/auction_fun_core/operations/auction_context/post_auction/participant_operation_spec.rb +88 -0
  102. data/spec/auction_fun_core/operations/auction_context/post_auction/winner_operation_spec.rb +76 -0
  103. data/spec/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation_spec.rb +98 -0
  104. data/spec/auction_fun_core/operations/auction_context/processor/finish/closed_operation_spec.rb +107 -0
  105. data/spec/auction_fun_core/operations/auction_context/processor/finish/penny_operation_spec.rb +107 -0
  106. data/spec/auction_fun_core/operations/auction_context/processor/finish/standard_operation_spec.rb +106 -0
  107. data/spec/auction_fun_core/operations/auction_context/processor/pause_operation_spec.rb +83 -0
  108. data/spec/auction_fun_core/operations/auction_context/processor/start_operation_spec.rb +147 -0
  109. data/spec/auction_fun_core/operations/auction_context/processor/unpause_operation_spec.rb +80 -0
  110. data/spec/auction_fun_core/operations/bid_context/create_bid_closed_operation_spec.rb +95 -0
  111. data/spec/auction_fun_core/operations/bid_context/create_bid_penny_operation_spec.rb +133 -0
  112. data/spec/auction_fun_core/operations/bid_context/create_bid_standard_operation_spec.rb +95 -0
  113. data/spec/auction_fun_core/operations/staff_context/authentication_operation_spec.rb +74 -0
  114. data/spec/auction_fun_core/operations/staff_context/registration_operation_spec.rb +93 -0
  115. data/spec/auction_fun_core/operations/user_context/authentication_operation_spec.rb +74 -0
  116. data/spec/auction_fun_core/operations/user_context/email_confirmation_operation_spec.rb +76 -0
  117. data/spec/auction_fun_core/operations/user_context/phone_confirmation_operation_spec.rb +76 -0
  118. data/spec/auction_fun_core/operations/user_context/registration_operation_spec.rb +100 -0
  119. data/spec/auction_fun_core/relations/auctions_spec.rb +471 -0
  120. data/spec/auction_fun_core/repos/auction_context/auction_repository_spec.rb +64 -0
  121. data/spec/auction_fun_core/repos/bid_context/bid_repository_spec.rb +64 -0
  122. data/spec/auction_fun_core/repos/staff_context/staff_repository_spec.rb +118 -0
  123. data/spec/auction_fun_core/repos/user_context/user_repository_spec.rb +117 -0
  124. data/spec/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer_spec.rb +48 -0
  125. data/spec/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer_spec.rb +48 -0
  126. data/spec/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_spec.rb +40 -0
  127. data/spec/auction_fun_core/services/mail/user_context/registration_mailer_spec.rb +33 -0
  128. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/participation_operation_job_spec.rb +54 -0
  129. data/spec/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job_spec.rb +48 -0
  130. data/spec/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job_spec.rb +53 -0
  131. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job_spec.rb +47 -0
  132. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job_spec.rb +47 -0
  133. data/spec/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job_spec.rb +47 -0
  134. data/spec/auction_fun_core/workers/operations/auction_context/processor/start_operation_job_spec.rb +47 -0
  135. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job_spec.rb +62 -0
  136. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/pre_auction/auction_start_reminder_mailer_job_spec.rb +59 -0
  137. data/spec/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job_spec.rb +62 -0
  138. data/spec/auction_fun_core/workers/services/mail/user_context/registration_mailer_job_spec.rb +53 -0
  139. data/spec/auction_fun_core_spec.rb +7 -0
  140. data/spec/spec_helper.rb +61 -0
  141. data/spec/support/background_job.rb +7 -0
  142. data/spec/support/factories/auctions.rb +143 -0
  143. data/spec/support/factories/bids.rb +6 -0
  144. data/spec/support/factories/staffs.rb +18 -0
  145. data/spec/support/factories/users.rb +43 -0
  146. data/spec/support/faker.rb +6 -0
  147. data/spec/support/mail.rb +13 -0
  148. data/spec/support/shared_examples/validate_email_contract.rb +25 -0
  149. data/spec/support/shared_examples/validate_name_contract.rb +19 -0
  150. data/spec/support/shared_examples/validate_password_confirmation_contract.rb +16 -0
  151. data/spec/support/shared_examples/validate_password_contract.rb +18 -0
  152. data/spec/support/shared_examples/validate_phone_contract.rb +25 -0
  153. data/spec/support/shared_examples/validate_stopwatch_contract.rb +32 -0
  154. data/system/providers/background_job.rb +6 -0
  155. metadata +87 -2
@@ -5,13 +5,29 @@ module AuctionFunCore
5
5
  module AuctionContext
6
6
  module PostAuction
7
7
  ##
8
- # Operation class for finish auctions.
8
+ # Operation class for managing participants in auctions.
9
9
  #
10
10
  class ParticipantOperation < AuctionFunCore::Operations::Base
11
11
  include Import["repos.user_context.user_repository"]
12
12
  include Import["contracts.auction_context.post_auction.participant_contract"]
13
13
  include Import["workers.services.mail.auction_context.post_auction.participant_mailer_job"]
14
14
 
15
+ ##
16
+ # Executes the participant 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 participant_id [Integer] The participating 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, participant_id: 123 }
26
+ #
27
+ # AuctionFunCore::Operations::AuctionContext::PostAuction::ParticipantOperation.call(attributes) do |result|
28
+ # result.success { |auction| puts "Participation operation completed successfully! #{auction.to_h}" }
29
+ # result.failure { |failure| puts "Failed auction participation operation: #{failure.errors.to_h}"}
30
+ # end
15
31
  def self.call(attributes, &block)
16
32
  operation = new.call(attributes)
17
33
 
@@ -20,8 +36,12 @@ module AuctionFunCore
20
36
  Dry::Matcher::ResultMatcher.call(operation, &block)
21
37
  end
22
38
 
23
- ## @todo Add more actions
24
- # Send email to participant with auction statistics.
39
+ ##
40
+ # Executes the participant operation.
41
+ #
42
+ # @param attributes [Hash] The attributes for the participant operation.
43
+ # @return [Dry::Monads::Result] The result of the operation.
44
+ #
25
45
  def call(attributes)
26
46
  auction, participant = yield validate_contract(attributes)
27
47
 
@@ -34,6 +54,12 @@ module AuctionFunCore
34
54
 
35
55
  private
36
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
+ #
37
63
  def validate_contract(attributes)
38
64
  contract = participant_contract.call(attributes)
39
65
 
@@ -42,6 +68,13 @@ module AuctionFunCore
42
68
  Success([contract.context[:auction], contract.context[:participant]])
43
69
  end
44
70
 
71
+ ##
72
+ # Sends participant email with auction statistics and payment instructions.
73
+ #
74
+ # @param auction_id [Integer] The ID of the auction.
75
+ # @param participant_id [Integer] The ID of the participant.
76
+ # @return [Dry::Monads::Result] The result of sending the email.
77
+ #
45
78
  def send_participant_email_with_statistics_and_payment_instructions(auction_id, participant_id)
46
79
  Success(participant_mailer_job.class.perform_async(auction_id, participant_id))
47
80
  end
@@ -5,13 +5,29 @@ module AuctionFunCore
5
5
  module AuctionContext
6
6
  module PostAuction
7
7
  ##
8
- # Operation class for finish auctions.
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
- ## @todo Add doc
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
@@ -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 change auction status from 'running' to 'finished'.
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
- # @todo Add custom doc
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
- # It only performs the basic processing of completing an auction.
28
- # It just changes the status at the database level and triggers the finished event.
29
- # @param auction_id [Integer] Auction ID
30
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
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
- # Calls the finish contract class to perform the validation
54
- # of the informed attributes.
55
- # @param attributes [Hash] auction attributes
56
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
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 change auction status from 'running' to 'finished'.
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
- # @todo Add custom doc
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
- # It only performs the basic processing of completing an auction.
28
- # It just changes the status at the database level and triggers the finished event.
29
- # @param auction_id [Integer] Auction ID
30
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
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
- # Calls the finish contract class to perform the validation
54
- # of the informed attributes.
55
- # @param attributes [Hash] auction attributes
56
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
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