server/lib/boardwise_web/controllers/coach_controller.ex

29 lines
634 B
Elixir
Raw Normal View History

2023-12-04 14:39:27 +00:00
defmodule BoardWiseWeb.CoachController do
use BoardWiseWeb, :controller
2023-12-06 02:46:27 +00:00
require Logger
2023-12-04 14:39:27 +00:00
alias BoardWise.Coaches
2023-12-06 02:46:27 +00:00
plug :fetch_query_params
def index(conn, params) do
page_no = get_integer_param(params, "page_no", 1)
page_size = get_integer_param(params, "page_size", 10)
coaches = Coaches.page_coaches(page_no, page_size)
2023-12-04 14:39:27 +00:00
render(conn, :index, coaches: coaches)
end
2023-12-06 02:46:27 +00:00
defp get_integer_param(params, key, default) do
val = Map.get(params, key)
if is_nil(val) do
default
else
case Integer.parse(val) do
{parsed, ""} -> parsed
_ -> default
end
end
end
2023-12-04 14:39:27 +00:00
end