Created
November 24, 2018 01:02
-
-
Save feymartynov/1101755722bd5519686c760ecf11c027 to your computer and use it in GitHub Desktop.
ExOperation article: Setup
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
# mix.exs | |
{:ex_operation, “~> 0.4”} | |
# config/config.exs | |
config :ex_operation, repo: MyApp.Repo | |
# lib/myapp/operation.ex | |
defmodule MyApp.Operation do | |
defmacro __using__(opts) do | |
quote do | |
use ExOperation.Operation, unquote(opts) | |
import MyApp.Operation | |
end | |
end | |
# custom DSL extensions | |
end | |
# lib/myapp_web.ex | |
def run(operation, conn, params) do | |
context = %{user: conn.assigns.current_user} | |
operation |> ExOperation.run(context, params) | |
end | |
# lib/myapp_web/controllers/order_controller.ex | |
def checkout(conn, params) do | |
with {:ok, %{result: order}} <- Order.Checkout |> run(conn, params) do | |
render conn, order: order | |
end | |
end |
Yea I just hooked that in. The gist should say where within lib/myapp_web.ex
preferably within the def controller ...
It's tripped me a few times :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've never had any success with the function at
lib/myapp_web.ex
Do you have a sample that shows this setup?