mirror of
https://github.com/mitchell/shortnr.git
synced 2025-12-17 05:17:22 +00:00
Refactor dets repo, dockerfile, and url type; add logger level func
This commit is contained in:
parent
faaf12ba42
commit
fe413d2a5e
5 changed files with 19 additions and 6 deletions
|
|
@ -46,7 +46,7 @@ defmodule Shortnr.Router do
|
|||
end
|
||||
|
||||
def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do
|
||||
Logger.error(inspect(reason), stack: inspect(stack))
|
||||
Logger.error(reason, stack: stack)
|
||||
|
||||
{:error, {:internal_server_error, "internal server error"}, conn}
|
||||
|> Text.encode_response()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ defmodule Shortnr.URL.Repo.DETS do
|
|||
|
||||
@impl true
|
||||
def get(key) do
|
||||
{:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)}
|
||||
case :dets.lookup(:urls, key) |> List.first() do
|
||||
{_, url} -> {:ok, url}
|
||||
nil -> {:ok, nil}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ defmodule Shortnr.URL do
|
|||
updated_at: DateTime.utc_now(),
|
||||
url: %URI{}
|
||||
|
||||
@type t :: %__MODULE__{id: String.t(), url: URI.t()}
|
||||
@type t :: %__MODULE__{
|
||||
id: String.t(),
|
||||
url: URI.t(),
|
||||
created_at: DateTime.t(),
|
||||
updated_at: DateTime.t()
|
||||
}
|
||||
|
||||
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
|
||||
def create(url, repo) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue