Skip to content

Commit

Permalink
refactor: create Account::Create service and extract to kiqr gem
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Apr 9, 2024
1 parent 03d065e commit b7cfaa7
Show file tree
Hide file tree
Showing 30 changed files with 971 additions and 25 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem "devise", "~> 4.9", ">= 4.9.3"
gem "devise-two-factor", "~> 5.0.0"
gem "dry-initializer", "~> 3.1"
gem "meta-tags", "~> 2.20"
gem "public_uid", "~> 2.2"
gem "rqrcode", "~> 2.0"
gem "simple_form", "~> 5.3.0"
gem "view_component", "~> 3.11"
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PATH
remote: gems/kiqr
specs:
kiqr (0.1.0)
devise (~> 4.9, >= 4.9.3)
devise-two-factor (~> 5.0.0)
public_uid (~> 2.2)
rails (>= 7.1.3.2)

GEM
Expand Down Expand Up @@ -403,8 +406,6 @@ DEPENDENCIES
brakeman (~> 6.1)
capybara
debug
devise (~> 4.9, >= 4.9.3)
devise-two-factor (~> 5.0.0)
dry-initializer (~> 3.1)
erb_lint
factory_bot_rails (~> 6.4.3)
Expand All @@ -414,7 +415,6 @@ DEPENDENCIES
kiqr!
letter_opener_web (~> 2.0)
meta-tags (~> 2.20)
public_uid (~> 2.2)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)
rails-controller-testing
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ def new

def create
@account = Account.new(account_permitted_parameters)
@account.account_users.new(user: current_user, owner: true)

if @account.save
redirect_to dashboard_path(account_id: @account), notice: I18n.t("accounts.create.success")
if @account.valid?
Kiqr::Services::Accounts::Create.call!(account: @account, user: current_user)
flash[:notice] = I18n.t("accounts.create.success")
redirect_to dashboard_path(account_id: @account)
else
render :new, status: :unprocessable_entity
end
Expand Down
6 changes: 0 additions & 6 deletions config/routes/authentication.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Devise routes for user authentication
devise_for :users, path_names: {sign_in: "login", sign_up: "create-account"}, controllers: {
registrations: "users/registrations",
sessions: "users/sessions"
}

# User personal accounts.
scope module: :users, path: :users do
get "onboarding" => "onboarding#new"
Expand Down
14 changes: 14 additions & 0 deletions gems/kiqr/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ gem "sprockets-rails"

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
# gem "brakeman", "~> 6.1"
# gem "debug", platforms: %i[mri windows]

# gem "standard", require: false
# gem "erb_lint", require: false
# gem "letter_opener_web", "~> 2.0"
gem "factory_bot", "~> 6.4.3"
# gem "rails-controller-testing"
gem "faker"
gem "simplecov", require: false
end
239 changes: 239 additions & 0 deletions gems/kiqr/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
PATH
remote: .
specs:
kiqr (0.1.0)
devise (~> 4.9, >= 4.9.3)
devise-two-factor (~> 5.0.0)
public_uid (~> 2.2)
rails (>= 7.1.3.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.3.2)
actionpack (= 7.1.3.2)
activesupport (= 7.1.3.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.3.2)
actionpack (= 7.1.3.2)
activejob (= 7.1.3.2)
activerecord (= 7.1.3.2)
activestorage (= 7.1.3.2)
activesupport (= 7.1.3.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.3.2)
actionpack (= 7.1.3.2)
actionview (= 7.1.3.2)
activejob (= 7.1.3.2)
activesupport (= 7.1.3.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.2)
actionpack (7.1.3.2)
actionview (= 7.1.3.2)
activesupport (= 7.1.3.2)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.3.2)
actionpack (= 7.1.3.2)
activerecord (= 7.1.3.2)
activestorage (= 7.1.3.2)
activesupport (= 7.1.3.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.3.2)
activesupport (= 7.1.3.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.3.2)
activesupport (= 7.1.3.2)
globalid (>= 0.3.6)
activemodel (7.1.3.2)
activesupport (= 7.1.3.2)
activerecord (7.1.3.2)
activemodel (= 7.1.3.2)
activesupport (= 7.1.3.2)
timeout (>= 0.4.0)
activestorage (7.1.3.2)
actionpack (= 7.1.3.2)
activejob (= 7.1.3.2)
activerecord (= 7.1.3.2)
activesupport (= 7.1.3.2)
marcel (~> 1.0)
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.7)
builder (3.2.4)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
devise (4.9.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-two-factor (5.0.0)
activesupport (~> 7.0)
devise (~> 4.0)
railties (~> 7.0)
rotp (~> 6.0)
docile (1.4.0)
drb (2.2.1)
erubi (1.12.0)
factory_bot (6.4.6)
activesupport (>= 5.0.0)
faker (3.3.1)
i18n (>= 1.8.11, < 2)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.12.0)
rdoc
reline (>= 0.4.2)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.22.3)
mutex_m (0.2.0)
net-imap (0.4.10)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.3-arm64-darwin)
racc (~> 1.4)
orm_adapter (0.5.0)
psych (5.1.2)
stringio
public_uid (2.2.0)
activerecord (> 4.2)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
rack (3.0.10)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rails (7.1.3.2)
actioncable (= 7.1.3.2)
actionmailbox (= 7.1.3.2)
actionmailer (= 7.1.3.2)
actionpack (= 7.1.3.2)
actiontext (= 7.1.3.2)
actionview (= 7.1.3.2)
activejob (= 7.1.3.2)
activemodel (= 7.1.3.2)
activerecord (= 7.1.3.2)
activestorage (= 7.1.3.2)
activesupport (= 7.1.3.2)
bundler (>= 1.15.0)
railties (= 7.1.3.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.3.2)
actionpack (= 7.1.3.2)
activesupport (= 7.1.3.2)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.1.0)
rdoc (6.6.3.1)
psych (>= 4.0.0)
reline (0.5.0)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rotp (6.3.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.7.3-arm64-darwin)
stringio (3.1.0)
thor (1.3.1)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.13)

PLATFORMS
arm64-darwin

DEPENDENCIES
factory_bot (~> 6.4.3)
faker
kiqr!
puma
simplecov
sprockets-rails
sqlite3

BUNDLED WITH
2.5.6
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b7cfaa7

Please sign in to comment.