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
@@ -3,7 +3,30 @@
3
3
  module AuctionFunCore
4
4
  module Repos
5
5
  module AuctionContext
6
- # SQL repository for auctions.
6
+ # Repository for handling repository operations related to auctions.
7
+ #
8
+ # This repository provides methods to interact with auction data in the database,
9
+ # including creating, updating, deleting, and retrieving auctions.
10
+ #
11
+ # @example
12
+ # auction_repo = AuctionFunCore::Repos::AuctionContext::AuctionRepository.new
13
+ #
14
+ # # Retrieve all auctions
15
+ # all_auctions = auction_repo.all
16
+ #
17
+ # # Get the total number of auctions
18
+ # total_auctions = auction_repo.count
19
+ #
20
+ # # Find an auction by its ID
21
+ # auction = auction_repo.by_id(123)
22
+ #
23
+ # # Find an auction by its ID and raise an error if not found
24
+ # auction = auction_repo.by_id!(123)
25
+ #
26
+ # @see AuctionFunCore::Entities::Auction Struct representing auction data
27
+ # @see https://rom-rb.org/learn/sql/3.3/queries/
28
+ # @see https://api.rom-rb.org/rom-sql/ROM/SQL/Relation/Reading
29
+ #
7
30
  class AuctionRepository < ROM::Repository[:auctions]
8
31
  include Import["container"]
9
32
 
@@ -11,28 +34,34 @@ module AuctionFunCore
11
34
  commands :create, update: :by_pk, delete: :by_pk
12
35
 
13
36
  # Returns all auctions in the database.
14
- # @return [Array<ROM::Struct::Auction>, []]
37
+ # @return [Array<ROM::Struct::Auction>]
15
38
  def all
16
39
  auctions.to_a
17
40
  end
18
41
 
19
- # Returns the total number of auctions in database.
20
- # @return [Integer]
42
+ # Returns the total number of auctions in the database.
43
+ #
44
+ # @return [Integer] Total number of auctions.
45
+ #
21
46
  def count
22
47
  auctions.count
23
48
  end
24
49
 
25
- # Search auction in database by primary key.
26
- # @param id [Integer] Auction ID
27
- # @return [ROM::Struct::Auction, nil]
50
+ # Retrieves an auction from the database by its primary key.
51
+ #
52
+ # @param id [Integer] The ID of the auction to retrieve.
53
+ # @return [ROM::Struct::Auction, nil] The retrieved auction, or nil if not found.
54
+ #
28
55
  def by_id(id)
29
56
  auctions.by_pk(id).one
30
57
  end
31
58
 
32
- # Search auction in database by primary key.
33
- # @param id [Integer] Auction ID
34
- # @raise [ROM::TupleCountMismatchError] if not found on database
35
- # @return [ROM::Struct::Auction]
59
+ # Retrieves an auction from the database by its primary key, raising an error if not found.
60
+ #
61
+ # @param id [Integer] The ID of the auction to retrieve.
62
+ # @raise [ROM::TupleCountMismatchError] if the auction is not found.
63
+ # @return [ROM::Struct::Auction] The retrieved auction.
64
+ #
36
65
  def by_id!(id)
37
66
  auctions.by_pk(id).one!
38
67
  end
@@ -3,21 +3,43 @@
3
3
  module AuctionFunCore
4
4
  module Repos
5
5
  module BidContext
6
- # SQL repository for bids.
6
+ # Repository for handling repository operations related to bids.
7
+ #
8
+ # This repository provides methods to interact with bid data in the database,
9
+ # including creating, updating, deleting, and retrieving bids.
10
+ #
11
+ # @example
12
+ # bid_repo = AuctionFunCore::Repos::BidContext::BidRepository.new
13
+ #
14
+ # # Get the total number of bids
15
+ # total_bids = bid_repo.count
16
+ #
17
+ # # Checks if a bid exists based on the provided conditions.
18
+ # bid_repo.exists?(id: 123)
19
+ #
20
+ # @see AuctionFunCore::Entities::Bid Struct representing bid data
21
+ # @see https://rom-rb.org/learn/sql/3.3/queries/
22
+ # @see https://api.rom-rb.org/rom-sql/ROM/SQL/Relation/Reading
23
+ #
7
24
  class BidRepository < ROM::Repository[:bids]
8
25
  include Import["container"]
9
26
 
10
27
  struct_namespace Entities
11
28
  commands :create, update: :by_pk, delete: :by_pk
12
29
 
13
- # Returns the total number of bids in database.
14
- # @return [Integer]
30
+ # Returns the total number of bids in the database.
31
+ #
32
+ # @return [Integer] Total number of bids.
33
+ #
15
34
  def count
16
35
  bids.count
17
36
  end
18
37
 
19
- # @param conditions [Hash] DSL Dataset
20
- # @return [Boolean]
38
+ # Checks if a bid exists based on the provided conditions.
39
+ #
40
+ # @param conditions [Hash] The conditions to check (DSL Dataset).
41
+ # @return [Boolean] true if a bid exists that matches the conditions, otherwise false.
42
+ #
21
43
  def exists?(conditions)
22
44
  bids.exist?(conditions)
23
45
  end
@@ -3,7 +3,41 @@
3
3
  module AuctionFunCore
4
4
  module Repos
5
5
  module StaffContext
6
- # SQL repository for staffs.
6
+ # Repository for handling repository operations related to staffs.
7
+ #
8
+ # This repository provides methods to interact with staff data in the database,
9
+ # including creating, updating, deleting, and retrieving staffs.
10
+ #
11
+ # @example
12
+ # staff_repo = AuctionFunCore::Repos::StaffContext::StaffRepository.new
13
+ #
14
+ # # Retrieve all staffs
15
+ # all_staffs = staff_repo.all
16
+ #
17
+ # # Get the total number of staffs
18
+ # total_staffs = staff_repo.count
19
+ #
20
+ # # Search staffs based on certain conditions
21
+ # conditions = {name: 'Staff'}
22
+ # search = staff_repo.query(conditions)
23
+ #
24
+ # # Find an staff by its ID
25
+ # staff = staff_repo.by_id(123)
26
+ #
27
+ # # Find an staff by its ID and raise an error if not found
28
+ # staff = staff_repo.by_id!(123)
29
+ #
30
+ # # Search for a staff by email or phone
31
+ # staff_by_login = staff_repo.by_login('example@example.com')
32
+ #
33
+ # # Check if a staff exists based on certain conditions
34
+ # conditions = { name: 'John Doe' }
35
+ # staff_exists = staff_repo.exists?(conditions)
36
+ #
37
+ # @see AuctionFunCore::Entities::Staff Struct representing staff data
38
+ # @see https://rom-rb.org/learn/sql/3.3/queries/
39
+ # @see https://api.rom-rb.org/rom-sql/ROM/SQL/Relation/Reading
40
+ #
7
41
  class StaffRepository < ROM::Repository[:staffs]
8
42
  include Import["container"]
9
43
 
@@ -11,50 +45,58 @@ module AuctionFunCore
11
45
  commands :create, update: :by_pk, delete: :by_pk
12
46
 
13
47
  # Returns all staffs in database.
14
- # @return [Array<ROM::Struct::Staff>, []]
48
+ # @return [Array<ROM::Struct::Staff>]
15
49
  def all
16
50
  staffs.to_a
17
51
  end
18
52
 
19
- # Returns the total number of staffs in database.
20
- # @return [Integer]
53
+ # Returns the total number of staffs in the database.
54
+ #
55
+ # @return [Integer] Total number of staffs.
21
56
  def count
22
57
  staffs.count
23
58
  end
24
59
 
25
- # Mount SQL conditions in query for search in database.
26
- # @param conditions [Hash] DSL Dataset
27
- # @return [AuctionFunCore::Relations::Staffs]
60
+ # Constructs SQL conditions for querying staffs in the database.
61
+ #
62
+ # @param conditions [Hash] The conditions to be used in the query (DSL Dataset).
63
+ # @return [AuctionFunCore::Relations::Staff] The relation containing the staffs that match the given conditions.
28
64
  def query(conditions)
29
65
  staffs.where(conditions)
30
66
  end
31
67
 
32
- # Search staff in database by primary key.
33
- # @param id [Integer] Staff ID
34
- # @return [ROM::Struct::Staff, nil]
68
+ # Retrieves an staff from the database by its primary key.
69
+ #
70
+ # @param id [Integer] The ID of the staff to retrieve.
71
+ # @return [ROM::Struct::Staff, nil] The retrieved staff, or nil if not found.
72
+ #
35
73
  def by_id(id)
36
74
  staffs.by_pk(id).one
37
75
  end
38
76
 
39
- # Search staffs in database by primary key.
40
- # @param id [Integer] Staff ID
41
- # @raise [ROM::TupleCountMismatchError] if not found on database
42
- # @return [ROM::Struct::Auction]
77
+ # Retrieves an staff from the database by its primary key, raising an error if not found.
78
+ #
79
+ # @param id [Integer] The ID of the staff to retrieve.
80
+ # @raise [ROM::TupleCountMismatchError] if the staff is not found.
81
+ # @return [ROM::Struct::Staff] The retrieved staff.
82
+ #
43
83
  def by_id!(id)
44
84
  staffs.by_pk(id).one!
45
85
  end
46
86
 
47
- # Search staff in database by email of phone keys.
48
- # @param login [String] Staff email or phone
49
- # @return [ROM::Struct::Staff, nil]
87
+ # Searches for a staff in the database by email or phone keys.
88
+ #
89
+ # @param login [String] The email or phone of the staff.
90
+ # @return [ROM::Struct::Staff, nil] The staff found with the provided email or phone,
91
+ # or nil if not found.
50
92
  def by_login(login)
51
93
  staffs.where(Sequel[email: login] | Sequel[phone: login]).one
52
94
  end
53
95
 
54
- # Checks if it returns any staff given one or more conditions.
55
- # @param conditions [Hash] DSL Dataset
56
- # @return [true] when some staff is returned from the given condition.
57
- # @return [false] when no staff is returned from the given condition.
96
+ # Checks if a bid exists based on the provided conditions.
97
+ #
98
+ # @param conditions [Hash] The conditions to check (DSL Dataset).
99
+ # @return [Boolean] true if a staff exists that matches the conditions, otherwise false.
58
100
  def exists?(conditions)
59
101
  staffs.exist?(conditions)
60
102
  end
@@ -3,7 +3,40 @@
3
3
  module AuctionFunCore
4
4
  module Repos
5
5
  module UserContext
6
- # SQL repository for users.
6
+ # Repository for handling repository operations related to users.
7
+ #
8
+ # This repository provides methods to interact with user data in the database,
9
+ # including creating, updating, deleting, and retrieving users.
10
+ #
11
+ # @example
12
+ # user_repo = AuctionFunCore::Repos::UserContext::UserRepository.new
13
+ #
14
+ # # Retrieve all users
15
+ # all_users = user_repo.all
16
+ #
17
+ # # Get the total number of users
18
+ # total_users = user_repo.count
19
+ #
20
+ # # Find a user by its ID
21
+ # user = user_repo.by_id(123)
22
+ #
23
+ # # Find a user by its ID and raise an error if not found
24
+ # user = user_repo.by_id!(123)
25
+ #
26
+ # # Search for a user by email or phone
27
+ # user = user_repo.by_login('example@example.com')
28
+ # user = user_repo.by_login('1234567890')
29
+ #
30
+ # # Search for a user by email confirmation token
31
+ # user = user_repo.by_email_confirmation_token('email_confirmation_token')
32
+ #
33
+ # # Search for a user by phone confirmation token
34
+ # user = user_repo.by_phone_confirmation_token('phone_confirmation_token')
35
+ #
36
+ # @see AuctionFunCore::Entities::User Struct representing user data
37
+ # @see https://rom-rb.org/learn/sql/3.3/queries/
38
+ # @see https://api.rom-rb.org/rom-sql/ROM/SQL/Relation/Reading
39
+ #
7
40
  class UserRepository < ROM::Repository[:users]
8
41
  include Import["container"]
9
42
 
@@ -11,7 +44,7 @@ module AuctionFunCore
11
44
  commands :create, update: :by_pk, delete: :by_pk
12
45
 
13
46
  # Returns all users in database.
14
- # @return [Array<ROM::Struct::User>, []]
47
+ # @return [Array<ROM::Struct::User>]
15
48
  def all
16
49
  users.to_a
17
50
  end
@@ -22,53 +55,64 @@ module AuctionFunCore
22
55
  users.count
23
56
  end
24
57
 
25
- # Mount SQL conditions in query for search in database.
26
- # @param conditions [Hash] DSL Dataset
27
- # @return [AuctionFunCore::Relations::Users]
58
+ # Constructs SQL conditions for querying users in the database.
59
+ #
60
+ # @param conditions [Hash] The conditions to be used in the query (DSL Dataset).
61
+ # @return [AuctionFunCore::Relations::Users] The relation containing the users that match the given conditions.
28
62
  def query(conditions)
29
63
  users.where(conditions)
30
64
  end
31
65
 
32
- # Search user in database by primary key.
33
- # @param id [Integer] User ID
34
- # @return [ROM::Struct::User, nil]
66
+ # Retrieves a user from the database by its primary key.
67
+ #
68
+ # @param id [Integer] The ID of the user to retrieve.
69
+ # @return [ROM::Struct::User, nil] The retrieved user, or nil if not found.
70
+ #
35
71
  def by_id(id)
36
72
  users.by_pk(id).one
37
73
  end
38
74
 
39
- # Search user in database by primary key.
40
- # @param id [Integer] User ID
41
- # @raise [ROM::TupleCountMismatchError] if not found on database
42
- # @return [ROM::Struct::Auction]
75
+ # Retrieves a user from the database by its primary key, raising an error if not found.
76
+ #
77
+ # @param id [Integer] The ID of the user to retrieve.
78
+ # @raise [ROM::TupleCountMismatchError] if the user is not found.
79
+ # @return [ROM::Struct::User] The retrieved user.
80
+ #
43
81
  def by_id!(id)
44
82
  users.by_pk(id).one!
45
83
  end
46
84
 
47
- # Search user in database by email of phone keys.
48
- # @param login [String] User email or phone
49
- # @return [ROM::Struct::User, nil]
85
+ # Searches for a user in the database by email or phone keys.
86
+ #
87
+ # @param login [String] The email or phone of the user.
88
+ # @return [ROM::Struct::User, nil] The user found with the provided email or phone,
89
+ # or nil if not found.
50
90
  def by_login(login)
51
91
  users.where(Sequel[email: login] | Sequel[phone: login]).one
52
92
  end
53
93
 
54
- # Search user in database by email_confirmation_token key.
55
- # @param email_confirmation_token [String] User email confirmation token
56
- # @return [ROM::Struct::User, nil]
94
+ # Searches for a user in the database by email confirmation token.
95
+ #
96
+ # @param email_confirmation_token [String] The email confirmation token of the user.
97
+ # @return [ROM::Struct::User, nil] The user found with the provided email confirmation token,
98
+ # or nil if not found.
57
99
  def by_email_confirmation_token(email_confirmation_token)
58
100
  users.where(Sequel[email_confirmation_token: email_confirmation_token]).one
59
101
  end
60
102
 
61
- # Search user in database by phone_confirmation_token of phone keys.
62
- # @param phone [String] User phone confirmation token
63
- # @return [ROM::Struct::User, nil]
103
+ # Searches for a user in the database by phone confirmation token.
104
+ #
105
+ # @param phone_confirmation_token [String] The phone confirmation token of the user.
106
+ # @return [ROM::Struct::User, nil] The user found with the provided phone confirmation token,
107
+ # or nil if not found.
64
108
  def by_phone_confirmation_token(phone_confirmation_token)
65
109
  users.where(Sequel[phone_confirmation_token: phone_confirmation_token]).one
66
110
  end
67
111
 
68
- # Checks if it returns any user given one or more conditions.
69
- # @param conditions [Hash] DSL Dataset
70
- # @return [true] when some user is returned from the given condition.
71
- # @return [false] when no user is returned from the given condition.
112
+ # Checks if a user exists based on the provided conditions.
113
+ #
114
+ # @param conditions [Hash] The conditions to check (DSL Dataset).
115
+ # @return [Boolean] true if a user exists that matches the conditions, otherwise false.
72
116
  def exists?(conditions)
73
117
  users.exist?(conditions)
74
118
  end
@@ -5,12 +5,15 @@ module AuctionFunCore
5
5
  module Mail
6
6
  module AuctionContext
7
7
  module PostAuction
8
+ # Service class responsible for sending emails to auction participants.
8
9
  class ParticipantMailer
9
10
  include IdleMailer::Mailer
10
11
  include IdleMailer::TemplateManager
11
12
 
13
+ # Initializes a new ParticipantMailer instance.
14
+ #
12
15
  # @param auction [ROM::Struct::Auction] The auction object
13
- # @param participant [ROM::Struct::User] The user object
16
+ # @param participant [ROM::Struct::User] The participant object
14
17
  # @param statistics [OpenStruct] Statistics object
15
18
  def initialize(auction, participant, statistics)
16
19
  @auction = auction
@@ -20,6 +23,9 @@ module AuctionFunCore
20
23
  mail.subject = I18n.t("mail.auction_context.post_auction.participant_mailer.subject", title: @auction.title)
21
24
  end
22
25
 
26
+ # Returns the template name for the ParticipantMailer.
27
+ #
28
+ # @return [String] The template name.
23
29
  def self.template_name
24
30
  IdleMailer.config.templates.join("auction_context/post_auction/participant")
25
31
  end
@@ -5,12 +5,15 @@ module AuctionFunCore
5
5
  module Mail
6
6
  module AuctionContext
7
7
  module PostAuction
8
+ # Service class responsible for sending emails to auction winners.
8
9
  class WinnerMailer
9
10
  include IdleMailer::Mailer
10
11
  include IdleMailer::TemplateManager
11
12
 
13
+ # Initializes a new WinnerMailer instance.
14
+ #
12
15
  # @param auction [ROM::Struct::Auction] The auction object
13
- # @param winner [ROM::Struct::User] The user object
16
+ # @param winner [ROM::Struct::User] The winner object
14
17
  # @param statistics [OpenStruct] Statistics object
15
18
  def initialize(auction, winner, statistics)
16
19
  @auction = auction
@@ -20,6 +23,9 @@ module AuctionFunCore
20
23
  mail.subject = I18n.t("mail.auction_context.post_auction.winner_mailer.subject", title: @auction.title)
21
24
  end
22
25
 
26
+ # Returns the template name for the WinnerMailer.
27
+ #
28
+ # @return [String] The template name.
23
29
  def self.template_name
24
30
  IdleMailer.config.templates.join("auction_context/post_auction/winner")
25
31
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuctionFunCore
4
+ module Services
5
+ module Mail
6
+ module AuctionContext
7
+ module PreAuction
8
+ # # Service class responsible for sending auction start reminder emails to participants.
9
+ class AuctionStartReminderMailer
10
+ include IdleMailer::Mailer
11
+ include IdleMailer::TemplateManager
12
+
13
+ # Initializes a new AuctionStartReminderMailer instance.
14
+ #
15
+ # @param auction [ROM::Struct::Auction] The auction object
16
+ # @param participant [ROM::Struct::User] The participant object
17
+ def initialize(auction, participant)
18
+ @auction = auction
19
+ @participant = participant
20
+ mail.to = participant.email
21
+ mail.subject = I18n.t("mail.auction_context.pre_auction.auction_start_reminder_mailer.subject", title: @auction.title)
22
+ end
23
+
24
+ # Returns the template name for the AuctionStartReminderMailer.
25
+ #
26
+ # @return [String] The template name.
27
+ def self.template_name
28
+ IdleMailer.config.templates.join("auction_context/pre_auction/auction_start_reminder")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -29,7 +29,7 @@
29
29
  <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
30
30
  <div style="font-family:Helvetica, Arial, sans-serif;font-size:18px;font-weight:400;line-height:24px;text-align:left;color:#434245;">
31
31
  <h1 style="margin: 0; font-size: 24px; line-height: normal; font-weight: bold;">
32
- <%= I18n.t("mail.general.hello", name: @participant.name) %>,
32
+ <%= I18n.t("application.general.hello", name: @participant.name) %>,
33
33
  </h1>
34
34
  </div>
35
35
  </td>
@@ -29,7 +29,7 @@
29
29
  <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
30
30
  <div style="font-family:Helvetica, Arial, sans-serif;font-size:18px;font-weight:400;line-height:24px;text-align:left;color:#434245;">
31
31
  <h1 style="margin: 0; font-size: 24px; line-height: normal; font-weight: bold;">
32
- <%= I18n.t("mail.general.hello", name: @winner.name) %>,
32
+ <%= I18n.t("application.general.hello", name: @winner.name) %>,
33
33
  </h1>
34
34
  </div>
35
35
  </td>