Working test version of confirmation email delivery

This commit is contained in:
2025-03-16 20:22:48 +02:00
parent d21b92045e
commit a454bb2c49
12 changed files with 82 additions and 20 deletions

View 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

View File

@@ -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.

View File

@@ -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

View File

@@ -0,0 +1,3 @@
<div>
<h1>Osuuspuutarhan testimaili, <%= @variable %>!</h1>
</div>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<title><%= @email.subject %></title>
</head>
<body>
<%= @inner_content %>
</body>
</html>