Skip to content

Commit

Permalink
Add module to create restaurant
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Sep 22, 2021
1 parent e47fb1e commit 8e4f0b6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/inmana/restaurants/create.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Inmana.Restaurants.Create do
alias Inmana.{Repo, Restaurant}

def call(params) do
params
|> Restaurant.changeset()
|> Repo.insert()
|> handle_insert()
end

defp handle_insert({:ok, %Restaurant{}} = result), do: result

defp handle_insert({:error, result}), do: {:error, %{result: result, status: :bad_request}}
end

0 comments on commit 8e4f0b6

Please sign in to comment.