From 4ee91a6228e25bc730678dd625f057f1d200f313 Mon Sep 17 00:00:00 2001 From: Rob Whittaker Date: Fri, 9 Dec 2016 11:59:25 +0000 Subject: [PATCH] Move things into the API namespace --- web/controllers/{ => api}/game_controller.ex | 2 +- web/router.ex | 9 +++++---- web/static/js/components/chess-board.js | 2 +- web/views/{ => api}/game_view.ex | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) rename web/controllers/{ => api}/game_controller.ex (76%) rename web/views/{ => api}/game_view.ex (74%) diff --git a/web/controllers/game_controller.ex b/web/controllers/api/game_controller.ex similarity index 76% rename from web/controllers/game_controller.ex rename to web/controllers/api/game_controller.ex index 3e46ecd..0d74ce0 100644 --- a/web/controllers/game_controller.ex +++ b/web/controllers/api/game_controller.ex @@ -1,4 +1,4 @@ -defmodule Chess.GameController do +defmodule Chess.Api.GameController do use Chess.Web, :controller alias Chess.Game diff --git a/web/router.ex b/web/router.ex index 95ce8a5..7abf0ed 100644 --- a/web/router.ex +++ b/web/router.ex @@ -17,11 +17,12 @@ defmodule Chess.Router do pipe_through :browser # Use the default browser stack get "/", PageController, :index - resources "/games", GameController end # Other scopes may use custom stacks. - # scope "/api", Chess do - # pipe_through :api - # end + scope "/api", Chess do + pipe_through :api + + resources "/games", Api.GameController, only: [:show] + end end diff --git a/web/static/js/components/chess-board.js b/web/static/js/components/chess-board.js index 7b81490..a23bf2e 100644 --- a/web/static/js/components/chess-board.js +++ b/web/static/js/components/chess-board.js @@ -8,7 +8,7 @@ class ChessBoard extends React.Component { componentWillMount() { const { gameId } = this.props; - $.ajax({ method: "GET", url: "/games/" + gameId }) + $.ajax({ method: "GET", url: "/api/games/" + gameId }) .then(() => console.log("Oh, hai!")); } diff --git a/web/views/game_view.ex b/web/views/api/game_view.ex similarity index 74% rename from web/views/game_view.ex rename to web/views/api/game_view.ex index 66172de..957ee25 100644 --- a/web/views/game_view.ex +++ b/web/views/api/game_view.ex @@ -1,4 +1,4 @@ -defmodule Chess.GameView do +defmodule Chess.Api.GameView do use Chess.Web, :view def render("show.json", %{ id: 1 }) do