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

camatcode / basenji / 594b515fe95c2d0848feedc055b9a66fb92a59c3

06 Jul 2025 05:05PM UTC coverage: 64.232% (+4.7%) from 59.566%
594b515fe95c2d0848feedc055b9a66fb92a59c3

push

github

web-flow
Merge pull request #24 from camatcode/work/json_api_collections

feat(collections): json_api

43 of 49 new or added lines in 10 files covered. (87.76%)

1 existing line in 1 file now uncovered.

343 of 534 relevant lines covered (64.23%)

385.28 hits per line

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

80.0
/lib/basenji_web/controllers/api/json_api/collections_controller.ex
1
defmodule BasenjiWeb.JSONAPI.CollectionsController do
2
  @moduledoc false
3
  use BasenjiWeb, :controller
4

5
  alias Basenji.Collections
6
  alias BasenjiWeb.API.Utils
7
  alias BasenjiWeb.Plugs.JSONAPIPlug, as: BasenjiJSONAPIPlug
8

9
  plug BasenjiJSONAPIPlug, api: BasenjiWeb.API, path: "collections", resource: Basenji.Collection
10

11
  def index(%{private: %{jsonapi_plug: jsonapi_plug}} = conn, _params) do
12
    collections = Collections.list_collections(Utils.to_opts(jsonapi_plug))
39✔
13
    render(conn, "index.json", %{data: collections})
39✔
14
  end
15

16
  def create(%{private: %{jsonapi_plug: jsonapi_plug}} = conn, params) do
17
    # validate params!
18
    attrs = params["data"]["attributes"] |> Utils.atomize()
1✔
19

20
    Collections.from_resource(params["data"]["attributes"]["resource_location"], attrs, Utils.to_opts(jsonapi_plug))
21
    |> case do
1✔
22
      {:ok, collection} -> render(conn, "create.json", %{data: collection})
1✔
NEW
23
      error -> Utils.bad_request_handler(conn, error)
×
24
    end
25
  end
26

27
  def show(%{private: %{jsonapi_plug: jsonapi_plug}} = conn, params) do
28
    Collections.get_collection(params["id"], Utils.to_opts(jsonapi_plug))
29
    |> case do
1✔
30
      {:ok, comic} ->
31
        render(conn, "create.json", %{data: comic})
1✔
32

33
      _ ->
NEW
34
        Utils.bad_request_handler(conn, {:error, :not_found})
×
35
    end
36
  end
37

38
  def update(%{private: %{jsonapi_plug: jsonapi_plug}} = conn, params) do
39
    id = params["id"]
1✔
40

41
    Collections.update_collection(id, params["data"]["attributes"], Utils.to_opts(jsonapi_plug))
42
    |> case do
1✔
43
      {:ok, collection} -> render(conn, "update.json", %{data: collection})
1✔
NEW
44
      e -> Utils.bad_request_handler(conn, e)
×
45
    end
46
  end
47

48
  def delete(conn, params) do
49
    {:ok, deleted} = Collections.delete_collection(params["id"])
1✔
50
    render(conn, "show.json", %{data: deleted})
1✔
51
  end
52
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

© 2026 Coveralls, Inc