I have a Accounts context. One of its jobs is to invite new users.
MyApp.Accounts.invite(%{...})
I invoke it from my controller like so.
def create(conn, %{"user" => user_params}) do
case Accounts.invite_user(user_params) do
{:ok, user} ->
conn
...
{:error, %Ecto.Changeset{} = changeset} ->
...
end
end
I would like for the email to be sent as a part of the logic from invite_user/1
and this is where things get a little funky.
Currently I’m using Bamboo and there seems to be a lot of nice helpers for rending views ect.
Such as use Bamboo.Phoenix, view: MyApp.EmailView
But right there I start to think this logic belongs in the web side of things not in my context side. To make things worse I’m finding there is a need to pass conn
from the controller to invite_user because I need to give it to the templates for use with route helpers.
My question is not so directly related to the context above, but rather where do you draw the line from bleeding things from your web side into the context side? IE: I’ve been told that I should not send the conn to my context since its really the concern of the controller, does that mean I should extract the logic for emailing in to my controller / web side?
IDK, just feeling like designing right now is really hard.
I guess my point is that I’m finding myself calling logic back and forth between calling web logic from in my contexts and that feels like a smell. Thoughts?