From 4743b414650daac6ff306099b4cd9938c5ec5e7a Mon Sep 17 00:00:00 2001 From: Jessica Phoenix Canady Date: Fri, 20 Sep 2024 08:41:38 -0400 Subject: [PATCH] Bunch of misc event work. --- lib/nights/event.ex | 18 ++ lib/nights/schema.ex | 9 + .../components/layouts/app.html.heex | 26 -- .../components/layouts/root.html.heex | 6 +- .../controllers/event_controller.ex | 7 + lib/nights_web/controllers/event_html.ex | 10 + .../controllers/event_html/index.html.heex | 3 + lib/nights_web/controllers/page_controller.ex | 9 - lib/nights_web/controllers/page_html.ex | 10 - .../controllers/page_html/home.html.heex | 222 ------------------ lib/nights_web/router.ex | 2 +- .../20240915165631_create_events.exs | 12 + .../controllers/events_controller_test.exs | 8 + .../controllers/page_controller_test.exs | 8 - 14 files changed, 71 insertions(+), 279 deletions(-) create mode 100644 lib/nights/event.ex create mode 100644 lib/nights/schema.ex create mode 100644 lib/nights_web/controllers/event_controller.ex create mode 100644 lib/nights_web/controllers/event_html.ex create mode 100644 lib/nights_web/controllers/event_html/index.html.heex delete mode 100644 lib/nights_web/controllers/page_controller.ex delete mode 100644 lib/nights_web/controllers/page_html.ex delete mode 100644 lib/nights_web/controllers/page_html/home.html.heex create mode 100644 priv/repo/migrations/20240915165631_create_events.exs create mode 100644 test/nights_web/controllers/events_controller_test.exs delete mode 100644 test/nights_web/controllers/page_controller_test.exs diff --git a/lib/nights/event.ex b/lib/nights/event.ex new file mode 100644 index 0000000..f75b74e --- /dev/null +++ b/lib/nights/event.ex @@ -0,0 +1,18 @@ +defmodule Nights.Nights.Event do + use Ecto.Schema + import Ecto.Changeset + + schema "events" do + field :description, :string + field :starts_at, :utc_datetime + + timestamps(type: :utc_datetime) + end + + @doc false + def changeset(event, attrs) do + event + |> cast(attrs, [:description, :starts_at]) + |> validate_required([:description, :starts_at]) + end +end diff --git a/lib/nights/schema.ex b/lib/nights/schema.ex new file mode 100644 index 0000000..a02cb56 --- /dev/null +++ b/lib/nights/schema.ex @@ -0,0 +1,9 @@ +defmodule Nights.Schema do + defmacro __using__(_) do + quote do + use Ecto.Schema + @primary_key {:id, :binary_id, autogenerate: true} + @foreign_key_type :binary_id + end + end +end diff --git a/lib/nights_web/components/layouts/app.html.heex b/lib/nights_web/components/layouts/app.html.heex index e23bfc8..fec9a04 100644 --- a/lib/nights_web/components/layouts/app.html.heex +++ b/lib/nights_web/components/layouts/app.html.heex @@ -1,29 +1,3 @@ -
-
-
- - - -

- v<%= Application.spec(:phoenix, :vsn) %> -

-
- -
-
<.flash_group flash={@flash} /> diff --git a/lib/nights_web/components/layouts/root.html.heex b/lib/nights_web/components/layouts/root.html.heex index 216e07f..2d45f65 100644 --- a/lib/nights_web/components/layouts/root.html.heex +++ b/lib/nights_web/components/layouts/root.html.heex @@ -4,14 +4,14 @@ - <.live_title suffix=" · Phoenix Framework"> - <%= assigns[:page_title] || "Nights" %> + <.live_title suffix=" · Canady Nights"> + <%= assigns[:page_title] || "lol Jess forgot to title this page" %> - + <%= @inner_content %> diff --git a/lib/nights_web/controllers/event_controller.ex b/lib/nights_web/controllers/event_controller.ex new file mode 100644 index 0000000..ecdce84 --- /dev/null +++ b/lib/nights_web/controllers/event_controller.ex @@ -0,0 +1,7 @@ +defmodule NightsWeb.EventController do + use NightsWeb, :controller + + def index(conn, _params) do + render(conn, :index, page_title: "Welcome!") + end +end diff --git a/lib/nights_web/controllers/event_html.ex b/lib/nights_web/controllers/event_html.ex new file mode 100644 index 0000000..ff3d718 --- /dev/null +++ b/lib/nights_web/controllers/event_html.ex @@ -0,0 +1,10 @@ +defmodule NightsWeb.EventHTML do + @moduledoc """ + This module is invoked by your endpoint in case of errors on HTML requests. + + See config/config.exs. + """ + use NightsWeb, :html + + embed_templates "event_html/*" +end diff --git a/lib/nights_web/controllers/event_html/index.html.heex b/lib/nights_web/controllers/event_html/index.html.heex new file mode 100644 index 0000000..5109d60 --- /dev/null +++ b/lib/nights_web/controllers/event_html/index.html.heex @@ -0,0 +1,3 @@ +
+ +
diff --git a/lib/nights_web/controllers/page_controller.ex b/lib/nights_web/controllers/page_controller.ex deleted file mode 100644 index ad72fa5..0000000 --- a/lib/nights_web/controllers/page_controller.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule NightsWeb.PageController do - use NightsWeb, :controller - - def home(conn, _params) do - # The home page is often custom made, - # so skip the default app layout. - render(conn, :home, layout: false) - end -end diff --git a/lib/nights_web/controllers/page_html.ex b/lib/nights_web/controllers/page_html.ex deleted file mode 100644 index 59060f9..0000000 --- a/lib/nights_web/controllers/page_html.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule NightsWeb.PageHTML do - @moduledoc """ - This module contains pages rendered by PageController. - - See the `page_html` directory for all templates available. - """ - use NightsWeb, :html - - embed_templates "page_html/*" -end diff --git a/lib/nights_web/controllers/page_html/home.html.heex b/lib/nights_web/controllers/page_html/home.html.heex deleted file mode 100644 index dc1820b..0000000 --- a/lib/nights_web/controllers/page_html/home.html.heex +++ /dev/null @@ -1,222 +0,0 @@ -<.flash_group flash={@flash} /> - -
-
- -

- Phoenix Framework - - v<%= Application.spec(:phoenix, :vsn) %> - -

-

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
-
diff --git a/lib/nights_web/router.ex b/lib/nights_web/router.ex index 2600a74..3d04300 100644 --- a/lib/nights_web/router.ex +++ b/lib/nights_web/router.ex @@ -17,7 +17,7 @@ defmodule NightsWeb.Router do scope "/", NightsWeb do pipe_through :browser - get "/", PageController, :home + get "/", EventController, :index end # Other scopes may use custom stacks. diff --git a/priv/repo/migrations/20240915165631_create_events.exs b/priv/repo/migrations/20240915165631_create_events.exs new file mode 100644 index 0000000..d3d86ea --- /dev/null +++ b/priv/repo/migrations/20240915165631_create_events.exs @@ -0,0 +1,12 @@ +defmodule Nights.Repo.Migrations.CreateEvents do + use Ecto.Migration + + def change do + create table(:events) do + add :description, :text + add :starts_at, :utc_datetime + + timestamps(type: :utc_datetime) + end + end +end diff --git a/test/nights_web/controllers/events_controller_test.exs b/test/nights_web/controllers/events_controller_test.exs new file mode 100644 index 0000000..4d49bc5 --- /dev/null +++ b/test/nights_web/controllers/events_controller_test.exs @@ -0,0 +1,8 @@ +defmodule NightsWeb.EventsControllerTest do + use NightsWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, ~p"/") + assert html_response(conn, 200) =~ "Upcoming Events" + end +end diff --git a/test/nights_web/controllers/page_controller_test.exs b/test/nights_web/controllers/page_controller_test.exs deleted file mode 100644 index 02292f3..0000000 --- a/test/nights_web/controllers/page_controller_test.exs +++ /dev/null @@ -1,8 +0,0 @@ -defmodule NightsWeb.PageControllerTest do - use NightsWeb.ConnCase - - test "GET /", %{conn: conn} do - conn = get(conn, ~p"/") - assert html_response(conn, 200) =~ "Peace of mind from prototype to production" - end -end