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

source-academy / backend / e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

31 Mar 2025 09:12AM UTC coverage: 19.982% (-73.6%) from 93.607%
e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

Pull #1236

github

RichDom2185
Redate migrations to maintain total ordering
Pull Request #1236: Added Exam mode

12 of 57 new or added lines in 8 files covered. (21.05%)

2430 existing lines in 97 files now uncovered.

671 of 3358 relevant lines covered (19.98%)

3.03 hits per line

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

0.0
/lib/cadet_web/controllers/team_controller.ex
1
defmodule CadetWeb.TeamController do
2
  @moduledoc """
3
  Controller module for handling team-related actions.
4
  """
5

6
  use CadetWeb, :controller
7
  use PhoenixSwagger
8

9
  import Ecto.Query
10

11
  alias Cadet.Repo
12
  alias Cadet.Accounts.Team
13

14
  def index(conn, %{"assessmentid" => assessment_id}) when is_ecto_id(assessment_id) do
UNCOV
15
    cr = conn.assigns.course_reg
×
16

UNCOV
17
    query =
×
UNCOV
18
      from(t in Team,
×
19
        where: t.assessment_id == ^assessment_id,
20
        join: tm in assoc(t, :team_members),
UNCOV
21
        where: tm.student_id == ^cr.id,
×
22
        limit: 1
23
      )
24

UNCOV
25
    team =
×
26
      query
27
      |> Repo.one()
28
      |> Repo.preload(assessment: [:config], team_members: [student: [:user]])
29

UNCOV
30
    if team == nil do
×
31
      conn
32
      |> put_status(:not_found)
UNCOV
33
      |> text("Team is not found!")
×
34
    else
UNCOV
35
      team_formation_overview = team_to_team_formation_overview(team)
×
36

37
      conn
38
      |> put_status(:ok)
39
      |> put_resp_content_type("application/json")
UNCOV
40
      |> render("index.json", teamFormationOverview: team_formation_overview)
×
41
    end
42
  end
43

44
  defp team_to_team_formation_overview(team) do
UNCOV
45
    assessment = team.assessment
×
46

UNCOV
47
    team_formation_overview = %{
×
UNCOV
48
      teamId: team.id,
×
UNCOV
49
      assessmentId: assessment.id,
×
UNCOV
50
      assessmentName: assessment.title,
×
UNCOV
51
      assessmentType: assessment.config.type,
×
UNCOV
52
      studentIds: team.team_members |> Enum.map(& &1.student.user.id),
×
UNCOV
53
      studentNames: team.team_members |> Enum.map(& &1.student.user.name)
×
54
    }
55

UNCOV
56
    team_formation_overview
×
57
  end
58

UNCOV
59
  swagger_path :index do
×
60
    get("/admin/teams")
61

62
    summary("Fetches team formation overview based on assessment ID")
63

64
    security([%{JWT: []}])
65

66
    parameters do
67
      assessmentid(:query, :string, "Assessment ID", required: true)
68
    end
69

70
    response(200, "OK", Schema.ref(:TeamFormationOverview))
71
    response(404, "Not Found")
72
    response(403, "Forbidden")
73
  end
74

75
  def swagger_definitions do
76
    %{
×
77
      TeamFormationOverview: %{
78
        "type" => "object",
79
        "properties" => %{
80
          "teamId" => %{"type" => "number", "description" => "The ID of the team"},
81
          "assessmentId" => %{"type" => "number", "description" => "The ID of the assessment"},
82
          "assessmentName" => %{"type" => "string", "description" => "The name of the assessment"},
83
          "assessmentType" => %{"type" => "string", "description" => "The type of the assessment"},
84
          "studentIds" => %{
85
            "type" => "array",
86
            "items" => %{"type" => "number"},
87
            "description" => "List of student IDs"
88
          },
89
          "studentNames" => %{
90
            "type" => "array",
91
            "items" => %{"type" => "string"},
92
            "description" => "List of student names"
93
          }
94
        },
95
        "required" => [
96
          "teamId",
97
          "assessmentId",
98
          "assessmentName",
99
          "assessmentType",
100
          "studentIds",
101
          "studentNames"
102
        ]
103
      }
104
    }
105
  end
106
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