-
-
Save drewolson/ddcbedbc4780c5066bbd to your computer and use it in GitHub Desktop.
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
defmodule Ensemble.InterviewController do | |
use Phoenix.Controller | |
alias Ensemble.Interview | |
plug :action | |
def index(conn, _params) do | |
render conn, :index, | |
recent: Interview.recent |> Ensemble.Repo.all, | |
upcoming: Interview.upcoming |> Ensemble.Repo.all, | |
today: Interview.today |> Ensemble.Repo.all | |
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
defimpl Poison.Encoder, for: Ensemble.Interview do | |
alias Ensemble.Interview | |
alias Ensemble.Interviewer | |
def encode(interview, _options) do | |
%{ | |
candidate: interview.candidate, | |
date: Ensemble.Helper.Date.serialize_date(interview.date), | |
position: interview.position, | |
sessions: sessions(interview) | |
} |> Poison.Encoder.encode([]) | |
end | |
defp sessions(interview) do | |
Enum.map(Interview.sessions, fn session -> | |
%{ | |
session: session, | |
team: team_name(interview, session), | |
interviewers: Interviewer.for_session(interview, session) |> Ensemble.Repo.all | |
} | |
end) | |
end | |
defp team_name(_interview, "lunch") do | |
"" | |
end | |
defp team_name(interview, session) do | |
Map.get(interview, String.to_atom(session)).name | |
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
defmodule Ensemble.InterviewView do | |
use Ensemble.Web, :view | |
alias Ensemble.Interviewer | |
def render("index.json", %{recent: recent, upcoming: upcoming, today: today}) do | |
%{ | |
today: today, | |
recent: recent, | |
upcoming: upcoming | |
} | |
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
defimpl Poison.Encoder, for: Ensemble.Interviewer do | |
def encode(interviewer, _options) do | |
interviewer.employee.name |> Poison.Encoder.encode([]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment