Minor changes
This commit is contained in:
parent
9aad11050b
commit
a1cc8fa095
@ -19,6 +19,24 @@ defmodule Logsrv do
|
|||||||
|> File.ls!
|
|> File.ls!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get(fd) do
|
||||||
|
if fd |> File.exists? do
|
||||||
|
{:ok, fd}
|
||||||
|
else
|
||||||
|
{:error, :enoent}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def page(title) do
|
||||||
|
fd = dir(:pages) <> title <> ".md"
|
||||||
|
get fd
|
||||||
|
end
|
||||||
|
|
||||||
|
def journal(date) do
|
||||||
|
fd = dir(:journals) <> date <> ".md"
|
||||||
|
get fd
|
||||||
|
end
|
||||||
|
|
||||||
def pages do
|
def pages do
|
||||||
dir(:pages)
|
dir(:pages)
|
||||||
|> File.ls!
|
|> File.ls!
|
||||||
|
|||||||
@ -33,7 +33,7 @@ defmodule Logsrv.Router do
|
|||||||
most_recent = Logsrv.journals
|
most_recent = Logsrv.journals
|
||||||
|> Enum.sort
|
|> Enum.sort
|
||||||
|> List.last
|
|> List.last
|
||||||
|> Logsrv.Helpers.to_date
|
|> Logsrv.Helpers.to_date!
|
||||||
|
|
||||||
conflicts = Logsrv.conflicts! |> length
|
conflicts = Logsrv.conflicts! |> length
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ defmodule Logsrv.Router do
|
|||||||
0 ->
|
0 ->
|
||||||
:ok
|
:ok
|
||||||
_ ->
|
_ ->
|
||||||
:conflicts
|
:conflict
|
||||||
end
|
end
|
||||||
|
|
||||||
summary = %{
|
summary = %{
|
||||||
@ -58,9 +58,10 @@ defmodule Logsrv.Router do
|
|||||||
|> send_resp(200, summary)
|
|> send_resp(200, summary)
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/journals" do
|
get "/journals.json" do
|
||||||
journals =
|
journals =
|
||||||
Logsrv.journals
|
Logsrv.journals
|
||||||
|
|> Enum.sort
|
||||||
|> Jason.encode!() # Encode the list to a JSON string
|
|> Jason.encode!() # Encode the list to a JSON string
|
||||||
|
|
||||||
conn
|
conn
|
||||||
@ -68,6 +69,16 @@ defmodule Logsrv.Router do
|
|||||||
|> send_resp(200, journals) # Send a 200 OK response with the posts in the body
|
|> send_resp(200, journals) # Send a 200 OK response with the posts in the body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/journals/:date" do
|
||||||
|
date = conn.params["date"]
|
||||||
|
|
||||||
|
journal = Logsrv.journal(date) |> File.read
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/json")
|
||||||
|
|> send_resp(200, journal) # Send a 200 OK response with the posts in the body
|
||||||
|
end
|
||||||
|
|
||||||
get "/pages" do
|
get "/pages" do
|
||||||
pages =
|
pages =
|
||||||
Logsrv.pages
|
Logsrv.pages
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user