Created
March 20, 2019 15:35
-
-
Save cybrox/aaf5f81c55f580417772f7bd9948ffa6 to your computer and use it in GitHub Desktop.
phx-ete5.ex
This file contains hidden or 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
post "/db/factory" do | |
# When piped through a generic Phoenix JSON API pipeline, using a route | |
# like this allows you to call your factory via your test API easily. | |
with {:ok, schema} <- Map.fetch(conn.body_params, "schema"), | |
{:ok, attrs} <- Map.fetch(conn.body_params, "attributes") do | |
db_schema = String.to_atom(schema) | |
db_attrs = Enum.map(attrs, fn {k, v} -> {String.to_atom(k), v} end) | |
db_entry = Factory.insert(db_schema, db_attrs) | |
send_resp(conn, 200, Poison.encode!(%{id: db_entry.id})) | |
else | |
_ -> send_resp(conn, 401, "schema or attributes missing") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment