• 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

36.84
/lib/cadet_web/admin_controllers/admin_stories_controller.ex
1
defmodule CadetWeb.AdminStoriesController do
2
  use CadetWeb, :controller
3
  use PhoenixSwagger
4

5
  alias Cadet.Stories.Stories
6

7
  def create(conn, %{"course_id" => course_id, "story" => story}) do
UNCOV
8
    result =
×
9
      story
10
      |> to_snake_case_atom_keys()
11
      |> Stories.create_story(course_id |> String.to_integer())
12

UNCOV
13
    case result do
×
14
      {:ok, _story} ->
UNCOV
15
        conn |> put_status(200) |> text('')
×
16

17
      {:error, {status, message}} ->
18
        conn
19
        |> put_status(status)
UNCOV
20
        |> text(message)
×
21
    end
22
  end
23

24
  def update(conn, _params = %{"course_id" => course_id, "storyid" => id, "story" => story}) do
UNCOV
25
    result =
×
26
      story
27
      |> to_snake_case_atom_keys()
28
      |> Stories.update_story(id, course_id |> String.to_integer())
29

UNCOV
30
    case result do
×
31
      {:ok, _story} ->
UNCOV
32
        conn |> put_status(200) |> text('')
×
33

34
      {:error, {status, message}} ->
35
        conn
36
        |> put_status(status)
UNCOV
37
        |> text(message)
×
38
    end
39
  end
40

41
  def delete(conn, _params = %{"course_id" => course_id, "storyid" => id}) do
UNCOV
42
    result = Stories.delete_story(id, course_id |> String.to_integer())
×
43

UNCOV
44
    case result do
×
45
      {:ok, _nil} ->
UNCOV
46
        conn |> put_status(204) |> text('')
×
47

48
      {:error, {status, message}} ->
49
        conn
50
        |> put_status(status)
UNCOV
51
        |> text(message)
×
52
    end
53
  end
54

55
  swagger_path :create do
1✔
56
    post("/courses/{course_id}/admin/stories")
57

58
    summary("Creates a new story")
59

60
    security([%{JWT: []}])
61

62
    response(200, "OK", :Story)
63
    response(400, "Bad request")
64
    response(403, "User not allowed to manage stories")
65
  end
66

67
  swagger_path :delete do
1✔
68
    PhoenixSwagger.Path.delete("/courses/{course_id}/admin/stories/{storyId}")
69

70
    summary("Delete a story from database by id")
71

72
    parameters do
73
      storyId(:path, :integer, "Story Id", required: true)
74
    end
75

76
    security([%{JWT: []}])
77

78
    response(204, "OK")
79
    response(403, "User not allowed to manage stories or stories from another course")
80
    response(404, "Story not found")
81
  end
82

83
  swagger_path :update do
1✔
84
    post("/courses/{course_id}/admin/stories/{storyId}")
85

86
    summary("Update details regarding a story")
87

88
    parameters do
89
      storyId(:path, :integer, "Story Id", required: true)
90
    end
91

92
    security([%{JWT: []}])
93

94
    produces("application/json")
95

96
    response(200, "OK", :Story)
97
    response(403, "User not allowed to manage stories or stories from another course")
98
    response(404, "Story not found")
99
  end
100

101
  @spec swagger_definitions :: %{Story: any}
102
  def swagger_definitions do
103
    %{
1✔
104
      Story:
105
        swagger_schema do
1✔
106
          properties do
1✔
107
            filenames(schema_array(:string), "Filenames of txt files", required: true)
108
            title(:string, "Title shown in Chapter Select Screen", required: true)
109
            imageUrl(:string, "Path to image shown in Chapter Select Screen", required: false)
110
            openAt(:string, "The opening date", format: "date-time", required: true)
111
            closeAt(:string, "The closing date", format: "date-time", required: true)
112
            isPublished(:boolean, "Whether or not is published", required: false)
113
            course_id(:integer, "The id of the course that this story belongs to", required: true)
1✔
114
          end
115
        end
116
    }
117
  end
118
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