File tree Expand file tree Collapse file tree 2 files changed +39
-13
lines changed
apps/admin/controllers/users
lib/ossboard/interactors/users Expand file tree Collapse file tree 2 files changed +39
-13
lines changed Original file line number Diff line number Diff line change @@ -15,24 +15,14 @@ class Update
15
15
end
16
16
17
17
def call ( params )
18
- # TODO: To operation
19
- @user = repo . find ( params [ :id ] )
18
+ result = Interactors :: Users :: Update . new ( params . valid? , params ) . call
19
+ @user = result . user
20
20
21
- if @user && params . valid?
22
- user_params = params [ :user ]
23
- user_params [ :admin ] = user_params [ :admin ] == '1'
24
-
25
- repo . update ( @user . id , user_params )
21
+ if result . successful?
26
22
redirect_to routes . user_path ( user . id )
27
23
else
28
24
redirect_to routes . edit_user_path ( user . id )
29
25
end
30
26
end
31
-
32
- private
33
-
34
- def repo
35
- @repo ||= UserRepository . new
36
- end
37
27
end
38
28
end
Original file line number Diff line number Diff line change
1
+ require 'hanami/interactor'
2
+
3
+ module Interactors
4
+ module Users
5
+ class Update
6
+ include Hanami ::Interactor
7
+
8
+ expose :user
9
+
10
+ def initialize ( params_valid , params )
11
+ @params = params
12
+ @params_valid = params_valid
13
+ @user = repo . find ( @params [ :id ] )
14
+ end
15
+
16
+ def call
17
+ return error ( 'No user found' ) unless @user
18
+ return error ( 'Unprocessable entity' ) unless @params_valid
19
+
20
+ prepare_user_params
21
+ repo . update ( @user . id , @params [ :user ] )
22
+ end
23
+
24
+ private
25
+
26
+ def repo
27
+ UserRepository . new ( )
28
+ end
29
+
30
+ def prepare_user_params
31
+
32
+ @params [ :user ] [ :admin ] = @params [ :user ] [ :admin ] == '1'
33
+ end
34
+ end
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments