#Api problem on a get method

2 messages · Page 1 of 1 (latest)

grand wraith
#

When I request get I have this error and since I'm a beginner I really can't find the problem? Who can help me?
My controller :

def index(conn, %{"working_times" => working_time_params, "user" => user}) do
    start_ = Map.get(working_time_params, "start", nil)
    end_ = Map.get(working_time_params, "end", nil)
    if start_ != nil && end_ != nil do
      working = TodoWeb.get_user_by_start_and_end!(start_, end_, user)
      render(conn, "show.json", working: working)
    else
      all_worktimes = TodoWeb.list_worktimes()
      case all_worktimes do
        [] ->
          conn
          |> put_status(:not_found)
          |> render("error_list_worktimes.json", message: "No worktimes found")
        _ ->
          render(conn, "index.json", all_worktimes: all_worktimes)
      end
    end
  end

My view :

    %{data: render_many(working_times, WorkingTimeView, "working_time.json")}
  end

  def render("show.json", %{working_times: working_times}) do
    %{data: render_one(working_times, WorkingTimeView, "working_time.json")}
  end

  def render("create.json", %{all_worktimes: all_worktimes}) do
    %{data: render_many(all_worktimes, WorkingTimeView, "working_time.json")}
  end

  def render("working_time.json", %{working_time: working_time}) do
    %{
      id: working_time.id,
      start: working_time.start,
      end: working_time.end,
    }
  end
end

Thank you in advance

robust flame
#

it looks like you are calling render(conn, "show.json", working: working) but the function for show.json wants working_times key