Expose all coaches as JSON dump.
parent
2697c7469b
commit
8bf4167e61
|
@ -0,0 +1,10 @@
|
||||||
|
defmodule BoardWiseWeb.CoachController do
|
||||||
|
use BoardWiseWeb, :controller
|
||||||
|
|
||||||
|
alias BoardWise.Coaches
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
coaches = Coaches.list_coaches()
|
||||||
|
render(conn, :index, coaches: coaches)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule BoardWiseWeb.CoachJSON do
|
||||||
|
alias BoardWise.Coaches.Coach
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a list of coaches.
|
||||||
|
"""
|
||||||
|
def index(%{coaches: coaches}) do
|
||||||
|
%{data: for(coach <- coaches, do: data(coach))}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp data(%Coach{} = coach) do
|
||||||
|
%{
|
||||||
|
site: coach.site,
|
||||||
|
username: coach.username,
|
||||||
|
rapid: coach.rapid,
|
||||||
|
blitz: coach.blitz,
|
||||||
|
bullet: coach.bullet
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,12 @@ defmodule BoardWiseWeb.Router do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope "/api", BoardWiseWeb do
|
||||||
|
pipe_through :api
|
||||||
|
|
||||||
|
get "/coaches", CoachController, :index
|
||||||
|
end
|
||||||
|
|
||||||
# Other scopes may use custom stacks.
|
# Other scopes may use custom stacks.
|
||||||
# scope "/api", BoardWiseWeb do
|
# scope "/api", BoardWiseWeb do
|
||||||
# pipe_through :api
|
# pipe_through :api
|
||||||
|
|
Loading…
Reference in New Issue