Break apart config by stage; refactor project structure

This commit is contained in:
mitchell 2020-02-07 23:53:08 -05:00
parent 98684feb2d
commit 4d07f94e89
14 changed files with 20 additions and 18 deletions

View file

@ -6,7 +6,7 @@ defmodule Shortnr do
require Logger
use Application
@impl Application
@impl true
def start(_type, _args) do
children = [
{Plug.Cowboy, scheme: :http, plug: Shortnr.Router, options: [port: port()]}
@ -22,7 +22,7 @@ defmodule Shortnr do
Supervisor.start_link(children, strategy: :one_for_one)
end
@impl Application
@impl true
def stop(_state) do
if ets_implementation() == :dets, do: :dets.close(:urls)
end

View file

@ -8,7 +8,7 @@ defmodule Shortnr.URL.Endpoints do
@behaviour Endpoints
@impl Endpoints
@impl true
def select(conn, name, arg \\ nil)
def select(conn, :list, _arg) do

View file

@ -6,7 +6,7 @@ defmodule Shortnr.URL.Repo.ETS do
@behaviour Repo
@impl Repo
@impl true
def get(key) do
case ets().lookup(:urls, key) |> List.first() do
{_, url} -> {:ok, url}
@ -14,25 +14,25 @@ defmodule Shortnr.URL.Repo.ETS do
end
end
@impl Repo
@impl true
def put(url) do
:ok = ets().insert(:urls, {url.id, url})
:ok
end
@impl Repo
@impl true
def list do
resp = ets().select(:urls, [{:"$1", [], [:"$1"]}])
{:ok, resp |> Enum.map(&elem(&1, 1))}
end
@impl Repo
@impl true
def delete(key) do
:ok = ets().delete(:urls, key)
:ok
end
@impl Repo
@impl true
def reset do
:ok = ets().delete_all_objects(:urls)
end