From 6697231935e735437c8dde19d06d7f52731f5a8d Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Fri, 12 Jan 2018 17:24:13 -0500 Subject: [PATCH] Move models into `lib/chess` --- lib/{chess_web/models => chess}/board.ex | 0 lib/{chess_web/models => chess/store}/game.ex | 10 ++++++++-- lib/chess_web.ex | 14 +------------- lib/chess_web/controllers/api/game_controller.ex | 4 ++-- lib/chess_web/controllers/game_controller.ex | 4 ++-- lib/chess_web/router.ex | 2 +- lib/chess_web/views/api/game_view.ex | 2 +- lib/chess_web/views/error_view.ex | 2 +- lib/chess_web/views/game_view.ex | 2 +- lib/chess_web/views/layout_view.ex | 2 +- lib/chess_web/views/page_view.ex | 2 +- 11 files changed, 19 insertions(+), 25 deletions(-) rename lib/{chess_web/models => chess}/board.ex (100%) rename lib/{chess_web/models => chess/store}/game.ex (80%) diff --git a/lib/chess_web/models/board.ex b/lib/chess/board.ex similarity index 100% rename from lib/chess_web/models/board.ex rename to lib/chess/board.ex diff --git a/lib/chess_web/models/game.ex b/lib/chess/store/game.ex similarity index 80% rename from lib/chess_web/models/game.ex rename to lib/chess/store/game.ex index 7f2b659..93a5825 100644 --- a/lib/chess_web/models/game.ex +++ b/lib/chess/store/game.ex @@ -1,5 +1,11 @@ -defmodule Chess.Game do - use Chess.Web, :model +defmodule Chess.Store.Game do + use Ecto.Schema + use Timex.Ecto.Timestamps + + import Ecto.Changeset + import Ecto.Query + + alias Chess.Store.Game schema "games" do field :board, :map diff --git a/lib/chess_web.ex b/lib/chess_web.ex index ac73f33..d1c2e38 100644 --- a/lib/chess_web.ex +++ b/lib/chess_web.ex @@ -1,4 +1,4 @@ -defmodule Chess.Web do +defmodule ChessWeb do @moduledoc """ A module that keeps using definitions for controllers, views and so on. @@ -16,18 +16,6 @@ defmodule Chess.Web do below. """ - def model do - quote do - use Ecto.Schema - - use Timex.Ecto.Timestamps - - import Ecto - import Ecto.Changeset - import Ecto.Query - end - end - def controller do quote do use Phoenix.Controller, namespace: ChessWeb diff --git a/lib/chess_web/controllers/api/game_controller.ex b/lib/chess_web/controllers/api/game_controller.ex index badda9e..4a29065 100644 --- a/lib/chess_web/controllers/api/game_controller.ex +++ b/lib/chess_web/controllers/api/game_controller.ex @@ -1,7 +1,7 @@ defmodule ChessWeb.Api.GameController do - use Chess.Web, :controller + use ChessWeb, :controller - alias Chess.Game + alias Chess.Store.Game def show(conn, %{"id" => id}) do game = Repo.get!(Game, id) diff --git a/lib/chess_web/controllers/game_controller.ex b/lib/chess_web/controllers/game_controller.ex index bfc48a0..f343d8a 100644 --- a/lib/chess_web/controllers/game_controller.ex +++ b/lib/chess_web/controllers/game_controller.ex @@ -1,7 +1,7 @@ defmodule ChessWeb.GameController do - use Chess.Web, :controller + use ChessWeb, :controller - alias Chess.Game + alias Chess.Store.Game def index(conn, _params) do changeset = Game.changeset(%Game{}) diff --git a/lib/chess_web/router.ex b/lib/chess_web/router.ex index 4c5230e..c7769f4 100644 --- a/lib/chess_web/router.ex +++ b/lib/chess_web/router.ex @@ -1,5 +1,5 @@ defmodule ChessWeb.Router do - use Chess.Web, :router + use ChessWeb, :router pipeline :browser do plug :accepts, ["html"] diff --git a/lib/chess_web/views/api/game_view.ex b/lib/chess_web/views/api/game_view.ex index 8520a7c..0dbf72a 100644 --- a/lib/chess_web/views/api/game_view.ex +++ b/lib/chess_web/views/api/game_view.ex @@ -1,5 +1,5 @@ defmodule ChessWeb.Api.GameView do - use Chess.Web, :view + use ChessWeb, :view alias Chess.Board diff --git a/lib/chess_web/views/error_view.ex b/lib/chess_web/views/error_view.ex index ad0d49d..f6f6de4 100644 --- a/lib/chess_web/views/error_view.ex +++ b/lib/chess_web/views/error_view.ex @@ -1,5 +1,5 @@ defmodule ChessWeb.ErrorView do - use Chess.Web, :view + use ChessWeb, :view def render("404.html", _assigns) do "Page not found" diff --git a/lib/chess_web/views/game_view.ex b/lib/chess_web/views/game_view.ex index 574875f..320f85c 100644 --- a/lib/chess_web/views/game_view.ex +++ b/lib/chess_web/views/game_view.ex @@ -1,3 +1,3 @@ defmodule ChessWeb.GameView do - use Chess.Web, :view + use ChessWeb, :view end diff --git a/lib/chess_web/views/layout_view.ex b/lib/chess_web/views/layout_view.ex index f09c6d2..c54108e 100644 --- a/lib/chess_web/views/layout_view.ex +++ b/lib/chess_web/views/layout_view.ex @@ -1,3 +1,3 @@ defmodule ChessWeb.LayoutView do - use Chess.Web, :view + use ChessWeb, :view end diff --git a/lib/chess_web/views/page_view.ex b/lib/chess_web/views/page_view.ex index 31e6fbc..d2b928b 100644 --- a/lib/chess_web/views/page_view.ex +++ b/lib/chess_web/views/page_view.ex @@ -1,3 +1,3 @@ defmodule ChessWeb.PageView do - use Chess.Web, :view + use ChessWeb, :view end