@@ -47,19 +47,6 @@ defmodule CadetWeb.UserController do
47
47
def collectibles_update ( conn , % { "picnickname" => pic_nickname , "picname" => pic_name } ) do
48
48
user = conn . assigns [ :current_user ]
49
49
Cadet.GameStates . update_collectibles ( pic_nickname , pic_name , user )
50
- '''
51
-
52
- # Error reporting part, to be further implemented.
53
-
54
- case Cadet.GameStates.update_collectibles(pic_nickname, pic_name, user) do
55
- {:ok, _} ->
56
- text(conn, "OK")
57
- {:error, {status, message}} ->
58
- conn
59
- |> put_status(status)
60
- |> text(message)
61
- end
62
- '''
63
50
end
64
51
65
52
swagger_path :collectibles_update do
@@ -77,16 +64,41 @@ defmodule CadetWeb.UserController do
77
64
response ( 401 , "Unauthorised" )
78
65
end
79
66
80
- '''
81
- # to do
82
- def save_data_update do
83
-
67
+ def save_data_update ( conn , % { [ ] => action_sequence , "" => start_location } ) do
68
+ user = conn . assigns [ :current_user ]
69
+ Cadet.GameStates . update_save_data ( action_sequence , start_location , user )
84
70
end
85
71
86
72
swagger_path :save_data_update do
73
+ put ( "/user/save_data/update" )
74
+ summary ( "update users' game data saved" )
75
+ security ( [ % { JWT: [ ] } ] )
76
+ consumes ( "application/json" )
77
+ produces ( "application/json" )
78
+ parameters do
79
+ action ( :path , :array , "action sequence" , required: true )
80
+ startLocation ( :path , :string , "start location" , required: true )
81
+ end
82
+ response ( 200 , "OK" )
83
+ response ( 400 , "Invalid parameters" )
84
+ response ( 401 , "Unauthorised" )
85
+ end
87
86
87
+ def game_state_clear_up ( conn , _params ) do
88
+ user = conn . assigns [ :current_user ]
89
+ Cadet.GameStates . clear_up ( user )
88
90
end
89
- '''
91
+
92
+ swagger_path :save_data_clear_up do
93
+ put ( "/user/save_data/clear_up" )
94
+ summary ( "clear up users' game data saved" )
95
+ security ( [ % { JWT: [ ] } ] )
96
+ consumes ( "application/json" )
97
+ produces ( "application/json" )
98
+ response ( 200 , "OK" )
99
+ response ( 401 , "Unauthorised" )
100
+ end
101
+
90
102
91
103
def swagger_definitions do
92
104
% {
@@ -125,7 +137,10 @@ defmodule CadetWeb.UserController do
125
137
126
138
game_states (
127
139
:map ,
128
- "States for user's game, including users' collectibles and save data." <> " Value will be a map of empty maps for non-students."
140
+ "States for user's game, including users' collectibles and save data.\n "
141
+ <> "collectibles is a map, and save data is a map with elements action sequence and start location\n "
142
+ <> "action sequence is an array of string, and start location is a string.\n "
143
+ <> " Value will be a map of empty maps for non-students."
129
144
)
130
145
end
131
146
end ,
0 commit comments