@@ -6,8 +6,7 @@ defmodule CadetWeb.UserController do
6
6
use CadetWeb , :controller
7
7
use PhoenixSwagger
8
8
import Cadet.Assessments
9
- import Cadet.GameStates
10
- import Ecto.Repo
9
+ import Cadet.Accounts.GameStates
11
10
12
11
def index ( conn , _ ) do
13
12
user = conn . assigns . current_user
@@ -29,19 +28,24 @@ defmodule CadetWeb.UserController do
29
28
)
30
29
end
31
30
32
- swagger_path :index do
33
- get ( "/user" )
34
- summary ( "Get the name and role of a user" )
35
- security ( [ % { JWT: [ ] } ] )
36
- produces ( "application/json" )
37
- response ( 200 , "OK" , Schema . ref ( :UserInfo ) )
38
- response ( 401 , "Unauthorised" )
31
+ def update_game_states ( conn , % { "gameStates" => new_game_states } ) do
32
+ user = conn . assigns [ :current_user ]
33
+
34
+ case update ( user , new_game_states ) do
35
+ { :ok , nil } ->
36
+ text ( conn , "OK" )
37
+
38
+ { :error , { status , message } } ->
39
+ conn
40
+ |> put_status ( status )
41
+ |> text ( message )
42
+ end
39
43
end
40
44
41
- def update_game_states ( conn , % { "gameStates" => new_game_states } ) do
45
+ def clear_up_game_states ( conn , _ ) do
42
46
user = conn . assigns [ :current_user ]
43
47
44
- case Cadet.GameStates . update ( user , new_game_states ) do
48
+ case clear ( user ) do
45
49
{ :ok , nil } ->
46
50
text ( conn , "OK" )
47
51
@@ -52,6 +56,16 @@ defmodule CadetWeb.UserController do
52
56
end
53
57
end
54
58
59
+ swagger_path :index do
60
+ get ( "/user" )
61
+ summary ( "Get the name and role of a user" )
62
+ security ( [ % { JWT: [ ] } ] )
63
+ produces ( "application/json" )
64
+ response ( 200 , "OK" , Schema . ref ( :UserInfo ) )
65
+ response ( 401 , "Unauthorised" )
66
+ end
67
+
68
+
55
69
swagger_path :update_game_states do
56
70
put ( "/user/game_states/save" )
57
71
summary ( "update user's game states" )
@@ -70,20 +84,6 @@ defmodule CadetWeb.UserController do
70
84
response ( 401 , "Unauthorised" )
71
85
end
72
86
73
- def clear_up_game_states ( conn , _ ) do
74
- user = conn . assigns [ :current_user ]
75
-
76
- case Cadet.GameStates . clear ( user ) do
77
- { :ok , nil } ->
78
- text ( conn , "OK" )
79
-
80
- { :error , { status , message } } ->
81
- conn
82
- |> put_status ( status )
83
- |> text ( message )
84
- end
85
- end
86
-
87
87
swagger_path :clear_up_game_states do
88
88
put ( "/user/game_states/clear" )
89
89
summary ( "clear up users' game data saved" )
0 commit comments