Skip to content

Commit 9635a2b

Browse files
updated to game_states version
Updated to game_states version and added some to-dos for the save_data part
1 parent 18375b5 commit 9635a2b

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

lib/cadet_web/controllers/user_controller.ex

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ defmodule CadetWeb.UserController do
66
use CadetWeb, :controller
77
use PhoenixSwagger
88

9-
import Ecto.Changeset
9+
# import Ecto.Changeset
1010

1111
import Cadet.Assessments
12-
import Cadet.Collectibles
12+
import Cadet.GameStates
13+
import Ecto.Repo
1314

1415
def index(conn, _) do
1516
user = conn.assigns.current_user
1617
grade = user_total_grade(user)
1718
max_grade = user_max_grade(user)
1819
story = user_current_story(user)
1920
xp = user_total_xp(user)
20-
collectibles = user_collectibles(user)
21-
21+
game_states = user_game_states(user)
2222
render(
2323
conn,
2424
"index.json",
@@ -27,9 +27,8 @@ defmodule CadetWeb.UserController do
2727
max_grade: max_grade,
2828
story: story,
2929
xp: xp,
30-
collectibles: collectibles,
30+
game_states: game_states
3131
)
32-
3332
end
3433

3534
swagger_path :index do
@@ -45,20 +44,26 @@ defmodule CadetWeb.UserController do
4544
response(401, "Unauthorised")
4645
end
4746

48-
def collectiblesUpdate(conn, %{"picnickname" => pic_nickname, "picname" => pic_name}) do
47+
def collectibles_update(conn, %{"picnickname" => pic_nickname, "picname" => pic_name}) do
4948
user = conn.assigns[:current_user]
50-
case Collectibles.update_collectibles(pic_nickname, pic_name, user) do
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
5155
{:ok, _} ->
5256
text(conn, "OK")
5357
{:error, {status, message}} ->
5458
conn
5559
|> put_status(status)
5660
|> text(message)
5761
end
62+
'''
5863
end
5964

60-
swagger_path :collectiblesUpdate do
61-
post("/user")
65+
swagger_path :collectibles_update do
66+
put("/user/collectibles")
6267
summary("add one collectible to the user")
6368
security([%{JWT: []}])
6469
consumes("application/json")
@@ -72,9 +77,16 @@ defmodule CadetWeb.UserController do
7277
response(401, "Unauthorised")
7378
end
7479

80+
'''
81+
# to do
82+
def save_data_update do
7583
84+
end
7685
86+
swagger_path :save_data_update do
7787
88+
end
89+
'''
7890

7991
def swagger_definitions do
8092
%{
@@ -111,9 +123,9 @@ defmodule CadetWeb.UserController do
111123
"Amount of xp. Only provided for 'Student'." <> "Value will be 0 for non-students."
112124
)
113125

114-
collectibles(
126+
game_states(
115127
:map,
116-
"Collectibles users obtained in story." <> " Value will be empty map for non-students."
128+
"States for user's game, including users' collectibles and save data." <> " Value will be a map of empty maps for non-students."
117129
)
118130
end
119131
end,

0 commit comments

Comments
 (0)