-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mix phx.gen.html Ctx Sent sent ... dwyl/aws-ses-lambda#3
- Loading branch information
Showing
13 changed files
with
479 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
defmodule App.Ctx do | ||
@moduledoc """ | ||
The Ctx context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias App.Repo | ||
|
||
alias App.Ctx.Sent | ||
|
||
@doc """ | ||
Returns the list of sent. | ||
## Examples | ||
iex> list_sent() | ||
[%Sent{}, ...] | ||
""" | ||
def list_sent do | ||
Repo.all(Sent) | ||
end | ||
|
||
@doc """ | ||
Gets a single sent. | ||
Raises `Ecto.NoResultsError` if the Sent does not exist. | ||
## Examples | ||
iex> get_sent!(123) | ||
%Sent{} | ||
iex> get_sent!(456) | ||
** (Ecto.NoResultsError) | ||
""" | ||
def get_sent!(id), do: Repo.get!(Sent, id) | ||
|
||
@doc """ | ||
Creates a sent. | ||
## Examples | ||
iex> create_sent(%{field: value}) | ||
{:ok, %Sent{}} | ||
iex> create_sent(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def create_sent(attrs \\ %{}) do | ||
%Sent{} | ||
|> Sent.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a sent. | ||
## Examples | ||
iex> update_sent(sent, %{field: new_value}) | ||
{:ok, %Sent{}} | ||
iex> update_sent(sent, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def update_sent(%Sent{} = sent, attrs) do | ||
sent | ||
|> Sent.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Deletes a sent. | ||
## Examples | ||
iex> delete_sent(sent) | ||
{:ok, %Sent{}} | ||
iex> delete_sent(sent) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def delete_sent(%Sent{} = sent) do | ||
Repo.delete(sent) | ||
end | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking sent changes. | ||
## Examples | ||
iex> change_sent(sent) | ||
%Ecto.Changeset{source: %Sent{}} | ||
""" | ||
def change_sent(%Sent{} = sent) do | ||
Sent.changeset(sent, %{}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule App.Ctx.Sent do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "sent" do | ||
field :message_id, :string | ||
field :request_id, :string | ||
field :template, :string | ||
field :person_id, :id | ||
field :status_id, :id | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(sent, attrs) do | ||
sent | ||
|> cast(attrs, [:message_id, :request_id, :template]) | ||
|> validate_required([:message_id, :request_id, :template]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule AppWeb.SentController do | ||
use AppWeb, :controller | ||
|
||
alias App.Ctx | ||
alias App.Ctx.Sent | ||
|
||
def index(conn, _params) do | ||
sent = Ctx.list_sent() | ||
render(conn, "index.html", sent: sent) | ||
end | ||
|
||
def new(conn, _params) do | ||
changeset = Ctx.change_sent(%Sent{}) | ||
render(conn, "new.html", changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"sent" => sent_params}) do | ||
case Ctx.create_sent(sent_params) do | ||
{:ok, sent} -> | ||
conn | ||
|> put_flash(:info, "Sent created successfully.") | ||
|> redirect(to: Routes.sent_path(conn, :show, sent)) | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, "new.html", changeset: changeset) | ||
end | ||
end | ||
|
||
def show(conn, %{"id" => id}) do | ||
sent = Ctx.get_sent!(id) | ||
render(conn, "show.html", sent: sent) | ||
end | ||
|
||
def edit(conn, %{"id" => id}) do | ||
sent = Ctx.get_sent!(id) | ||
changeset = Ctx.change_sent(sent) | ||
render(conn, "edit.html", sent: sent, changeset: changeset) | ||
end | ||
|
||
def update(conn, %{"id" => id, "sent" => sent_params}) do | ||
sent = Ctx.get_sent!(id) | ||
|
||
case Ctx.update_sent(sent, sent_params) do | ||
{:ok, sent} -> | ||
conn | ||
|> put_flash(:info, "Sent updated successfully.") | ||
|> redirect(to: Routes.sent_path(conn, :show, sent)) | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, "edit.html", sent: sent, changeset: changeset) | ||
end | ||
end | ||
|
||
def delete(conn, %{"id" => id}) do | ||
sent = Ctx.get_sent!(id) | ||
{:ok, _sent} = Ctx.delete_sent(sent) | ||
|
||
conn | ||
|> put_flash(:info, "Sent deleted successfully.") | ||
|> redirect(to: Routes.sent_path(conn, :index)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>Edit Sent</h1> | ||
|
||
<%= render "form.html", Map.put(assigns, :action, Routes.sent_path(@conn, :update, @sent)) %> | ||
|
||
<span><%= link "Back", to: Routes.sent_path(@conn, :index) %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%= form_for @changeset, @action, fn f -> %> | ||
<%= if @changeset.action do %> | ||
<div class="alert alert-danger"> | ||
<p>Oops, something went wrong! Please check the errors below.</p> | ||
</div> | ||
<% end %> | ||
|
||
<%= label f, :message_id %> | ||
<%= text_input f, :message_id %> | ||
<%= error_tag f, :message_id %> | ||
|
||
<%= label f, :request_id %> | ||
<%= text_input f, :request_id %> | ||
<%= error_tag f, :request_id %> | ||
|
||
<%= label f, :template %> | ||
<%= text_input f, :template %> | ||
<%= error_tag f, :template %> | ||
|
||
<div> | ||
<%= submit "Save" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<h1>Listing Sent</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Message</th> | ||
<th>Request</th> | ||
<th>Template</th> | ||
|
||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= for sent <- @sent do %> | ||
<tr> | ||
<td><%= sent.message_id %></td> | ||
<td><%= sent.request_id %></td> | ||
<td><%= sent.template %></td> | ||
|
||
<td> | ||
<span><%= link "Show", to: Routes.sent_path(@conn, :show, sent) %></span> | ||
<span><%= link "Edit", to: Routes.sent_path(@conn, :edit, sent) %></span> | ||
<span><%= link "Delete", to: Routes.sent_path(@conn, :delete, sent), method: :delete, data: [confirm: "Are you sure?"] %></span> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<span><%= link "New Sent", to: Routes.sent_path(@conn, :new) %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New Sent</h1> | ||
|
||
<%= render "form.html", Map.put(assigns, :action, Routes.sent_path(@conn, :create)) %> | ||
|
||
<span><%= link "Back", to: Routes.sent_path(@conn, :index) %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<h1>Show Sent</h1> | ||
|
||
<ul> | ||
|
||
<li> | ||
<strong>Message:</strong> | ||
<%= @sent.message_id %> | ||
</li> | ||
|
||
<li> | ||
<strong>Request:</strong> | ||
<%= @sent.request_id %> | ||
</li> | ||
|
||
<li> | ||
<strong>Template:</strong> | ||
<%= @sent.template %> | ||
</li> | ||
|
||
</ul> | ||
|
||
<span><%= link "Edit", to: Routes.sent_path(@conn, :edit, @sent) %></span> | ||
<span><%= link "Back", to: Routes.sent_path(@conn, :index) %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule AppWeb.SentView do | ||
use AppWeb, :view | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule App.Repo.Migrations.CreateSent do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:sent) do | ||
add :message_id, :string | ||
add :request_id, :string | ||
add :template, :string | ||
add :person_id, references(:people, on_delete: :nothing) | ||
add :status_id, references(:status, on_delete: :nothing) | ||
|
||
timestamps() | ||
end | ||
|
||
create index(:sent, [:person_id]) | ||
create index(:sent, [:status_id]) | ||
end | ||
end |
Oops, something went wrong.