auction_fun_core 0.8.5 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/auction_fun_core.gemspec +1 -0
  4. data/db/migrate/20240229143000_create_auctions.rb +1 -0
  5. data/db/seeds.rb +87 -36
  6. data/i18n/en-US/contracts/contracts.en-US.yml +9 -0
  7. data/i18n/en-US/mail/application.en-US.yml +59 -0
  8. data/i18n/en-US/mail/auction_context/post_auction/participant.en-US.yml +13 -0
  9. data/i18n/en-US/mail/auction_context/post_auction/winner.en-US.yml +13 -0
  10. data/i18n/pt-BR/contracts/contracts.pt-BR.yml +9 -0
  11. data/i18n/pt-BR/mail/application.pt-BR.yml +59 -0
  12. data/i18n/pt-BR/mail/auction_context/post_auction/participant.pt-BR.yml +13 -0
  13. data/i18n/pt-BR/mail/auction_context/post_auction/winner.pt-BR.yml +13 -0
  14. data/i18n/pt-BR/mail/user_context/registration.pt-BR.yml +0 -4
  15. data/lib/auction_fun_core/contracts/auction_context/post_auction/participant_contract.rb +42 -0
  16. data/lib/auction_fun_core/contracts/auction_context/post_auction/winner_contract.rb +41 -0
  17. data/lib/auction_fun_core/contracts/auction_context/processor/finish/closed_contract.rb +47 -0
  18. data/lib/auction_fun_core/contracts/auction_context/processor/finish/penny_contract.rb +48 -0
  19. data/lib/auction_fun_core/contracts/auction_context/processor/finish/standard_contract.rb +48 -0
  20. data/lib/auction_fun_core/entities/auction.rb +6 -0
  21. data/lib/auction_fun_core/operations/auction_context/create_operation.rb +12 -2
  22. data/lib/auction_fun_core/operations/auction_context/post_auction/participant_operation.rb +52 -0
  23. data/lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb +51 -0
  24. data/lib/auction_fun_core/operations/auction_context/processor/finish/closed_operation.rb +100 -0
  25. data/lib/auction_fun_core/operations/auction_context/processor/finish/penny_operation.rb +100 -0
  26. data/lib/auction_fun_core/operations/auction_context/processor/finish/standard_operation.rb +102 -0
  27. data/lib/auction_fun_core/operations/auction_context/processor/start_operation.rb +23 -11
  28. data/lib/auction_fun_core/operations/bid_context/create_bid_penny_operation.rb +57 -7
  29. data/lib/auction_fun_core/operations/staff_context/registration_operation.rb +10 -0
  30. data/lib/auction_fun_core/relations/auctions.rb +167 -26
  31. data/lib/auction_fun_core/relations/staffs.rb +1 -1
  32. data/lib/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer.rb +31 -0
  33. data/lib/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer.rb +31 -0
  34. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/participant.html.erb +173 -0
  35. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/winner.html.erb +174 -0
  36. data/lib/auction_fun_core/services/mail/templates/user_context/registration.html.erb +2 -2
  37. data/lib/auction_fun_core/version.rb +1 -1
  38. data/lib/auction_fun_core/workers/application_job.rb +2 -0
  39. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/participant_operation_job.rb +33 -0
  40. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job.rb +33 -0
  41. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job.rb +34 -0
  42. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job.rb +37 -0
  43. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job.rb +34 -0
  44. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job.rb +51 -0
  45. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job.rb +51 -0
  46. data/system/providers/background_job.rb +19 -0
  47. metadata +43 -5
  48. data/lib/auction_fun_core/contracts/auction_context/processor/finish_contract.rb +0 -27
  49. data/lib/auction_fun_core/operations/auction_context/processor/finish_operation.rb +0 -61
  50. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish_operation_job.rb +0 -32
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AuctionFunCore
4
- module Contracts
5
- module AuctionContext
6
- module Processor
7
- ##
8
- # Contract class for finish auctions.
9
- #
10
- class FinishContract < Contracts::ApplicationContract
11
- option :auction_repo, default: proc { Repos::AuctionContext::AuctionRepository.new }
12
-
13
- params do
14
- required(:auction_id).filled(:integer)
15
- end
16
-
17
- # Validation for auction.
18
- # Validates if the auction exists in the database.
19
- rule(:auction_id) do |context:|
20
- context[:auction] ||= auction_repo.by_id(value)
21
- key.failure(I18n.t("contracts.errors.custom.not_found")) unless context[:auction]
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AuctionFunCore
4
- module Operations
5
- module AuctionContext
6
- module Processor
7
- ##
8
- # Operation class for dispatch finish auction.
9
- # By default, this change auction status from 'running' to 'finished'.
10
- #
11
- class FinishOperation < AuctionFunCore::Operations::Base
12
- include Import["repos.auction_context.auction_repository"]
13
- include Import["contracts.auction_context.processor.finish_contract"]
14
-
15
- # @todo Add custom doc
16
- def self.call(auction_id, &block)
17
- operation = new.call(auction_id)
18
-
19
- return operation unless block
20
-
21
- Dry::Matcher::ResultMatcher.call(operation, &block)
22
- end
23
-
24
- # It only performs the basic processing of completing an auction.
25
- # It just changes the status at the database level and triggers the finished event.
26
- # @param auction_id [Integer] Auction ID
27
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
28
- def call(auction_id)
29
- yield validate(auction_id: auction_id)
30
-
31
- auction_repository.transaction do |_t|
32
- @auction, _ = auction_repository.update(auction_id, status: "finished")
33
-
34
- publish_auction_finish_event(@auction)
35
- end
36
-
37
- Success(@auction)
38
- end
39
-
40
- private
41
-
42
- # Calls the finish contract class to perform the validation
43
- # of the informed attributes.
44
- # @param attributes [Hash] auction attributes
45
- # @return [Dry::Monads::Result::Success, Dry::Monads::Result::Failure]
46
- def validate(attributes)
47
- contract = finish_contract.call(attributes)
48
-
49
- return Failure(contract.errors.to_h) if contract.failure?
50
-
51
- Success(contract.to_h)
52
- end
53
-
54
- def publish_auction_finish_event(auction)
55
- Application[:event].publish("auctions.finished", auction.to_h)
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AuctionFunCore
4
- module Workers
5
- module Operations
6
- module AuctionContext
7
- module Processor
8
- ##
9
- # BackgroundJob class for call finish auction operation.
10
- #
11
- class FinishOperationJob < Workers::ApplicationJob
12
- include Import["repos.auction_context.auction_repository"]
13
- include Import["operations.auction_context.processor.finish_operation"]
14
-
15
- # @todo Add detailed documentation
16
- def perform(auction_id, retry_count = 0)
17
- auction = auction_repository.by_id!(auction_id)
18
-
19
- finish_operation.call(auction.id)
20
- rescue => e
21
- capture_exception(e, {auction_id: auction_id, retry_count: retry_count})
22
- raise if retry_count >= MAX_RETRIES
23
-
24
- interval = backoff_exponential_job(retry_count)
25
- self.class.perform_at(interval, auction_id, retry_count + 1)
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end