-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
4645828
commit 8d142f0
Showing
4 changed files
with
54 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule AfcWeb.EmotionController do | ||
use AfcWeb, :controller | ||
alias Afc.{Angry, Happy, Repo} | ||
|
||
def show(conn, %{"id" => emotion}) do | ||
{module, changeset} = get_page_module_and_changeset(emotion) | ||
|
||
render conn, "form.html", changeset: changeset, module: module | ||
end | ||
|
||
def create(conn, params) do | ||
submitted_emotion = | ||
~w(angry happy) | ||
|> Enum.filter(&(Map.has_key?(params, &1))) | ||
|> hd() | ||
|
||
form_info = Map.get(params, submitted_emotion) | ||
|
||
{module, changeset} = | ||
get_page_module_and_changeset(submitted_emotion, form_info) | ||
|
||
case Repo.insert(changeset) do | ||
{:ok, _captured_emotion} -> | ||
|
||
# The emotion itself has been captured at this point. Next step | ||
# is to insert into the emotion_log table. | ||
render conn, "captured.html" | ||
|
||
{:error, changeset} -> | ||
render conn, "form.html", changeset: changeset, module: module | ||
end | ||
end | ||
|
||
defp get_page_module_and_changeset(page, params \\ %{}) do | ||
case page do | ||
"happy" -> | ||
{Happy, Happy.changeset(%Happy{}, params)} | ||
"angry" -> | ||
{Angry, Angry.changeset(%Angry{}, params)} | ||
end | ||
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div class="tc w4"> | ||
<a href="/" class="pointer link black"> | ||
<%= link to: emotion_path(@conn, :show, @page), class: "pointer link black" do %> | ||
<%= emoji_p_tag(@emoji) %> | ||
<p class="-mt2"><%= @emotion %></p> | ||
</a> | ||
<%= end %> | ||
</div> |
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