diff --git a/lib/faces/gallery/github_user_data.ex b/lib/faces/gallery/github_user_data.ex index e50f5f0..3d09fdf 100644 --- a/lib/faces/gallery/github_user_data.ex +++ b/lib/faces/gallery/github_user_data.ex @@ -15,7 +15,7 @@ defmodule Faces.Gallery.GithubUserData do }} iex> GitHubUserData.get("thisUserReallyDoesntExist") - {:error, "404 while retrieving thisUserReallyDoesntExist from Github: Not Found"} + {:error, "404 while retrieving \"thisUserReallyDoesntExist\" from Github: Not Found"} """ def get(username) do with {200, user_data, _} <- get_user_from_github(username), @@ -27,10 +27,10 @@ defmodule Faces.Gallery.GithubUserData do {:error, reason} {i, %{"message" => message}, _} when is_integer(i) -> - {:error, "#{i} while retrieving #{username} from Github: #{message}"} + {:error, "#{i} while retrieving #{inspect(username)} from Github: #{message}"} {i, _, _} when is_integer(i) -> - {:error, "#{i} while retrieving #{username} from Github"} + {:error, "#{i} while retrieving #{inspect(username)} from Github"} end end diff --git a/lib/faces_web/controllers/face_controller.ex b/lib/faces_web/controllers/face_controller.ex new file mode 100644 index 0000000..45fbbe0 --- /dev/null +++ b/lib/faces_web/controllers/face_controller.ex @@ -0,0 +1,20 @@ +defmodule FacesWeb.FaceController do + use FacesWeb, :controller + alias Faces.Gallery + + def index(conn, _params) do + render(conn, "index.html", people: Gallery.list_people()) + end + + def create(conn, %{"username" => username}) do + case Gallery.import_user(username) do + {:ok, _user} -> + render(conn, "index.html", people: Gallery.list_people()) + + {:error, reason} -> + conn + |> put_flash(:error, reason) + |> render("index.html", people: Gallery.list_people()) + end + end +end diff --git a/lib/faces_web/controllers/page_controller.ex b/lib/faces_web/controllers/page_controller.ex deleted file mode 100644 index 9202eaf..0000000 --- a/lib/faces_web/controllers/page_controller.ex +++ /dev/null @@ -1,8 +0,0 @@ -defmodule FacesWeb.PageController do - use FacesWeb, :controller - alias Faces.Gallery - - def index(conn, _params) do - render(conn, "index.html", people: Gallery.list_people()) - end -end diff --git a/lib/faces_web/router.ex b/lib/faces_web/router.ex index 4e4913c..590ab90 100644 --- a/lib/faces_web/router.ex +++ b/lib/faces_web/router.ex @@ -2,21 +2,22 @@ defmodule FacesWeb.Router do use FacesWeb, :router pipeline :browser do - plug :accepts, ["html"] - plug :fetch_session - plug :fetch_flash - plug :protect_from_forgery - plug :put_secure_browser_headers + plug(:accepts, ["html"]) + plug(:fetch_session) + plug(:fetch_flash) + plug(:protect_from_forgery) + plug(:put_secure_browser_headers) end pipeline :api do - plug :accepts, ["json"] + plug(:accepts, ["json"]) end scope "/", FacesWeb do - pipe_through :browser # Use the default browser stack + # Use the default browser stack + pipe_through(:browser) - get "/", PageController, :index + resources("/", FaceController) end # Other scopes may use custom stacks. diff --git a/lib/faces_web/templates/face/index.html.eex b/lib/faces_web/templates/face/index.html.eex new file mode 100644 index 0000000..23076d7 --- /dev/null +++ b/lib/faces_web/templates/face/index.html.eex @@ -0,0 +1,41 @@ +
+
+

Face Gallery

+ + <%= if get_flash(@conn, :error) do %> + + <% end %> +
+
+ + diff --git a/lib/faces_web/templates/page/index.html.eex b/lib/faces_web/templates/page/index.html.eex deleted file mode 100644 index f7c89bb..0000000 --- a/lib/faces_web/templates/page/index.html.eex +++ /dev/null @@ -1,19 +0,0 @@ -
-
-

Face Gallery

-
-
- - diff --git a/lib/faces_web/views/face_view.ex b/lib/faces_web/views/face_view.ex new file mode 100644 index 0000000..fb8f4a9 --- /dev/null +++ b/lib/faces_web/views/face_view.ex @@ -0,0 +1,3 @@ +defmodule FacesWeb.FaceView do + use FacesWeb, :view +end diff --git a/lib/faces_web/views/page_view.ex b/lib/faces_web/views/page_view.ex deleted file mode 100644 index f6036ef..0000000 --- a/lib/faces_web/views/page_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule FacesWeb.PageView do - use FacesWeb, :view -end