forked from ossboard-org/ossboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ossboard-org#165 from nickskalkin/update-users-usi…
…ng-interactor Updating users using interactor
- Loading branch information
Showing
2 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'hanami/interactor' | ||
|
||
module Interactors | ||
module Users | ||
class Update | ||
include Hanami::Interactor | ||
|
||
expose :user | ||
|
||
def initialize(params_valid, params) | ||
@params = params | ||
@params_valid = params_valid | ||
@user = repo.find(@params[:id]) | ||
end | ||
|
||
def call | ||
return error('No user found') unless @user | ||
return error('Unprocessable entity') unless @params_valid | ||
|
||
prepare_user_params | ||
repo.update(@user.id, @params[:user]) | ||
end | ||
|
||
private | ||
|
||
def repo | ||
UserRepository.new() | ||
end | ||
|
||
def prepare_user_params | ||
|
||
@params[:user][:admin] = @params[:user][:admin] == '1' | ||
end | ||
end | ||
end | ||
end |