mirror of
https://github.com/mitchell/shortnr.git
synced 2025-12-19 14:07:22 +00:00
First working iteration of shortnr api
This commit is contained in:
parent
7ff70d452a
commit
9ee9eddbfa
8 changed files with 147 additions and 12 deletions
20
lib/url/repo/dets.ex
Normal file
20
lib/url/repo/dets.ex
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule Shortnr.URL.Repo.DETS do
|
||||
@behaviour Shortnr.URL.Repo
|
||||
|
||||
@impl true
|
||||
def get(key) do
|
||||
{:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def put(url) do
|
||||
:ok = :dets.insert(:urls, {url.id, url})
|
||||
:ok
|
||||
end
|
||||
|
||||
@impl true
|
||||
def list() do
|
||||
resp = :dets.select(:urls, [{:"$1", [], [:"$1"]}])
|
||||
{:ok, resp |> Enum.map(&elem(&1, 1))}
|
||||
end
|
||||
end
|
||||
8
lib/url/repo/repo.ex
Normal file
8
lib/url/repo/repo.ex
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
defmodule Shortnr.URL.Repo do
|
||||
alias Shortnr.URL
|
||||
alias Shortnr.Transport
|
||||
|
||||
@callback put(URL.t()) :: :ok | Transport.error()
|
||||
@callback get(String.t()) :: {:ok, URL.t()} | Transport.error()
|
||||
@callback list() :: {:ok, list(URL.t())} | Transport.error()
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue