@@ -6,6 +6,8 @@ defmodule CadetWeb.UserController do
6
6
use CadetWeb , :controller
7
7
use PhoenixSwagger
8
8
9
+ import Ecto.Changeset
10
+
9
11
import Cadet.Assessments
10
12
import Cadet.Collectibles
11
13
@@ -15,7 +17,6 @@ defmodule CadetWeb.UserController do
15
17
max_grade = user_max_grade ( user )
16
18
story = user_current_story ( user )
17
19
xp = user_total_xp ( user )
18
-
19
20
collectibles = user_collectibles ( user )
20
21
21
22
render (
@@ -28,26 +29,7 @@ defmodule CadetWeb.UserController do
28
29
xp: xp ,
29
30
collectibles: collectibles ,
30
31
)
31
- end
32
32
33
- def addCollectibles ( conn , pic_nickname , pic_name ) do
34
- user = conn . assigns . current_user
35
- grade = user_total_grade ( user )
36
- max_grade = user_max_grade ( user )
37
- story = user_current_story ( user )
38
- xp = user_total_xp ( user )
39
- collectibles = add_user_collectibles ( user , pic_nickname , pic_name )
40
-
41
- render (
42
- conn ,
43
- "index.json" ,
44
- user: user ,
45
- grade: grade ,
46
- max_grade: max_grade ,
47
- story: story ,
48
- xp: xp ,
49
- collectibles: collectibles ,
50
- )
51
33
end
52
34
53
35
swagger_path :index do
@@ -63,15 +45,37 @@ defmodule CadetWeb.UserController do
63
45
response ( 401 , "Unauthorised" )
64
46
end
65
47
66
- swagger_path :addCollectibles do
48
+ def collectiblesUpdate ( conn , % { "picnickname" => pic_nickname , "picname" => pic_name } ) do
49
+ user = conn . assigns [ :current_user ]
50
+ case Collectibles . update_collectibles ( pic_nickname , pic_name , user ) do
51
+ { :ok , _ } ->
52
+ text ( conn , "OK" )
53
+ { :error , { status , message } } ->
54
+ conn
55
+ |> put_status ( status )
56
+ |> text ( message )
57
+ end
58
+ end
59
+
60
+ swagger_path :collectiblesUpdate do
67
61
post ( "/user" )
68
62
summary ( "add one collectible to the user" )
69
63
security ( [ % { JWT: [ ] } ] )
64
+ consumes ( "application/json" )
65
+ produces ( "application/json" )
66
+ parameters do
67
+ picNickname ( :path , :string , "picture nickname" , required: true )
68
+ questionId ( :path , :string , "picture name" , required: true )
69
+ end
70
70
response ( 200 , "OK" )
71
71
response ( 400 , "Invalid parameters" )
72
72
response ( 401 , "Unauthorised" )
73
73
end
74
74
75
+
76
+
77
+
78
+
75
79
def swagger_definitions do
76
80
% {
77
81
UserInfo:
0 commit comments