From 0280c122af6136e929ce9739d9b1d0326be4a4cc Mon Sep 17 00:00:00 2001 From: Erick Macedo Pinto Date: Tue, 19 Oct 2021 23:58:43 -0300 Subject: [PATCH] Add module to create supply --- lib/inmana/supplies/create.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/inmana/supplies/create.ex diff --git a/lib/inmana/supplies/create.ex b/lib/inmana/supplies/create.ex new file mode 100644 index 0000000..b56115f --- /dev/null +++ b/lib/inmana/supplies/create.ex @@ -0,0 +1,14 @@ +defmodule Inmana.Supplies.Create do + alias Inmana.{Repo, Supply} + + def call(params) do + params + |> Supply.changeset() + |> Repo.insert() + |> handle_insert() + end + + defp handle_insert({:ok, %Supply{}} = result), do: result + + defp handle_insert({:error, result}), do: {:error, %{result: result, status: :bad_request}} +end