Handling requests in a controller
At this point, the request is in the controller, which was called by the router according to the logic we described. We'll build the FileController
that we saw in the router, and go through the four actions we've created routes for: index, show, new. and create. Let's begin with the index action:
$ cat apps/elixir_drip_web/lib/elixir_drip_web/controllers/ file_controller.ex defmodule ElixirDripWeb.FileController do use ElixirDripWeb, :controller alias ElixirDrip.Storage def index(conn, %{"path" => path}) do with {:ok, media} <- Storage.media_by_folder("hardcoded_user_id", path) do render(conn, "index.html", files: media.files, folders: media.folders, current_path: path) else {:error, :invalid_path} -> conn |> put_flash(:error, "The path provided is invalid.") |> redirect(to: file_path(conn, :index, "path": "$")) _ -> conn |> put_flash(:error, "Unexpected...