Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit ee808a0

Browse files
committed
Finish adding all content from Game Setup chapter
1 parent 404fa7e commit ee808a0

File tree

8 files changed

+47
-21
lines changed

8 files changed

+47
-21
lines changed

‎assets/elm/src/Main.elm‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type alias Game =
3535
{ description : String
3636
, featured : Bool
3737
, id : Int
38+
, slug : String
3839
, thumbnail : String
3940
, title : String
4041
}
@@ -97,10 +98,11 @@ decodeGamesList =
9798

9899
decodeGame : Decode.Decoder Game
99100
decodeGame =
100-
Decode.map5 Game
101+
Decode.map6 Game
101102
(Decode.field "description" Decode.string)
102103
(Decode.field "featured" Decode.bool)
103104
(Decode.field "id" Decode.int)
105+
(Decode.field "slug" Decode.string)
104106
(Decode.field "thumbnail" Decode.string)
105107
(Decode.field "title" Decode.string)
106108

@@ -190,7 +192,11 @@ featured model =
190192
[ h2 [] [ text "Featured" ]
191193
, h3 [] [ text game.title ]
192194
, p [] [ text game.description ]
193-
, button [ class "button" ] [ text "Play Now!" ]
195+
, a
196+
[ class "button"
197+
, href ("games/" ++ game.slug)
198+
]
199+
[ text "Play Now!" ]
194200
]
195201
]
196202
]
@@ -229,7 +235,7 @@ gamesList games =
229235

230236
gamesListItem : Game -> Html msg
231237
gamesListItem game =
232-
a [ href "#" ]
238+
a [ href ("games/"++ game.slug) ]
233239
[ li [ class "game-item" ]
234240
[ div [ class "game-image" ]
235241
[ img [ src game.thumbnail ] []

‎lib/platform/products/products.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ defmodule Platform.Products do
3636
3737
"""
3838
def get_game!(id), do: Repo.get!(Game, id)
39+
def get_game_by_slug!(slug), do: Repo.get_by!(Game, slug: slug)
3940

4041
@doc """
4142
Creates a game.

‎lib/platform_web/controllers/game_controller.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ defmodule PlatformWeb.GameController do
2525
render(conn, "show.json", game: game)
2626
end
2727

28-
def play(conn, %{"id" => id}) do
29-
game = Products.get_game!(id)
28+
def play(conn, %{"slug" => slug}) do
29+
game = Products.get_game_by_slug!(slug)
3030
render(conn, "show.html", game: game)
3131
end
3232

‎lib/platform_web/router.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule PlatformWeb.Router do
1818
pipe_through :browser
1919

2020
get "/", PageController, :index
21-
get "/games/:id", GameController, :play
21+
get "/games/:slug", GameController, :play
2222
resources "/players", PlayerController
2323
resources "/sessions", PlayerSessionController, only: [:new, :create, :delete]
2424
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="<%= @game.title |> String.downcase() %>"></div>
1+
<div id="<%= @game.slug %>"></div>

‎lib/platform_web/views/game_view.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule PlatformWeb.GameView do
1515
id: game.id,
1616
description: game.description,
1717
featured: game.featured,
18+
slug: game.slug,
1819
thumbnail: game.thumbnail,
1920
title: game.title
2021
}

‎test/platform/products/products_test.exs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ defmodule Platform.ProductsTest do
99
@valid_attrs %{
1010
description: "some description",
1111
featured: true,
12+
slug: "some slug",
1213
thumbnail: "some thumbnail",
1314
title: "some title"
1415
}
1516
@update_attrs %{
1617
description: "some updated description",
1718
featured: false,
19+
slug: "some updated slug",
1820
thumbnail: "some updated thumbnail",
1921
title: "some updated title"
2022
}
21-
@invalid_attrs %{description: nil, featured: nil, thumbnail: nil, title: nil}
23+
@invalid_attrs %{
24+
description: nil,
25+
featured: nil,
26+
slug: nil,
27+
thumbnail: nil,
28+
title: nil
29+
}
2230

2331
def game_fixture(attrs \\ %{}) do
2432
{:ok, game} =

‎test/platform_web/controllers/game_controller_test.exs‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ defmodule PlatformWeb.GameControllerTest do
77
@create_attrs %{
88
description: "some description",
99
featured: true,
10+
slug: "some slug",
1011
thumbnail: "some thumbnail",
1112
title: "some title"
1213
}
1314
@update_attrs %{
1415
description: "some updated description",
1516
featured: false,
17+
slug: "some updated slug",
1618
thumbnail: "some updated thumbnail",
1719
title: "some updated title"
1820
}
19-
@invalid_attrs %{description: nil, featured: nil, thumbnail: nil, title: nil}
21+
@invalid_attrs %{
22+
description: nil,
23+
featured: nil,
24+
slug: nil,
25+
thumbnail: nil,
26+
title: nil
27+
}
2028

2129
def fixture(:game) do
2230
{:ok, game} = Products.create_game(@create_attrs)
@@ -42,12 +50,13 @@ defmodule PlatformWeb.GameControllerTest do
4250
conn = get(conn, Routes.game_path(conn, :show, id))
4351

4452
assert %{
45-
"id" => id,
46-
"description" => "some description",
47-
"featured" => true,
48-
"thumbnail" => "some thumbnail",
49-
"title" => "some title"
50-
} = json_response(conn, 200)["data"]
53+
"id" => id,
54+
"description" => "some description",
55+
"featured" => true,
56+
"slug" => "some slug",
57+
"thumbnail" => "some thumbnail",
58+
"title" => "some title"
59+
} = json_response(conn, 200)["data"]
5160
end
5261

5362
test "renders errors when data is invalid", %{conn: conn} do
@@ -66,12 +75,13 @@ defmodule PlatformWeb.GameControllerTest do
6675
conn = get(conn, Routes.game_path(conn, :show, id))
6776

6877
assert %{
69-
"id" => id,
70-
"description" => "some updated description",
71-
"featured" => false,
72-
"thumbnail" => "some updated thumbnail",
73-
"title" => "some updated title"
74-
} = json_response(conn, 200)["data"]
78+
"id" => id,
79+
"description" => "some updated description",
80+
"featured" => false,
81+
"slug" => "some updated slug",
82+
"thumbnail" => "some updated thumbnail",
83+
"title" => "some updated title"
84+
} = json_response(conn, 200)["data"]
7585
end
7686

7787
test "renders errors when data is invalid", %{conn: conn, game: game} do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /