Skip to content

Commit 2b9df61

Browse files
committed
Code for step 1
0 parents  commit 2b9df61

File tree

26 files changed

+730
-0
lines changed

26 files changed

+730
-0
lines changed

.formatter.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
import_deps: [:ecto, :phoenix],
3+
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
4+
subdirectories: ["priv/*/migrations"]
5+
]

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
auto_finder-*.tar
24+
25+
# Since we are building assets from assets/,
26+
# we ignore priv/static. You may want to comment
27+
# this depending on your deployment strategy.
28+
/priv/static/

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# AutoFinder
2+
3+
To start your Phoenix server:
4+
5+
* Install dependencies with `mix deps.get`
6+
* Create and migrate your database with `mix ecto.setup`
7+
* Start Phoenix endpoint with `mix phx.server`
8+
9+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
10+
11+
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
12+
13+
## Learn more
14+
15+
* Official website: https://www.phoenixframework.org/
16+
* Guides: https://hexdocs.pm/phoenix/overview.html
17+
* Docs: https://hexdocs.pm/phoenix
18+
* Forum: https://elixirforum.com/c/phoenix-forum
19+
* Source: https://github.com/phoenixframework/phoenix

config/config.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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
8+
use Mix.Config
9+
10+
config :auto_finder,
11+
ecto_repos: [AutoFinder.Repo]
12+
13+
# Configures the endpoint
14+
config :auto_finder, AutoFinderWeb.Endpoint,
15+
url: [host: "localhost"],
16+
secret_key_base: "wTE8BWxHVIakeO9JNCU3T8qF+zseb3/o/t0lbkl35UFbs257bBkAmNJFHrGW+1Qb",
17+
render_errors: [view: AutoFinderWeb.ErrorView, accepts: ~w(json)],
18+
pubsub: [name: AutoFinder.PubSub, adapter: Phoenix.PubSub.PG2],
19+
live_view: [signing_salt: "60QXfDxg"]
20+
21+
# Configures Elixir's Logger
22+
config :logger, :console,
23+
format: "$time $metadata[$level] $message\n",
24+
metadata: [:request_id]
25+
26+
# Use Jason for JSON parsing in Phoenix
27+
config :phoenix, :json_library, Jason
28+
29+
# Import environment specific config. This must remain at the bottom
30+
# of this file so it overrides the configuration defined above.
31+
import_config "#{Mix.env()}.exs"

config/dev.exs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use Mix.Config
2+
3+
# Configure your database
4+
config :auto_finder, AutoFinder.Repo,
5+
username: "postgres",
6+
password: "postgres",
7+
database: "auto_finder_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+
#
15+
# The watchers configuration can be used to run external
16+
# watchers to your application. For example, we use it
17+
# with webpack to recompile .js and .css sources.
18+
config :auto_finder, AutoFinderWeb.Endpoint,
19+
http: [port: 4000],
20+
debug_errors: true,
21+
code_reloader: true,
22+
check_origin: false,
23+
watchers: []
24+
25+
# ## SSL Support
26+
#
27+
# In order to use HTTPS in development, a self-signed
28+
# certificate can be generated by running the following
29+
# Mix task:
30+
#
31+
# mix phx.gen.cert
32+
#
33+
# Note that this task requires Erlang/OTP 20 or later.
34+
# Run `mix help phx.gen.cert` for more information.
35+
#
36+
# The `http:` config above can be replaced with:
37+
#
38+
# https: [
39+
# port: 4001,
40+
# cipher_suite: :strong,
41+
# keyfile: "priv/cert/selfsigned_key.pem",
42+
# certfile: "priv/cert/selfsigned.pem"
43+
# ],
44+
#
45+
# If desired, both `http:` and `https:` keys can be
46+
# configured to run both http and https servers on
47+
# different ports.
48+
49+
# Do not include metadata nor timestamps in development logs
50+
config :logger, :console, format: "[$level] $message\n"
51+
52+
# Set a higher stacktrace during development. Avoid configuring such
53+
# in production as building large stacktraces may be expensive.
54+
config :phoenix, :stacktrace_depth, 20
55+
56+
# Initialize plugs at runtime for faster development compilation
57+
config :phoenix, :plug_init_mode, :runtime

config/prod.exs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use Mix.Config
2+
3+
# For production, don't forget to configure the url host
4+
# to something meaningful, Phoenix uses this information
5+
# when generating URLs.
6+
#
7+
# Note we also include the path to a cache manifest
8+
# containing the digested version of static files. This
9+
# manifest is generated by the `mix phx.digest` task,
10+
# which you should run after static files are built and
11+
# before starting your production server.
12+
config :auto_finder, AutoFinderWeb.Endpoint,
13+
url: [host: "example.com", port: 80],
14+
cache_static_manifest: "priv/static/cache_manifest.json"
15+
16+
# Do not print debug messages in production
17+
config :logger, level: :info
18+
19+
# ## SSL Support
20+
#
21+
# To get SSL working, you will need to add the `https` key
22+
# to the previous section and set your `:url` port to 443:
23+
#
24+
# config :auto_finder, AutoFinderWeb.Endpoint,
25+
# ...
26+
# url: [host: "example.com", port: 443],
27+
# https: [
28+
# port: 443,
29+
# cipher_suite: :strong,
30+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
31+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH"),
32+
# transport_options: [socket_opts: [:inet6]]
33+
# ]
34+
#
35+
# The `cipher_suite` is set to `:strong` to support only the
36+
# latest and more secure SSL ciphers. This means old browsers
37+
# and clients may not be supported. You can set it to
38+
# `:compatible` for wider support.
39+
#
40+
# `:keyfile` and `:certfile` expect an absolute path to the key
41+
# and cert in disk or a relative path inside priv, for example
42+
# "priv/ssl/server.key". For all supported SSL configuration
43+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
44+
#
45+
# We also recommend setting `force_ssl` in your endpoint, ensuring
46+
# no data is ever sent via http, always redirecting to https:
47+
#
48+
# config :auto_finder, AutoFinderWeb.Endpoint,
49+
# force_ssl: [hsts: true]
50+
#
51+
# Check `Plug.SSL` for all available options in `force_ssl`.
52+
53+
# Finally import the config/prod.secret.exs which loads secrets
54+
# and configuration from environment variables.
55+
import_config "prod.secret.exs"

config/prod.secret.exs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# In this file, we load production configuration and secrets
2+
# from environment variables. You can also hardcode secrets,
3+
# although such is generally not recommended and you have to
4+
# remember to add this file to your .gitignore.
5+
use Mix.Config
6+
7+
database_url =
8+
System.get_env("DATABASE_URL") ||
9+
raise """
10+
environment variable DATABASE_URL is missing.
11+
For example: ecto://USER:PASS@HOST/DATABASE
12+
"""
13+
14+
config :auto_finder, AutoFinder.Repo,
15+
# ssl: true,
16+
url: database_url,
17+
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
18+
19+
secret_key_base =
20+
System.get_env("SECRET_KEY_BASE") ||
21+
raise """
22+
environment variable SECRET_KEY_BASE is missing.
23+
You can generate one by calling: mix phx.gen.secret
24+
"""
25+
26+
config :auto_finder, AutoFinderWeb.Endpoint,
27+
http: [
28+
port: String.to_integer(System.get_env("PORT") || "4000"),
29+
transport_options: [socket_opts: [:inet6]]
30+
],
31+
secret_key_base: secret_key_base
32+
33+
# ## Using releases (Elixir v1.9+)
34+
#
35+
# If you are doing OTP releases, you need to instruct Phoenix
36+
# to start each relevant endpoint:
37+
#
38+
# config :auto_finder, AutoFinderWeb.Endpoint, server: true
39+
#
40+
# Then you can assemble a release by calling `mix release`.
41+
# See `mix help release` for more information.

config/test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use Mix.Config
2+
3+
# Configure your database
4+
config :auto_finder, AutoFinder.Repo,
5+
username: "postgres",
6+
password: "postgres",
7+
database: "auto_finder_test",
8+
hostname: "localhost",
9+
pool: Ecto.Adapters.SQL.Sandbox
10+
11+
# We don't run a server during test. If one is required,
12+
# you can enable the server option below.
13+
config :auto_finder, AutoFinderWeb.Endpoint,
14+
http: [port: 4002],
15+
server: false
16+
17+
# Print only warnings and errors during test
18+
config :logger, level: :warn

lib/auto_finder.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule AutoFinder do
2+
@moduledoc """
3+
AutoFinder keeps the contexts that define your domain
4+
and business logic.
5+
6+
Contexts are also responsible for managing your data, regardless
7+
if it comes from the database, an external API or others.
8+
"""
9+
end

lib/auto_finder/application.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule AutoFinder.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
8+
def start(_type, _args) do
9+
# List all child processes to be supervised
10+
children = [
11+
# Start the Ecto repository
12+
AutoFinder.Repo,
13+
# Start the endpoint when the application starts
14+
AutoFinderWeb.Endpoint
15+
# Starts a worker by calling: AutoFinder.Worker.start_link(arg)
16+
# {AutoFinder.Worker, arg},
17+
]
18+
19+
# See https://hexdocs.pm/elixir/Supervisor.html
20+
# for other strategies and supported options
21+
opts = [strategy: :one_for_one, name: AutoFinder.Supervisor]
22+
Supervisor.start_link(children, opts)
23+
end
24+
25+
# Tell Phoenix to update the endpoint configuration
26+
# whenever the application is updated.
27+
def config_change(changed, _new, removed) do
28+
AutoFinderWeb.Endpoint.config_change(changed, removed)
29+
:ok
30+
end
31+
end

0 commit comments

Comments
 (0)