Working test version of confirmation email delivery
This commit is contained in:
15
lib/osuuspuutarha/confirmation_sender.ex
Normal file
15
lib/osuuspuutarha/confirmation_sender.ex
Normal file
@@ -0,0 +1,15 @@
|
||||
defmodule Osuuspuutarha.ConfirmationSender do
|
||||
@moduledoc """
|
||||
This module is responsible for sending confirmation emails.
|
||||
"""
|
||||
import Swoosh.Email
|
||||
|
||||
def send_confirmation_email(order) do
|
||||
new()
|
||||
|> to({"Testi Testinen", "livonsaaren.tietokonepaja@gmail.com"})
|
||||
|> from({"Livonsaaren Osuuspuutarha", "noreply@livonsaarenosuuspuutarha.fi"})
|
||||
|> subject("Kiitokset tilauksesta!")
|
||||
|> html_body("<h1>Hello #{order.fname}</h1>")
|
||||
|> text_body("Hello #{order.fname}\n")
|
||||
end
|
||||
end
|
||||
@@ -8,6 +8,9 @@ defmodule Osuuspuutarha.Orders do
|
||||
|
||||
alias Osuuspuutarha.Orders.Order
|
||||
|
||||
alias Osuuspuutarha.ConfirmationSender
|
||||
alias Osuuspuutarha.Mailer
|
||||
|
||||
@doc """
|
||||
Returns the list of orders.
|
||||
|
||||
@@ -42,19 +45,34 @@ defmodule Osuuspuutarha.Orders do
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_order(%{field: value})
|
||||
iex> process_order(%{field: value})
|
||||
{:ok, %Order{}}
|
||||
|
||||
iex> create_order(%{field: bad_value})
|
||||
iex> process_order(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_order(attrs \\ %{}) do
|
||||
def process_order(attrs \\ %{}) do
|
||||
case insert_order(attrs) do
|
||||
{:ok, order} ->
|
||||
send_confirmation_email_and_deliver(order)
|
||||
|
||||
{:error, changeset} ->
|
||||
{:error, changeset}
|
||||
end
|
||||
end
|
||||
|
||||
defp insert_order(attrs) do
|
||||
%Order{}
|
||||
|> Order.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
defp send_confirmation_email_and_deliver(order) do
|
||||
ConfirmationSender.send_confirmation_email(order)
|
||||
|> Mailer.deliver()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a order.
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ defmodule OsuuspuutarhaWeb.OrderLive.FormComponent do
|
||||
end
|
||||
|
||||
defp save_order(socket, :new, order_params) do
|
||||
case Orders.create_order(order_params) do
|
||||
case Orders.process_order(order_params) do
|
||||
{:ok, _order} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<h1>Osuuspuutarhan testimaili, <%= @variable %>!</h1>
|
||||
</div>
|
||||
8
lib/osuuspuutarha_web/templates/layout/email.html.heex
Normal file
8
lib/osuuspuutarha_web/templates/layout/email.html.heex
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title><%= @email.subject %></title>
|
||||
</head>
|
||||
<body>
|
||||
<%= @inner_content %>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user