• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / 18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

08 Sep 2024 06:14PM UTC coverage: 79.088% (-15.3%) from 94.372%
18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

Pull #1180

github

josh1248
Change appropriate routes into admin scope
Pull Request #1180: Transfer groundControl (and admin panel) from staff to admin route

7 of 12 new or added lines in 1 file covered. (58.33%)

499 existing lines in 25 files now uncovered.

2602 of 3290 relevant lines covered (79.09%)

1023.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.69
/lib/cadet_web/admin_controllers/admin_goals_controller.ex
1
defmodule CadetWeb.AdminGoalsController do
2
  use CadetWeb, :controller
3

4
  use PhoenixSwagger
5

6
  alias Cadet.Incentives.Goals
7
  alias Cadet.Accounts.CourseRegistration
8

9
  def index(conn, _) do
UNCOV
10
    course_id = conn.assigns.course_reg.course_id
×
UNCOV
11
    render(conn, "index.json", goals: Goals.get(course_id))
×
12
  end
13

14
  def index_goals_with_progress(conn, %{"course_reg_id" => course_reg_id}) do
UNCOV
15
    course_id = conn.assigns.course_reg.course_id
×
UNCOV
16
    course_reg = %CourseRegistration{id: String.to_integer(course_reg_id), course_id: course_id}
×
17

UNCOV
18
    render(conn, "index_goals_with_progress.json", goals: Goals.get_with_progress(course_reg))
×
19
  end
20

21
  def bulk_update(conn, %{"goals" => goals}) do
UNCOV
22
    course_reg = conn.assigns.course_reg
×
23

24
    goals
UNCOV
25
    |> Enum.map(&json_to_goal(&1, course_reg.course_id))
×
26
    |> Goals.upsert_many()
UNCOV
27
    |> handle_standard_result(conn)
×
28
  end
29

30
  def update(conn, %{"uuid" => uuid, "goal" => goal}) do
UNCOV
31
    course_reg = conn.assigns.course_reg
×
32

33
    goal
UNCOV
34
    |> json_to_goal(course_reg.course_id, uuid)
×
35
    |> Goals.upsert()
UNCOV
36
    |> handle_standard_result(conn)
×
37
  end
38

39
  def update_progress(conn, %{
40
        "uuid" => uuid,
41
        "course_reg_id" => course_reg_id,
42
        "progress" => progress
43
      }) do
UNCOV
44
    course_reg_id = String.to_integer(course_reg_id)
×
45

46
    progress
47
    |> json_to_progress(uuid, course_reg_id)
48
    |> Goals.upsert_progress(uuid, course_reg_id)
UNCOV
49
    |> handle_standard_result(conn)
×
50
  end
51

52
  def delete(conn, %{"uuid" => uuid}) do
UNCOV
53
    course_reg = conn.assigns.course_reg
×
54

55
    uuid
UNCOV
56
    |> Goals.delete(course_reg.course_id)
×
UNCOV
57
    |> handle_standard_result(conn)
×
58
  end
59

60
  defp json_to_goal(json, course_id, uuid \\ nil) do
UNCOV
61
    original_meta = json["meta"]
×
62

UNCOV
63
    json =
×
64
      json
65
      |> snake_casify_string_keys_recursive()
66
      |> Map.put("meta", original_meta)
67
      |> Map.put("course_id", course_id)
68

UNCOV
69
    if is_nil(uuid) do
×
UNCOV
70
      json
×
71
    else
UNCOV
72
      Map.put(json, "uuid", uuid)
×
73
    end
74
  end
75

76
  defp json_to_progress(json, uuid, course_reg_id) do
UNCOV
77
    json =
×
78
      json
79
      |> snake_casify_string_keys_recursive()
80

UNCOV
81
    %{
×
82
      count: Map.get(json, "count"),
83
      completed: Map.get(json, "completed"),
84
      goal_uuid: uuid,
85
      course_reg_id: course_reg_id
86
    }
87
  end
88

89
  swagger_path :index do
1✔
90
    get("/admin/goals")
91

92
    summary("Gets goals")
93
    security([%{JWT: []}])
94

95
    response(200, "OK", Schema.array(:Goal))
96
    response(401, "Unauthorised")
97
    response(403, "Forbidden")
98
  end
99

100
  swagger_path :index_goals_with_progress do
1✔
101
    get("/admin/goals/{courseRegId}")
102

103
    summary("Gets goals and goal progress of a user")
104
    security([%{JWT: []}])
105

106
    parameters do
107
      courseRegId(:path, :integer, "Course Reg ID", required: true)
108
    end
109

110
    response(200, "OK", Schema.array(:GoalWithProgress))
111
    response(401, "Unauthorised")
112
    response(403, "Forbidden")
113
  end
114

115
  swagger_path :update do
1✔
116
    put("/admin/goals/{uuid}")
117

118
    summary("Inserts or updates a goal")
119

120
    security([%{JWT: []}])
121

122
    parameters do
123
      uuid(:path, :string, "Goal UUID", required: true, format: :uuid)
124

125
      goal(
126
        :body,
127
        Schema.ref(:Goal),
128
        "The goal to insert, or properties to update",
129
        required: true
130
      )
131
    end
132

133
    response(204, "Success")
134
    response(401, "Unauthorised")
135
    response(403, "Forbidden")
136
  end
137

138
  swagger_path :bulk_update do
1✔
139
    put("/admin/goals")
140

141
    summary("Inserts or updates goals")
142

143
    security([%{JWT: []}])
144

145
    parameters do
146
      goals(
147
        :body,
148
        Schema.array(:Goal),
149
        "The goals to insert or sets of properties to update",
150
        required: true
151
      )
152
    end
153

154
    response(204, "Success")
155
    response(401, "Unauthorised")
156
    response(403, "Forbidden")
157
  end
158

159
  swagger_path :update_progress do
1✔
160
    post("/admin/users/{courseRegId}/goals/{uuid}/progress")
161

162
    summary("Inserts or updates own goal progress of specifed goal")
163
    security([%{JWT: []}])
164

165
    parameters do
166
      uuid(:path, :string, "Goal UUID", required: true, format: :uuid)
167
      courseRegId(:path, :integer, "Course Reg ID", required: true)
168

169
      progress(
170
        :body,
171
        Schema.ref(:GoalProgress),
172
        "The goal progress to insert or update",
173
        required: true
174
      )
175
    end
176

177
    response(204, "Success")
178
    response(401, "Unauthorised")
179
    response(403, "Forbidden")
180
  end
181

182
  swagger_path :delete do
1✔
183
    PhoenixSwagger.Path.delete("/admin/goals/{uuid}")
184

185
    summary("Deletes a goal")
186
    security([%{JWT: []}])
187

188
    parameters do
189
      uuid(:path, :string, "Goal UUID", required: true, format: :uuid)
190
    end
191

192
    response(204, "Success")
193
    response(401, "Unauthorised")
194
    response(403, "Forbidden")
195
    response(404, "Goal not found")
196
  end
197
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc