meta/lib/recycledcloud_web/controllers/support_controller.ex
2021-02-02 18:49:11 +01:00

29 lines
828 B
Elixir

defmodule RecycledCloudWeb.SupportController do
use RecycledCloudWeb, :controller
alias RecycledCloud.SupportRequest
def new(conn, _params) do
conn
|> assign(:request_changeset, SupportRequest.changeset(%SupportRequest{}, %{}))
|> render("new.html")
end
def create(conn, %{"support_request" => request} = params) do
action = SupportRequest.changeset(%SupportRequest{}, request)
|> Ecto.Changeset.apply_action(:update)
case action do
{:ok, request} ->
SupportRequest.send(request)
conn
|> put_flash(:info, "Request has been sent. We'll come back to you.")
|> redirect(to: Routes.page_path(conn, :index))
{:error, changeset} ->
conn
|> assign(:request_changeset, changeset)
|> render("new.html")
end
end
end