|
@@ -1,9 +1,20 @@
|
|
|
defmodule FourlettersWeb.FourlettersController do
|
|
|
use FourlettersWeb, :controller
|
|
|
+ import Fourletters.Troll
|
|
|
+ import ABCD.Fourletters
|
|
|
|
|
|
def fourletters(conn, %{"messenger" => messenger}) do
|
|
|
if String.length(messenger) == 4 do
|
|
|
- render(conn, "four.html", messenger: messenger)
|
|
|
+
|
|
|
+ {:ok, sup_pid} = Supervisor.start_link(Fourletters.Troll, [])
|
|
|
+ pid = case Supervisor.start_child(
|
|
|
+ sup_pid, %{id: String.to_atom(messenger),
|
|
|
+ start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
|
+ {:ok, pid} -> pid
|
|
|
+ {:error, {:already_started, pid}} -> pid
|
|
|
+ end
|
|
|
+ messages = ABCD.Fourletters.get(pid)
|
|
|
+ render(conn, "four.html", messenger: messenger, messages: messages)
|
|
|
end
|
|
|
redirect(conn, to: "/")
|
|
|
end
|