Expose all coaches as JSON dump.

pull/3/head
Joshua Potter 2023-12-04 07:39:27 -07:00
parent 2697c7469b
commit 8bf4167e61
3 changed files with 36 additions and 0 deletions

View File

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

View File

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

View File

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