Skip to content

Commit 6eca04c

Browse files
authored
Merge pull request #5 from elixirschool/scallan/remove-db
Remove Repo from the project
2 parents 22225e3 + b09cb14 commit 6eca04c

File tree

17 files changed

+63
-143
lines changed

17 files changed

+63
-143
lines changed

config/cards.exs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use Mix.Config
2+
3+
config :pointing_party,
4+
cards: [
5+
%{
6+
title: "Support loading data from a database",
7+
description: """
8+
We need to update the application to read users and cards from the database. This work includes adding Repo to the
9+
project, creating migrations, and a seed.exs file.
10+
"""
11+
},
12+
%{
13+
title: "Save pointing results to database",
14+
description: """
15+
Update the application to save an individual's vote and the final card points to the database.
16+
"""
17+
},
18+
19+
%{
20+
title: "Add Guardian dependency",
21+
description: """
22+
In preparation for adding authentication to the application, we need to add the Guardian dependency.
23+
"""
24+
},
25+
%{
26+
title: "Create Auth module and config",
27+
description: """
28+
Create a module that uses the Guardian package and implements the approach set of callbacks. Additionally,
29+
add the Guardian configuration.
30+
"""
31+
},
32+
%{
33+
title: "Update authenication flow to use new auth",
34+
description: """
35+
Update our existing authentication flow to use the newly created Auth module.
36+
"""
37+
},
38+
]

config/config.exs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# This file is responsible for configuring your application
2-
# and its dependencies with the aid of the Mix.Config module.
3-
#
4-
# This configuration file is loaded before any dependency and
5-
# is restricted to this project.
6-
7-
# General application configuration
81
use Mix.Config
92

103
config :pointing_party,
@@ -25,6 +18,8 @@ config :logger, :console,
2518
# Use Jason for JSON parsing in Phoenix
2619
config :phoenix, :json_library, Jason
2720

21+
import_config "cards.exs"
22+
2823
# Import environment specific config. This must remain at the bottom
2924
# of this file so it overrides the configuration defined above.
3025
import_config "#{Mix.env()}.exs"

config/dev.exs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
use Mix.Config
22

3-
# Configure your database
4-
config :pointing_party, PointingParty.Repo,
5-
username: "postgres",
6-
password: "postgres",
7-
database: "pointing_party_dev",
8-
hostname: "localhost",
9-
show_sensitive_data_on_connection_error: true,
10-
pool_size: 10
11-
12-
# For development, we disable any cache and enable
13-
# debugging and code reloading.
14-
#
153
# The watchers configuration can be used to run external
164
# watchers to your application. For example, we use it
175
# with webpack to recompile .js and .css sources.

config/test.exs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
use Mix.Config
22

3-
# Configure your database
4-
config :pointing_party, PointingParty.Repo,
5-
username: "postgres",
6-
password: "postgres",
7-
database: "pointing_party_test",
8-
hostname: "localhost",
9-
pool: Ecto.Adapters.SQL.Sandbox
10-
113
# We don't run a server during test. If one is required,
124
# you can enable the server option below.
135
config :pointing_party, PointingPartyWeb.Endpoint,

lib/pointing_party/account.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule PointingParty.Account do
22
use Ecto.Schema
3+
34
import Ecto.Changeset
5+
46
alias PointingParty.Account
57

68
schema "accounts" do

lib/pointing_party/account/auth.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule PointingParty.Account.Auth do
22
alias PointingParty.Account
3+
34
def login(params) do
45
Account.create(params)
56
end

lib/pointing_party/application.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ defmodule PointingParty.Application do
77

88
def start(_type, _args) do
99
children = [
10-
PointingParty.Repo,
1110
PointingPartyWeb.Endpoint,
1211
PointingPartyWeb.Presence
1312
]

lib/pointing_party/card.ex

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
defmodule PointingParty.Card do
22
use Ecto.Schema
3+
34
import Ecto.Changeset
4-
import Ecto.Query
5-
alias PointingParty.Repo
6-
alias PointingParty.Card
75

6+
@pointing_scale [0, 1, 3, 5]
87

98
schema "cards" do
109
field :description, :string
11-
field :title, :string
1210
field :points, :integer
11+
field :title, :string
1312

1413
timestamps()
1514
end
1615

17-
def points_range, do: [0, 1, 3, 5]
16+
def points_range, do: @pointing_scale
1817

1918
@doc false
2019
def changeset(card, attrs) do
2120
card
2221
|> cast(attrs, [:title, :description, :points])
2322
|> validate_required([:title, :description])
24-
|> validate_inclusion(:points, Card.points_range())
23+
|> validate_inclusion(:points, @pointing_scale)
2524
end
2625

27-
def get!(id) do
28-
Repo.get!(Card, id)
29-
end
26+
def first, do: List.first(cards())
3027

31-
def first do
32-
Card
33-
|> first
34-
|> Repo.one()
28+
defp cards do
29+
:pointing_party
30+
|> Application.get_env(:cards)
31+
|> Enum.map(&struct(__MODULE__, &1))
3532
end
3633
end

lib/pointing_party/repo.ex

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/pointing_party_web/templates/layout/app.html.eex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<%= if signed_in?(@conn) do %>
1818
<li>Hi, <%= @conn.assigns.username %></li>
1919
<li><%= link "Log Out", to: Routes.session_path(@conn, :delete), method: :delete, class: "nav-link" %></li>
20-
<%= else %>
20+
<% else %>
2121
<li><%= link "Log In", to: Routes.session_path(@conn, :new), class: "nav-link" %></li>
22-
<%= end %>
22+
<% end %>
2323
</ul>
2424
</nav>
2525
<a href="/" class="phx-logo">

0 commit comments

Comments
 (0)