@@ -47,19 +47,6 @@ defmodule CadetWeb.UserController do
4747 def collectibles_update ( conn , % { "picnickname" => pic_nickname , "picname" => pic_name } ) do
4848 user = conn . assigns [ :current_user ]
4949 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- '''
6350 end
6451
6552 swagger_path :collectibles_update do
@@ -77,16 +64,41 @@ defmodule CadetWeb.UserController do
7764 response ( 401 , "Unauthorised" )
7865 end
7966
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 )
8470 end
8571
8672 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
8786
87+ def game_state_clear_up ( conn , _params ) do
88+ user = conn . assigns [ :current_user ]
89+ Cadet.GameStates . clear_up ( user )
8890 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+
90102
91103 def swagger_definitions do
92104 % {
@@ -125,7 +137,10 @@ defmodule CadetWeb.UserController do
125137
126138 game_states (
127139 :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."
129144 )
130145 end
131146 end ,
0 commit comments