Minor changes

This commit is contained in:
Ryan Pandya 2022-09-04 16:25:54 -07:00
parent 9aad11050b
commit a1cc8fa095
2 changed files with 32 additions and 3 deletions

View File

@ -19,6 +19,24 @@ defmodule Logsrv do
|> File.ls!
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
dir(:pages)
|> File.ls!

View File

@ -33,7 +33,7 @@ defmodule Logsrv.Router do
most_recent = Logsrv.journals
|> Enum.sort
|> List.last
|> Logsrv.Helpers.to_date
|> Logsrv.Helpers.to_date!
conflicts = Logsrv.conflicts! |> length
@ -41,7 +41,7 @@ defmodule Logsrv.Router do
0 ->
:ok
_ ->
:conflicts
:conflict
end
summary = %{
@ -58,9 +58,10 @@ defmodule Logsrv.Router do
|> send_resp(200, summary)
end
get "/journals" do
get "/journals.json" do
journals =
Logsrv.journals
|> Enum.sort
|> Jason.encode!() # Encode the list to a JSON string
conn
@ -68,6 +69,16 @@ defmodule Logsrv.Router do
|> send_resp(200, journals) # Send a 200 OK response with the posts in the body
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
pages =
Logsrv.pages