Skip to content

Commit f4416dc

Browse files
More refactoring
1 parent 809e7a7 commit f4416dc

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

lib/pointing_party/account.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule PointingParty.Account do
1111

1212
def create(attrs) do
1313
changeset = changeset(%Account{}, attrs)
14+
1415
if changeset.valid? do
1516
account = apply_changes(changeset)
1617
{:ok, account}
@@ -19,7 +20,6 @@ defmodule PointingParty.Account do
1920
end
2021
end
2122

22-
@doc false
2323
def changeset(account, attrs \\ %{}) do
2424
account
2525
|> cast(attrs, [:username])

lib/pointing_party/card.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ defmodule PointingParty.Card do
1313
timestamps()
1414
end
1515

16-
def points_range, do: @pointing_scale
17-
18-
@doc false
1916
def changeset(card, attrs) do
2017
card
2118
|> cast(attrs, [:title, :description, :points])
@@ -28,4 +25,6 @@ defmodule PointingParty.Card do
2825
|> Application.get_env(:cards)
2926
|> Enum.map(&struct(__MODULE__, &1))
3027
end
28+
29+
def points_range, do: @pointing_scale
3130
end

lib/pointing_party/vote_calculator.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ defmodule PointingParty.VoteCalculator do
1919
end
2020

2121
defp get_points(score_card, users) do
22-
votes =
23-
users
24-
|> Enum.map(fn {_username, %{metas: [%{points: points}]}} ->
25-
points
26-
end)
22+
votes = Enum.map(users, fn {_username, %{metas: [%{points: points}]}} -> points end)
2723

2824
update_score_card(score_card, :votes, votes)
2925
end

lib/pointing_party_web/channels/room_channel.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule PointingPartyWeb.RoomChannel do
22
use PointingPartyWeb, :channel
3+
34
alias PointingParty.Card
5+
46
def join("room:lobby", _payload, socket) do
57
send(self(), :after_join)
68

@@ -9,29 +11,34 @@ defmodule PointingPartyWeb.RoomChannel do
911

1012
def handle_info(:after_join, socket) do
1113
# handle Presence listing and tracking here
14+
1215
{:noreply, socket}
1316
end
1417

1518
def handle_in("user_estimated", %{"points" => points}, socket) do
1619
# update votes for user presence
1720
# calculate votes if everyone voted with the help of the VoteCalculator
1821
# broadcast the 'winner'/'tie' event with a payload of %{points: points}
22+
1923
{:noreply, socket}
2024
end
2125

2226
def handle_in("finalized_points", %{"points" => points}, socket) do
2327
# update state by setting the current card to the next card
2428
# broadcast the "new_card" message with a payload of %{card: new_current_card}
29+
2530
{:reply, :ok, socket}
2631
end
2732

2833
def handle_in("start_pointing", _params, socket) do
2934
updated_socket = initialize_state(socket)
3035
# broadcast the "new_card" message with a payload of %{card: current_card}
36+
3137
{:reply, :ok, updated_socket}
3238
end
3339

3440
defp initialize_state(%{assigns: %{cards: _cards}} = socket), do: socket
41+
3542
defp initialize_state(socket) do
3643
[first | cards] = Card.cards()
3744

lib/pointing_party_web/controllers/session_controller.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule PointingPartyWeb.SessionController do
22
use PointingPartyWeb, :controller
3-
alias PointingParty.Account.Auth
4-
alias PointingParty.Account
3+
4+
alias PointingParty.{Account, Account.Auth}
55

66
def new(conn, _params) do
77
changeset = Account.changeset(%Account{})
@@ -15,13 +15,16 @@ defmodule PointingPartyWeb.SessionController do
1515
|> put_session(:username, username)
1616
|> redirect(to: "/cards")
1717
|> halt()
18+
1819
{:error, changeset} ->
1920
render(conn, "new.html", changeset: changeset)
2021
end
2122
end
2223

2324
def delete(conn, _params) do
24-
clear_session(conn)
25-
|> redirect(to: "/login") |> halt()
25+
conn
26+
|> clear_session()
27+
|> redirect(to: "/login")
28+
|> halt()
2629
end
2730
end

lib/pointing_party_web/plugs/auth.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ defmodule PointingPartyWeb.Plugs.Auth do
66

77
def call(conn, _default) do
88
case authenticate(conn) do
9-
nil -> conn |> redirect(to: "/login") |> halt()
10-
username -> assign(conn, :username, username)
9+
nil ->
10+
conn
11+
|> redirect(to: "/login")
12+
|> halt()
13+
14+
username ->
15+
assign(conn, :username, username)
1116
end
1217
end
1318

lib/pointing_party_web/templates/card/index.html.eex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<div class="col-2">
1515
<label for="story-points">Story Points</label>
1616
<select class="form-control story-points" id="story-points">
17+
<option>0</option>
1718
<option>1</option>
18-
<option>2</option>
1919
<option>3</option>
2020
<option>5</option>
2121
</select>
@@ -24,12 +24,12 @@
2424
<a href="#" class="btn btn-primary calculate-points">Vote!</a>
2525
<div class="winner" style="display: none;">
2626
<p class="final-points"></p>
27-
<button disabled=true class="btn btn-primary next-card" value="">Next Card</a>
27+
<button disabled=true class="btn btn-primary next-card" value="">Next Card</button>
2828
</div>
2929
<div class="tie" style="display: none;">
30-
<p class="card-text"> TIE! </p>
31-
<button disabled=true class="btn btn-primary next-card" value=""></a>
32-
<button disabled=true class="btn btn-primary next-card" value=""></a>
30+
<p class="card-text">TIE!</p>
31+
<button disabled=true class="btn btn-primary next-card" value=""></button>
32+
<button disabled=true class="btn btn-primary next-card" value=""></button>
3333
</div>
3434
</div>
3535
</div>

0 commit comments

Comments
 (0)