Skip to content

Commit

Permalink
[v7.2] Improve use cases' SRP
Browse files Browse the repository at this point in the history
  • Loading branch information
serradura committed Dec 18, 2019
1 parent e682705 commit 50e763c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.5'

gem 'u-case', '~> 2.2', require: 'u-case/with_validation'
gem 'u-case', '~> 2.3', require: 'u-case/with_validation'
gem 'type_validator', '~> 1.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -205,7 +205,7 @@ GEM
tzinfo (1.2.5)
thread_safe (~> 0.1)
u-attributes (1.2.0)
u-case (2.2.0)
u-case (2.3.0)
u-attributes (~> 1.1)
virtus (1.0.5)
axiom-types (~> 0.1)
Expand Down Expand Up @@ -233,7 +233,7 @@ DEPENDENCIES
sqlite3 (~> 1.4)
type_validator (~> 1.0)
tzinfo-data
u-case (~> 2.2)
u-case (~> 2.3)

RUBY VERSION
ruby 2.6.5p114
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/todos_controller.rb
Expand Up @@ -10,6 +10,7 @@ def index
def create
Todo::List::AddItem
.call(user: current_user, params: params)
.then(Todo::Serialize::AsJson)
.on_failure(:parameter_missing) { |error| render_json(400, error: error[:message]) }
.on_failure(:invalid_todo) { |todo| render_json(422, todo: todo[:errors]) }
.on_success { |result| render_json(201, todo: result[:todo]) }
Expand All @@ -18,6 +19,7 @@ def create
def destroy
Todo::List::DeleteItem
.call(user: current_user, todo_id: params[:id])
.then(Todo::Serialize::AsJson)
.on_failure(:validation_error) { |result| render_json(400, errors: result[:errors]) }
.on_failure(:todo_not_found) { render_json(404, todo: { id: 'not found' }) }
.on_success { |result| render_json(200, todo: result[:todo]) }
Expand All @@ -26,6 +28,7 @@ def destroy
def update
Todo::List::UpdateItem
.call(user: current_user, todo_id: params[:id], params: params)
.then(Todo::Serialize::AsJson)
.on_failure(:parameter_missing) { |error| render_json(400, error: error[:message]) }
.on_failure(:validation_error) { |result| render_json(400, errors: result[:errors]) }
.on_failure(:todo_not_found) { render_json(404, todo: { id: 'not found' }) }
Expand All @@ -36,6 +39,7 @@ def update
def complete
Todo::List::CompleteItem
.call(user: current_user, todo_id: params[:id])
.then(Todo::Serialize::AsJson)
.on_failure(:validation_error) { |result| render_json(400, errors: result[:errors]) }
.on_failure(:todo_not_found) { render_json(404, todo: { id: 'not found' }) }
.on_success { |result| render_json(200, todo: result[:todo]) }
Expand All @@ -44,6 +48,7 @@ def complete
def activate
Todo::List::ActivateItem
.call(user: current_user, todo_id: params[:id])
.then(Todo::Serialize::AsJson)
.on_failure(:validation_error) { |result| render_json(400, errors: result[:errors]) }
.on_failure(:todo_not_found) { render_json(404, todo: { id: 'not found' }) }
.on_success { |result| render_json(200, todo: result[:todo]) }
Expand Down
3 changes: 1 addition & 2 deletions app/models/todo/list/activate_item.rb
@@ -1,7 +1,6 @@
class Todo::List::ActivateItem < Micro::Case
flow Todo::List::FindItem,
self.call!,
Todo::Serialize::AsJson
self.call!

attribute :todo

Expand Down
3 changes: 1 addition & 2 deletions app/models/todo/list/add_item.rb
@@ -1,6 +1,5 @@
class Todo::List::AddItem < Micro::Case
flow self.call!,
Todo::Serialize::AsJson
flow self.call!

attributes :user, :params

Expand Down
3 changes: 1 addition & 2 deletions app/models/todo/list/complete_item.rb
@@ -1,7 +1,6 @@
class Todo::List::CompleteItem < Micro::Case
flow Todo::List::FindItem,
self.call!,
Todo::Serialize::AsJson
self.call!

attribute :todo

Expand Down
3 changes: 1 addition & 2 deletions app/models/todo/list/delete_item.rb
@@ -1,7 +1,6 @@
class Todo::List::DeleteItem < Micro::Case
flow Todo::List::FindItem,
self.call!,
Todo::Serialize::AsJson
self.call!

attribute :todo

Expand Down
3 changes: 1 addition & 2 deletions app/models/todo/list/update_item.rb
@@ -1,7 +1,6 @@
class Todo::List::UpdateItem < Micro::Case
flow Todo::List::FindItem,
self.call!,
Todo::Serialize::AsJson
self.call!

attributes :todo, :params

Expand Down

0 comments on commit 50e763c

Please sign in to comment.