auction_fun_core 0.8.5 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +2 -0
  3. data/CHANGELOG.md +48 -0
  4. data/Procfile +1 -0
  5. data/README.md +34 -32
  6. data/Rakefile +1 -1
  7. data/auction_fun_core.gemspec +1 -0
  8. data/db/migrate/20240229143000_create_auctions.rb +1 -0
  9. data/db/seeds.rb +87 -36
  10. data/i18n/en-US/contracts/contracts.en-US.yml +12 -0
  11. data/i18n/en-US/mail/application.en-US.yml +66 -0
  12. data/i18n/en-US/mail/auction_context/post_auction/participant.en-US.yml +13 -0
  13. data/i18n/en-US/mail/auction_context/post_auction/winner.en-US.yml +13 -0
  14. data/i18n/en-US/mail/auction_context/pre_auction/auction_start_reminder.en-US.yml +11 -0
  15. data/i18n/pt-BR/contracts/contracts.pt-BR.yml +12 -0
  16. data/i18n/pt-BR/mail/application.pt-BR.yml +66 -0
  17. data/i18n/pt-BR/mail/auction_context/post_auction/participant.pt-BR.yml +13 -0
  18. data/i18n/pt-BR/mail/auction_context/post_auction/winner.pt-BR.yml +13 -0
  19. data/i18n/pt-BR/mail/auction_context/pre_auction/auction_start_reminder.pt-BR.yml +11 -0
  20. data/i18n/pt-BR/mail/user_context/registration.pt-BR.yml +0 -4
  21. data/lib/auction_fun_core/business/configuration.rb +31 -0
  22. data/lib/auction_fun_core/business/token_generator.rb +19 -1
  23. data/lib/auction_fun_core/contracts/application_contract.rb +9 -1
  24. data/lib/auction_fun_core/contracts/auction_context/create_contract.rb +35 -20
  25. data/lib/auction_fun_core/contracts/auction_context/post_auction/participant_contract.rb +64 -0
  26. data/lib/auction_fun_core/contracts/auction_context/post_auction/winner_contract.rb +62 -0
  27. data/lib/auction_fun_core/contracts/auction_context/pre_auction/auction_start_reminder_contract.rb +48 -0
  28. data/lib/auction_fun_core/contracts/auction_context/processor/finish/closed_contract.rb +59 -0
  29. data/lib/auction_fun_core/contracts/auction_context/processor/finish/penny_contract.rb +60 -0
  30. data/lib/auction_fun_core/contracts/auction_context/processor/finish/standard_contract.rb +60 -0
  31. data/lib/auction_fun_core/contracts/auction_context/processor/pause_contract.rb +16 -4
  32. data/lib/auction_fun_core/contracts/auction_context/processor/start_contract.rb +17 -5
  33. data/lib/auction_fun_core/contracts/auction_context/processor/unpause_contract.rb +16 -4
  34. data/lib/auction_fun_core/contracts/bid_context/create_bid_closed_contract.rb +20 -11
  35. data/lib/auction_fun_core/contracts/bid_context/create_bid_penny_contract.rb +18 -9
  36. data/lib/auction_fun_core/contracts/bid_context/create_bid_standard_contract.rb +19 -10
  37. data/lib/auction_fun_core/contracts/staff_context/authentication_contract.rb +18 -4
  38. data/lib/auction_fun_core/contracts/staff_context/registration_contract.rb +20 -8
  39. data/lib/auction_fun_core/contracts/user_context/authentication_contract.rb +18 -4
  40. data/lib/auction_fun_core/contracts/user_context/email_confirmation_contract.rb +17 -2
  41. data/lib/auction_fun_core/contracts/user_context/phone_confirmation_contract.rb +17 -2
  42. data/lib/auction_fun_core/contracts/user_context/registration_contract.rb +26 -8
  43. data/lib/auction_fun_core/entities/auction.rb +52 -2
  44. data/lib/auction_fun_core/entities/bid.rb +3 -2
  45. data/lib/auction_fun_core/entities/staff.rb +15 -2
  46. data/lib/auction_fun_core/entities/user.rb +31 -2
  47. data/lib/auction_fun_core/events/app.rb +8 -2
  48. data/lib/auction_fun_core/events/listener.rb +19 -16
  49. data/lib/auction_fun_core/operations/auction_context/create_operation.rb +37 -11
  50. data/lib/auction_fun_core/operations/auction_context/post_auction/participant_operation.rb +85 -0
  51. data/lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb +85 -0
  52. data/lib/auction_fun_core/operations/auction_context/pre_auction/auction_start_reminder_operation.rb +96 -0
  53. data/lib/auction_fun_core/operations/auction_context/processor/finish/closed_operation.rb +172 -0
  54. data/lib/auction_fun_core/operations/auction_context/processor/finish/penny_operation.rb +171 -0
  55. data/lib/auction_fun_core/operations/auction_context/processor/finish/standard_operation.rb +171 -0
  56. data/lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb +36 -1
  57. data/lib/auction_fun_core/operations/auction_context/processor/start_operation.rb +23 -11
  58. data/lib/auction_fun_core/operations/auction_context/processor/unpause_operation.rb +36 -1
  59. data/lib/auction_fun_core/operations/bid_context/create_bid_penny_operation.rb +57 -7
  60. data/lib/auction_fun_core/operations/staff_context/registration_operation.rb +10 -0
  61. data/lib/auction_fun_core/relations/auctions.rb +252 -30
  62. data/lib/auction_fun_core/relations/bids.rb +18 -0
  63. data/lib/auction_fun_core/relations/staffs.rb +1 -1
  64. data/lib/auction_fun_core/repos/auction_context/auction_repository.rb +40 -11
  65. data/lib/auction_fun_core/repos/bid_context/bid_repository.rb +27 -5
  66. data/lib/auction_fun_core/repos/staff_context/staff_repository.rb +63 -21
  67. data/lib/auction_fun_core/repos/user_context/user_repository.rb +69 -25
  68. data/lib/auction_fun_core/services/mail/auction_context/post_auction/participant_mailer.rb +37 -0
  69. data/lib/auction_fun_core/services/mail/auction_context/post_auction/winner_mailer.rb +37 -0
  70. data/lib/auction_fun_core/services/mail/auction_context/pre_auction/auction_start_reminder_mailer.rb +35 -0
  71. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/participant.html.erb +173 -0
  72. data/lib/auction_fun_core/services/mail/templates/auction_context/post_auction/winner.html.erb +174 -0
  73. data/lib/auction_fun_core/services/mail/templates/auction_context/pre_auction/auction_start_reminder.html.erb +192 -0
  74. data/lib/auction_fun_core/services/mail/templates/user_context/registration.html.erb +2 -2
  75. data/lib/auction_fun_core/services/mail/user_context/registration_mailer.rb +6 -0
  76. data/lib/auction_fun_core/version.rb +1 -1
  77. data/lib/auction_fun_core/workers/application_job.rb +12 -0
  78. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/participant_operation_job.rb +38 -0
  79. data/lib/auction_fun_core/workers/operations/auction_context/post_auction/winner_operation_job.rb +37 -0
  80. data/lib/auction_fun_core/workers/operations/auction_context/pre_auction/auction_start_reminder_operation_job.rb +44 -0
  81. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/closed_operation_job.rb +37 -0
  82. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/penny_operation_job.rb +40 -0
  83. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish/standard_operation_job.rb +38 -0
  84. data/lib/auction_fun_core/workers/operations/auction_context/processor/start_operation_job.rb +6 -3
  85. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/participant_mailer_job.rb +56 -0
  86. data/lib/auction_fun_core/workers/services/mail/auction_context/post_auction/winner_mailer_job.rb +57 -0
  87. data/lib/auction_fun_core/workers/services/mail/auction_context/pre_auction/auction_start_reminder_mailer_job.rb +48 -0
  88. data/lib/auction_fun_core/workers/services/mail/user_context/registration_mailer_job.rb +8 -6
  89. data/system/providers/background_job.rb +25 -0
  90. metadata +51 -5
  91. data/lib/auction_fun_core/contracts/auction_context/processor/finish_contract.rb +0 -27
  92. data/lib/auction_fun_core/operations/auction_context/processor/finish_operation.rb +0 -61
  93. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish_operation_job.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b42434481eccb486a4e38674f4219b1969e8951bd0a06430066a2ca9e9c9931d
4
- data.tar.gz: a243a07a6b63c1e9a10f17a616290b1eea8c825af4a5e1a47e7f4f3515e192c6
3
+ metadata.gz: a93057cdc62225a319b45c2836b5cfd713935664c8a7d9bdf2d39678909dacc7
4
+ data.tar.gz: 87f51a7eb83f0b47bc13394c36e37f36821a8ef5f4c429ec18e272155d9a1261
5
5
  SHA512:
6
- metadata.gz: 6a3d12e06b32f527e2744f996b14716e32e6f496a5367452eeeae62425a34c7a90878c2f256e901a9a165b00325838f0bba29526580d02dc65d0240c4444d2f8
7
- data.tar.gz: 4dcaa1d26811cdab77368cc5eb5567b83a5cf647e9f123ecaed217e41e908e7f1ea6e56a5fcfccc6410f04e9ba91b054fe282c41a7c7b1b5806556006f76e703
6
+ metadata.gz: 70b11f00396f1195ae8e7060eb8316141abbe3e3f30621d80769d94b63b4d1469695b6ca0a35a9910419e7579f047b2bd9d4f7a3ad469803cf47cb3aae4efc75
7
+ data.tar.gz: 520de3854f324a0e79bca1c4bfdfe69288077e208de37831b3c25cd84e75acb2664f79cf87372cee2ffb4a4a3800398b0fd72c537cb83a330b925c2d0113cdbe
data/.standard.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/standardrb/standard
3
+ format: progress
4
+ parallel: true
3
5
  ruby_version: 3.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.9] - 2024-04-29
4
+
5
+ ### Added
6
+
7
+ - Using yadr as a standard documentation tool;
8
+
9
+ ### Changed
10
+
11
+ - Upgrade README;
12
+ - Updating CI to run lint;
13
+ - Using the heredoc standard to build SQL queries;
14
+
15
+ ## [0.8.8] - 2024-04-25
16
+
17
+ ### Added
18
+
19
+ - Auction start reminder sent to participants;
20
+ - I18n time format;
21
+
22
+ ### Fixed:
23
+
24
+ - I18n messages for winner and auction participant emails;
25
+
26
+ ## [0.8.7] - 2024-04-23
27
+
28
+ ### Added
29
+
30
+ - Removing default values from relations;
31
+ - Rebuild factories to not contain default values;
32
+ - Add automated tests for auction relations;
33
+
34
+ ## [0.8.6] - 2024-04-23
35
+
36
+ ### Added
37
+
38
+ - Auction finalization configured for each type of auction;
39
+ - Add operations for winner and participant of an auction;
40
+ - Configure background job to work with unique jobs;
41
+ - Add 'sidekiq-unique-jobs' to be responsible for finishing penny auctions;
42
+
43
+ ### Changed:
44
+
45
+ - General improvements on seed data;
46
+
47
+ ### Fixed:
48
+
49
+ - NameError: uninitialized constant AuctionFunCore::Workers::ApplicationJob::Sidekiq (NameError)
50
+
3
51
  ## [0.8.5] - 2024-04-03
4
52
 
5
53
  ### Added
data/Procfile CHANGED
@@ -2,3 +2,4 @@ database: postgres
2
2
  redis: redis-server
3
3
  mailserver: maildev --hide-extensions STARTTLS
4
4
  background: bundle exec sidekiq -r ./config/app.rb
5
+ documentation: bundle exec yard server --reload
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AuctionFunCore
2
2
 
3
- This lib contains all the business logic necessary to run the auctions. A principle and standard must be strictly followed: The [SRP principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)The principle of single responsibility and some standard [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) concepts.
3
+ This lib contains all the business logic necessary to run the auctions. A principle and standard must be strictly followed: The [The principle of single responsibility](https://en.wikipedia.org/wiki/Single_responsibility_principle) and [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) concepts.
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,13 +13,13 @@ gem 'auction_fun_core'
13
13
  And then execute:
14
14
 
15
15
  ```sh
16
- user@host:~$ bundle install
16
+ bundle install
17
17
  ```
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
21
  ```sh
22
- user@host:~$ gem install auction_fun_core
22
+ gem install auction_fun_core
23
23
  ```
24
24
 
25
25
  ## Getting Started
@@ -27,10 +27,10 @@ user@host:~$ gem install auction_fun_core
27
27
  Initially, download the project remotely and copy the templates from the project's environment variables:
28
28
 
29
29
  ```sh
30
- user@host:~$ git clone git@github.com:ricardopacheco/auction-fun-core.git core
31
- user@host:~$ cd core
32
- user@host:~$ cp .env.development.template .env.development
33
- user@host:~$ cp .env.test.template .env.test
30
+ git clone git@github.com:ricardopacheco/auction-fun-core.git core
31
+ cd core
32
+ cp .env.development.template .env.development
33
+ cp .env.test.template .env.test
34
34
  ```
35
35
 
36
36
  > As the idea of this project is to be a lib, it was decided to use a specific environment variable called `APP_ENV`, so as not to conflict with others if the lib is used by a framework.
@@ -40,7 +40,7 @@ user@host:~$ cp .env.test.template .env.test
40
40
  Configure the `.env.development` file with the values according to your machine or network.
41
41
 
42
42
  Run the commands below to create the database and its structure, remembering to replace
43
- the `userdb` by the user of your postgresql service. By default, if `APP_ENV` is not provided
43
+ the `postgres` by the user of your postgresql service. By default, if `APP_ENV` is not provided
44
44
  is considered the value `development` by default.
45
45
 
46
46
  ### OS dependencies
@@ -52,50 +52,50 @@ is considered the value `development` by default.
52
52
  #### Database (PostgreSQL)
53
53
 
54
54
  ```sh
55
- user@host:~$ sudo apt install build-essential libssl-dev libreadline-dev zlib1g-dev libcurl4-openssl-dev uuid-dev
56
- user@host:~$ asdf plugin add postgres
57
- user@host:~$ asdf install postgres 16.1
58
- user@host:~$ rm -rf $HOME/.asdf/installs/postgres/16.1/data
59
- user@host:~$ initdb -D $HOME/.asdf/installs/postgres/16.1/data -U postgres
55
+ sudo apt install build-essential libssl-dev libreadline-dev zlib1g-dev libcurl4-openssl-dev uuid-dev
56
+ asdf plugin add postgres
57
+ asdf install postgres 16.1
58
+ rm -rf $HOME/.asdf/installs/postgres/16.1/data
59
+ initdb -D $HOME/.asdf/installs/postgres/16.1/data -U postgres
60
60
  ```
61
61
 
62
62
  ```sh
63
- user@host:~$ sudo apt install autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
64
- user@host:~$ asdf plugin add ruby
65
- user@host:~$ asdf install ruby 3.3.0
66
- user@host:~$ gem install pg -v 1.5.5 --verbose -- --with-pg-config=$HOME/.asdf/installs/postgres/16.1/bin/pg_config # Fix pg_config
67
- user@host:~$ bin/setup
63
+ sudo apt install autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
64
+ asdf plugin add ruby
65
+ asdf install ruby 3.3.0
66
+ gem install pg -v 1.5.5 --verbose -- --with-pg-config=$HOME/.asdf/installs/postgres/16.1/bin/pg_config # Fix pg_config
67
+ bin/setup
68
68
  ```
69
69
 
70
70
  #### Overmind (Procfile manager)
71
71
 
72
72
  ```sh
73
- user@host:~$ asdf install golang latest
74
- user@host:~$ go install github.com/DarthSim/overmind/v2
75
- user@host:~$ asdf reshim
73
+ asdf install golang latest
74
+ go install github.com/DarthSim/overmind/v2
75
+ asdf reshim
76
76
  ```
77
77
 
78
78
  #### Create database for development environment
79
79
 
80
- > **[postgres]** in rake commands is a name of user for postgres. Change if needed
80
+ - **postgres** in rake commands is a name of user for postgres. Change if needed
81
81
 
82
82
  In current tab:
83
83
 
84
84
  ```sh
85
- user@host:~$ overmind s -l database
85
+ overmind s -l database
86
86
  ```
87
87
 
88
88
  Open a new tab and create development database:
89
89
 
90
90
  ```sh
91
- user@host:~$ bundle exec rake 'auction_fun_core:db:create_database[postgres]'
92
- user@host:~$ bundle exec rake 'auction_fun_core:db:migrate'
91
+ bundle exec rake 'auction_fun_core:db:create_database[postgres]'
92
+ bundle exec rake 'auction_fun_core:db:migrate'
93
93
  ```
94
94
 
95
95
  Now come back to overmind tab, kill the current database process using **Ctrl+c**. After that:
96
96
 
97
97
  ```sh
98
- user@host:~$ overmind start
98
+ overmind start
99
99
  ```
100
100
 
101
101
  This will start all required services needed to run core application.
@@ -103,7 +103,7 @@ This will start all required services needed to run core application.
103
103
  In new tab, you could run seed data for development with
104
104
 
105
105
  ```sh
106
- user@host:~$ bundle exec rake 'auction_fun_core:db:seed'
106
+ bundle exec rake 'auction_fun_core:db:seed'
107
107
  ```
108
108
 
109
109
  ## Interactive prompt
@@ -117,9 +117,9 @@ Configure the `.env.test` file with the values according to your machine or netw
117
117
  Run the test suite with the coverage report using the command:
118
118
 
119
119
  ```sh
120
- user@host:~$ APP_ENV=test bundle exec rake auction_fun_core:db:create_database[userdb]
121
- user@host:~$ APP_ENV=test bundle exec rake auction_fun_core:db:migrate
122
- user@host:~$ CI=true APP_ENV=test bundle exec rspec .
120
+ APP_ENV=test bundle exec rake auction_fun_core:db:create_database[postgres]
121
+ APP_ENV=test bundle exec rake auction_fun_core:db:migrate
122
+ CI=true APP_ENV=test bundle exec rspec .
123
123
  ```
124
124
 
125
125
  ## Documentation
@@ -127,10 +127,12 @@ user@host:~$ CI=true APP_ENV=test bundle exec rspec .
127
127
  This project uses `yadr` as a documentation tool. To generate documentation and view it, run
128
128
 
129
129
  ```sh
130
- user@host:~$ bundle exec yard server --reload
130
+ bundle exec yard server --reload
131
131
  ```
132
132
 
133
- Documentation will be available at `http://localhost:8808`
133
+ Documentation will be available at `http://localhost:8808`.
134
+
135
+ > If you already use overmind, the documentation server starts automatically.
134
136
 
135
137
  ## External resources
136
138
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'config/application'
3
+ require_relative "config/application"
4
4
  require "bundler/gem_tasks"
5
5
  require "rspec/core/rake_task"
6
6
 
@@ -49,6 +49,7 @@ Gem::Specification.new do |spec|
49
49
  spec.add_dependency "rom", "5.3.0"
50
50
  spec.add_dependency "rom-sql", "3.6.2"
51
51
  spec.add_dependency "sidekiq", "7.2.2"
52
+ spec.add_dependency "sidekiq-unique-jobs", "8.0.10"
52
53
  spec.add_dependency "yard", "0.9.36"
53
54
  spec.add_dependency "zeitwerk", "2.6.13"
54
55
 
@@ -5,6 +5,7 @@ ROM::SQL.migration do
5
5
  create_table(:auctions) do
6
6
  primary_key :id
7
7
  foreign_key :staff_id, :staffs, null: false
8
+ foreign_key :winner_id, :users
8
9
  column :title, String, null: false
9
10
  column :description, :text
10
11
  column :kind, :auction_kinds, null: false
data/db/seeds.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pry"
4
3
  require "faker"
4
+ require "pry"
5
5
 
6
6
  I18n.enforce_available_locales = false
7
7
  Faker::Config.locale = "pt-BR"
@@ -13,7 +13,6 @@ STOPWATCH_OPTIONS = [15, 30, 45, 60].freeze
13
13
  AuctionFunCore::Application.start(:core)
14
14
 
15
15
  # Instantiate repos
16
- auction_repository = AuctionFunCore::Repos::AuctionContext::AuctionRepository.new
17
16
  staff_repository = AuctionFunCore::Repos::StaffContext::StaffRepository.new
18
17
 
19
18
  # Create root staff. Create as a regular user using the normal flow and after that
@@ -44,6 +43,19 @@ AuctionFunCore::Operations::StaffContext::RegistrationOperation.call(common_staf
44
43
  result.success { |staff| @staff = staff }
45
44
  end
46
45
 
46
+ # Add some users
47
+ 100.times do
48
+ attributes = {
49
+ name: Faker::Name.name, email: Faker::Internet.unique.email,
50
+ phone: Faker::PhoneNumber.unique.cell_phone_in_e164, password: "password",
51
+ password_confirmation: "password"
52
+ }
53
+ AuctionFunCore::Operations::UserContext::RegistrationOperation.call(attributes) do |result|
54
+ result.failure { |failure| raise "Error to create user: #{failure}" }
55
+ result.success { |user| puts "Create user with: #{user.to_h}" }
56
+ end
57
+ end
58
+
47
59
  # Create some standard auctions
48
60
  (1..15).each do |i|
49
61
  attributes = {
@@ -53,7 +65,31 @@ end
53
65
  }
54
66
  AuctionFunCore::Operations::AuctionContext::CreateOperation.call(attributes) do |result|
55
67
  result.failure { |failure| raise "Error to create standard auction: #{failure}" }
56
- result.success { |auction| puts "Create standard auction with: #{auction.to_h}" }
68
+ result.success do |auction|
69
+ @auction = auction
70
+ puts "Create standard auction with: #{auction.to_h}"
71
+ end
72
+ end
73
+
74
+ # Create auctions that have no bid. Multiples if 7
75
+ next if (i % 7).zero?
76
+
77
+ # Increase the value of each new bid by 10%
78
+ @current_bid = @auction.minimal_bid_cents
79
+ @minimal_percentage = 0.1
80
+ # Create some bids for standard auctions based on total users
81
+ (2..100).to_a.sample(rand(1..100)).each_with_index do |user_id, index|
82
+ @current_bid = index.zero? ? @current_bid : (@current_bid + (@current_bid * @minimal_percentage)).round(half: :up)
83
+ bid_params = {
84
+ auction_id: @auction.id,
85
+ user_id: user_id,
86
+ value_cents: @current_bid
87
+ }
88
+
89
+ AuctionFunCore::Operations::BidContext::CreateBidStandardOperation.call(bid_params) do |result|
90
+ result.failure { |failure| raise "Error to create bid: #{failure}" }
91
+ result.success { |bid| puts "Create standard bid with: #{bid.to_h}" }
92
+ end
57
93
  end
58
94
  end
59
95
 
@@ -65,52 +101,67 @@ end
65
101
 
66
102
  attributes = {
67
103
  staff_id: @staff.id, title: Faker::Commerce.product_name, description: Faker::Lorem.paragraph_by_chars,
68
- kind: "penny", started_at: started_at, finished_at: finished_at, stopwatch: stopwatch
104
+ kind: "penny", started_at: started_at, finished_at: finished_at, stopwatch: stopwatch,
105
+ initial_bid_cents: (i * 100), minimal_bid_cents: (i * 100)
69
106
  }
70
107
  AuctionFunCore::Operations::AuctionContext::CreateOperation.call(attributes) do |result|
71
108
  result.failure { |failure| raise "Error to create penny auction: #{failure}" }
72
- result.success { |auction| puts "Create penny auction with: #{auction.to_h}" }
109
+ result.success do |auction|
110
+ @auction = auction
111
+ puts "Create penny auction with: #{auction.to_h}"
112
+ end
113
+ end
114
+
115
+ # Create auctions that have no bid. Multiples if 7
116
+ next if (i % 7).zero?
117
+
118
+ # Create some bids for penny auctions based on total users
119
+ (2..100).to_a.sample(rand(1..100)).each do |user_id|
120
+ bid_params = {
121
+ auction_id: @auction.id,
122
+ user_id: user_id,
123
+ value_cents: @auction.minimal_bid_cents
124
+ }
125
+
126
+ AuctionFunCore::Operations::BidContext::CreateBidPennyOperation.call(bid_params) do |result|
127
+ result.failure { |failure| raise "Error to create bid: #{failure}" }
128
+ result.success { |bid| puts "Create penny bid with: #{bid.to_h}" }
129
+ end
73
130
  end
74
131
  end
75
132
 
76
133
  # Create some closed auctions
77
- (1..3).each do |i|
134
+ (1..5).each do |i|
78
135
  attributes = {
79
- staff_id: @staff.id, title: Faker::Commerce.product_name, kind: "closed",
80
- started_at: i.hour.from_now, finished_at: i.day.from_now.end_of_day,
136
+ staff_id: @staff.id, title: Faker::Commerce.product_name, description: Faker::Lorem.paragraph_by_chars,
137
+ kind: "closed", started_at: i.hour.from_now, finished_at: i.day.from_now.end_of_day,
81
138
  initial_bid_cents: (i * 1000)
82
139
  }
83
140
  AuctionFunCore::Operations::AuctionContext::CreateOperation.call(attributes) do |result|
84
141
  result.failure { |failure| raise "Error to create closed auction: #{failure}" }
85
- result.success { |auction| puts "Create closed auction with: #{auction.to_h}" }
142
+ result.success do |auction|
143
+ @auction = auction
144
+ puts "Create closed auction with: #{auction.to_h}"
145
+ end
86
146
  end
87
- end
88
-
89
- # Add some users
90
- 100.times do
91
- attributes = {
92
- name: Faker::Name.name, email: Faker::Internet.unique.email,
93
- phone: Faker::PhoneNumber.unique.cell_phone_in_e164, password: "password",
94
- password_confirmation: "password"
95
- }
96
- AuctionFunCore::Operations::UserContext::RegistrationOperation.call(attributes) do |result|
97
- result.failure { |failure| raise "Error to create user: #{failure}" }
98
- result.success { |user| puts "Create user with: #{user.to_h}" }
99
- end
100
- end
101
-
102
- # Create some bids
103
- auction_repository.all.each do |auction|
104
- next if auction.id.even?
105
-
106
- bid_params = {
107
- auction_id: auction.id,
108
- user_id: rand(2..100),
109
- value_cents: auction.minimal_bid_cents + (auction.minimal_bid_cents * 0.10)
110
- }
111
147
 
112
- "AuctionFunCore::Operations::BidContext::CreateBid#{auction.kind.capitalize}Operation".constantize.call(bid_params) do |result|
113
- result.failure { |failure| raise "Error to create bid: #{failure}" }
114
- result.success { |bid| puts "Create bid with: #{bid.to_h}" }
148
+ # Create auctions that have no bid. Pair numbers
149
+ next if i.even?
150
+
151
+ @minimal_bid = @auction.minimal_bid_cents
152
+ # Create some bids for closed auctions based on total users
153
+ (2..100).to_a.sample(rand(1..100)).each_with_index do |user_id, index|
154
+ # Choosing a random value for the bid, obeying the rule that it has to be just greater than the minimum bid.
155
+ random_bid = index.zero? ? @minimal_bid : rand((@minimal_bid + 1)..10_000).round
156
+ bid_params = {
157
+ auction_id: @auction.id,
158
+ user_id: user_id,
159
+ value_cents: random_bid
160
+ }
161
+
162
+ AuctionFunCore::Operations::BidContext::CreateBidClosedOperation.call(bid_params) do |result|
163
+ result.failure { |failure| raise "Error to create bid: #{failure}" }
164
+ result.success { |bid| puts "Create closed bid with: #{bid.to_h}" }
165
+ end
115
166
  end
116
167
  end
@@ -70,3 +70,15 @@ en-US:
70
70
  auction_context:
71
71
  create:
72
72
  finished_at: "must be after started time"
73
+ pre_auction:
74
+ auction_start_reminder:
75
+ auction_already_started: "auction already started"
76
+ post_auction:
77
+ participant:
78
+ none: "there was no participation from this user in the auction reported"
79
+ winner:
80
+ wrong: "was not the winner of this auction"
81
+ processor:
82
+ finish:
83
+ invalid_kind: "auction with invalid type"
84
+ invalid_status: "auction with invalid status"
@@ -0,0 +1,66 @@
1
+ en-US:
2
+ date:
3
+ abbr_day_names:
4
+ - Sun
5
+ - Mon
6
+ - Tue
7
+ - Wed
8
+ - Thu
9
+ - Fri
10
+ - Sat
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mar
16
+ - Apr
17
+ - May
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Oct
23
+ - Nov
24
+ - Dec
25
+ day_names:
26
+ - Sunday
27
+ - Monday
28
+ - Tuesday
29
+ - Wednesday
30
+ - Thursday
31
+ - Friday
32
+ - Saturday
33
+ formats:
34
+ default: "%Y-%m-%d"
35
+ long: "%B %d, %Y"
36
+ short: "%b %d"
37
+ month_names:
38
+ -
39
+ - January
40
+ - February
41
+ - March
42
+ - April
43
+ - May
44
+ - June
45
+ - July
46
+ - August
47
+ - September
48
+ - October
49
+ - November
50
+ - December
51
+ order:
52
+ - :year
53
+ - :month
54
+ - :day
55
+ time:
56
+ am: am
57
+ formats:
58
+ default: "%a, %d %b %Y %H:%M:%S %z"
59
+ long: "%B %d, %Y %H:%M"
60
+ short: "%d %b %H:%M"
61
+ pm: pm
62
+ application:
63
+ general:
64
+ hello: "Hi %{name}"
65
+ app_name: "AuctionFun"
66
+ team: "Team AuctionFun"
@@ -0,0 +1,13 @@
1
+ en-US:
2
+ mail:
3
+ auction_context:
4
+ post_auction:
5
+ participant_mailer:
6
+ subject: "Thank you for participating in the auction %{title}"
7
+ body:
8
+ description: "Thank you for participating in the auction <b>%{title}</b>! Although you weren't the winner this time, we would like to recognize your efforts and share some statistics on your performance:"
9
+ stats:
10
+ auction_total_bids: "Total auction bids: %{auction_total_bids}"
11
+ winner_bid: "Winner bid: %{winner_bid}"
12
+ auction_date: "Auction Date"
13
+ regards: "We hope you found the experience enriching and invite you to participate in our future auctions. Follow our website and social media to stay up to date with upcoming opportunities."
@@ -0,0 +1,13 @@
1
+ en-US:
2
+ mail:
3
+ auction_context:
4
+ post_auction:
5
+ winner_mailer:
6
+ subject: "Congratulations! You are the winner of the auction %{title}!"
7
+ body:
8
+ description: "We are very happy to inform you that you were the winner of our auction <b>%{title}</b>! Your bid was the highest, and you are now the new owner of item. Below is some information and statistics about the auction:"
9
+ item:
10
+ title: "Auctioned item: <b>%{title}</b>"
11
+ winner_bid: "Your Winning Bid: %{winner_bid}"
12
+ auction_total_bids: "Total Number of Bids: %{auction_total_bids}"
13
+ auction_date: "Auction Date"
@@ -0,0 +1,11 @@
1
+ pt-BR:
2
+ mail:
3
+ auction_context:
4
+ pre_auction:
5
+ auction_start_reminder_mailer:
6
+ subject: "The %{title} auction will start soon!"
7
+ body:
8
+ description: "We are excited to inform you that the auction you are participating in will begin soon!"
9
+ auction_date: "Start Time"
10
+ link_to_auction: "Click the link below to view auction details"
11
+ thanks: "Thank you for your participation and we wish you good luck!"
@@ -70,3 +70,15 @@ pt-BR:
70
70
  auction_context:
71
71
  create:
72
72
  finished_at: "deve ser depois da hora de início"
73
+ pre_auction:
74
+ auction_start_reminder:
75
+ auction_already_started: "leilão já foi iniciado"
76
+ post_auction:
77
+ participant:
78
+ none: "não houve nenhuma participação deste usuário no leilão informado"
79
+ winner:
80
+ wrong: "não foi o vencedor deste leilão"
81
+ processor:
82
+ finish:
83
+ invalid_kind: "leilão com tipo inválido"
84
+ invalid_status: "leilão com status inválido"
@@ -0,0 +1,66 @@
1
+ pt-BR:
2
+ date:
3
+ abbr_day_names:
4
+ - Dom
5
+ - Seg
6
+ - Ter
7
+ - Qua
8
+ - Qui
9
+ - Sex
10
+ - Sáb
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Fev
15
+ - Mar
16
+ - Abr
17
+ - Mai
18
+ - Jun
19
+ - Jul
20
+ - Ago
21
+ - Set
22
+ - Out
23
+ - Nov
24
+ - Dez
25
+ day_names:
26
+ - Domingo
27
+ - Segunda-feira
28
+ - Terça-feira
29
+ - Quarta-feira
30
+ - Quinta-feira
31
+ - Sexta-feira
32
+ - Sábado
33
+ formats:
34
+ default: "%d/%m/%Y"
35
+ long: "%d de %B de %Y"
36
+ short: "%d de %B"
37
+ month_names:
38
+ -
39
+ - Janeiro
40
+ - Fevereiro
41
+ - Março
42
+ - Abril
43
+ - Maio
44
+ - Junho
45
+ - Julho
46
+ - Agosto
47
+ - Setembro
48
+ - Outubro
49
+ - Novembro
50
+ - Dezembro
51
+ order:
52
+ - :day
53
+ - :month
54
+ - :year
55
+ time:
56
+ am: am
57
+ formats:
58
+ default: "%a, %d de %B de %Y, %H:%M:%S %z"
59
+ long: "%d de %B de %Y, %H:%M"
60
+ short: "%d de %B, %H:%M"
61
+ pm: pm
62
+ application:
63
+ general:
64
+ hello: "Olá %{name}"
65
+ app_name: "AuctionFun"
66
+ team: "Time AuctionFun"
@@ -0,0 +1,13 @@
1
+ pt-BR:
2
+ mail:
3
+ auction_context:
4
+ post_auction:
5
+ participant_mailer:
6
+ subject: "Sua participação no leilão %{title}"
7
+ body:
8
+ description: "Agradecemos por participar do leilão <b>%{title}</b>! Embora você não tenha sido o vencedor desta vez, gostaríamos de reconhecer o seu empenho e compartilhar algumas estatísticas do seu desempenho:"
9
+ stats:
10
+ auction_total_bids: "Total de lances do leilão: %{auction_total_bids}"
11
+ winner_bid: "Lance vencedor: %{winner_bid}"
12
+ auction_date: "Data do Leilão"
13
+ regards: "Esperamos que você tenha encontrado a experiência enriquecedora e convidamos você a participar de nossos futuros leilões. Acompanhe nosso site e redes sociais para ficar por dentro das próximas oportunidades."
@@ -0,0 +1,13 @@
1
+ pt-BR:
2
+ mail:
3
+ auction_context:
4
+ post_auction:
5
+ winner_mailer:
6
+ subject: "Parabéns! Você é o vencedor do leilão %{title}!"
7
+ body:
8
+ description: "Estamos muito felizes em informar que você foi o vencedor do leilão <b>%{title}</b>! Seu lance foi o maior, e agora você é o novo proprietário do item. Abaixo estão algumas informações e estatísticas sobre o leilão:"
9
+ item:
10
+ title: "Item Arrematado: <b>%{title}</b>"
11
+ winner_bid: "Seu Lance Vencedor: %{winner_bid}"
12
+ auction_total_bids: "Número Total de Lances: %{auction_total_bids}"
13
+ auction_date: "Data do Leilão"