From f1c1ca6d14da7472ea7215b5c21b98e7c635976b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Tue, 12 Aug 2025 19:50:35 +0200 Subject: [PATCH] feat(user): routes and simple template --- .../controllers/user_controller.ex | 33 +++++++++++++++++++ .../controllers/user_html.ex | 10 ++++++ .../controllers/user_html/edit.html.heex | 9 +++++ .../controllers/user_html/index.html.heex | 9 +++++ .../controllers/user_html/new.html.heex | 9 +++++ .../controllers/user_html/show.html.heex | 9 +++++ lib/learning_phoenix_web/router.ex | 1 + 7 files changed, 80 insertions(+) create mode 100644 lib/learning_phoenix_web/controllers/user_controller.ex create mode 100644 lib/learning_phoenix_web/controllers/user_html.ex create mode 100644 lib/learning_phoenix_web/controllers/user_html/edit.html.heex create mode 100644 lib/learning_phoenix_web/controllers/user_html/index.html.heex create mode 100644 lib/learning_phoenix_web/controllers/user_html/new.html.heex create mode 100644 lib/learning_phoenix_web/controllers/user_html/show.html.heex diff --git a/lib/learning_phoenix_web/controllers/user_controller.ex b/lib/learning_phoenix_web/controllers/user_controller.ex new file mode 100644 index 0000000..138ee5a --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_controller.ex @@ -0,0 +1,33 @@ +defmodule LearningPhoenixWeb.UserController do + use LearningPhoenixWeb, :controller + + def index(conn, _params) do + render(conn, :index) + end + + def edit(conn, _params) do + render(conn, :edit) + end + + def new(conn, _params) do + render(conn, :new) + end + + def show(conn, _params) do + render(conn, :show) + end + + def create(conn, _params) do + #redirect(conn, url(~p"/users/#{id}")) + redirect(conn, url(~p"/users")) + end + + def update(conn, _params) do + #redirect(conn, url(~p"/users/#{id}")) + redirect(conn, url(~p"/users")) + end + + def delete(conn, _params) do + redirect(conn, url(~p"/users")) + end +end diff --git a/lib/learning_phoenix_web/controllers/user_html.ex b/lib/learning_phoenix_web/controllers/user_html.ex new file mode 100644 index 0000000..66e7351 --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_html.ex @@ -0,0 +1,10 @@ +defmodule LearningPhoenixWeb.UserHTML do + @moduledoc """ + This module contains pages rendered by PageController. + + See the `page_html` directory for all templates available. + """ + use LearningPhoenixWeb, :html + + embed_templates "user_html/*" +end diff --git a/lib/learning_phoenix_web/controllers/user_html/edit.html.heex b/lib/learning_phoenix_web/controllers/user_html/edit.html.heex new file mode 100644 index 0000000..740586d --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_html/edit.html.heex @@ -0,0 +1,9 @@ + +
+

+ Page d'edit des utilisateurs +

+

+ Cette page permet de modifier un utilisateur +

+
diff --git a/lib/learning_phoenix_web/controllers/user_html/index.html.heex b/lib/learning_phoenix_web/controllers/user_html/index.html.heex new file mode 100644 index 0000000..d5e1e6b --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_html/index.html.heex @@ -0,0 +1,9 @@ + +
+

+ Liste de tous les utilisateurs +

+

+ Cette page contient la liste de tous les utilisateurs +

+
diff --git a/lib/learning_phoenix_web/controllers/user_html/new.html.heex b/lib/learning_phoenix_web/controllers/user_html/new.html.heex new file mode 100644 index 0000000..5e39b9c --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_html/new.html.heex @@ -0,0 +1,9 @@ + +
+

+ Création d'utilisateur +

+

+ Cette page permet de créer un utilisateur. +

+
diff --git a/lib/learning_phoenix_web/controllers/user_html/show.html.heex b/lib/learning_phoenix_web/controllers/user_html/show.html.heex new file mode 100644 index 0000000..ae00824 --- /dev/null +++ b/lib/learning_phoenix_web/controllers/user_html/show.html.heex @@ -0,0 +1,9 @@ + +
+

+ Info sur un utilisateur en particulier +

+

+ Cette page donne les info sur un utilisateur en particulier +

+
diff --git a/lib/learning_phoenix_web/router.ex b/lib/learning_phoenix_web/router.ex index 1c1ecda..60dbb53 100644 --- a/lib/learning_phoenix_web/router.ex +++ b/lib/learning_phoenix_web/router.ex @@ -18,6 +18,7 @@ defmodule LearningPhoenixWeb.Router do pipe_through :browser get "/", PageController, :home + resources "/users", UserController end # Other scopes may use custom stacks.