-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: data_reference controller (#184)
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
apps/lenra_web/lib/lenra_web/controllers/data_reference_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule LenraWeb.DataReferenceController do | ||
use LenraWeb, :controller | ||
|
||
alias Lenra.DataReferencesServices | ||
|
||
def create(conn, params) do | ||
with {:ok, inserted_reference: reference} <- DataReferencesServices.create(params) do | ||
conn | ||
|> assign_data(:inserted_reference, reference) | ||
|> reply | ||
end | ||
end | ||
|
||
def delete(conn, params) do | ||
with {:ok, deleted_reference: reference} <- DataReferencesServices.delete(params) do | ||
conn | ||
|> assign_data(:deleted_reference, reference) | ||
|> reply | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
apps/lenra_web/test/controllers/data_reference_controller_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule LenraWeb.DataReferenceControllerTest do | ||
@moduledoc """ | ||
Test the `LenraWeb.DataReferenceController` module | ||
""" | ||
|
||
use LenraWeb.ConnCase, async: true | ||
|
||
alias Lenra.{Environment, LenraApplication, Repo} | ||
|
||
setup %{conn: conn} do | ||
{:ok, %{conn: conn}} | ||
end | ||
|
||
defp create_app_and_get_env(conn) do | ||
post(conn, Routes.apps_path(conn, :create), %{ | ||
"name" => "test", | ||
"color" => "ffffff", | ||
"icon" => 12 | ||
}) | ||
|
||
Repo.get_by(Environment, application_id: Enum.at(Repo.all(LenraApplication), 0).id) | ||
end | ||
|
||
# TODO make tests when route are defined | ||
describe "LenraWeb.DataReferenceController.create_2/1" do | ||
test "should create data if params valid" do | ||
end | ||
|
||
test "should return error if params not valid" do | ||
end | ||
end | ||
|
||
describe "LenraWeb.DataReferenceController.delete_1/1" do | ||
test "should delete data if id valid" do | ||
end | ||
|
||
test "should return error if id invalid" do | ||
end | ||
end | ||
end |