Minor changes
This commit is contained in:
parent
3dba30c9b1
commit
9aad11050b
@ -1,5 +1,7 @@
|
||||
import Config
|
||||
|
||||
config :elixir, :time_zone_database, Tz.TimeZoneDatabase
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# of this file so it overrides the configuration defined above.
|
||||
import_config "#{config_env()}.env.exs"
|
||||
|
||||
@ -2,6 +2,9 @@ defmodule Logsrv do
|
||||
@moduledoc """
|
||||
Documentation for `Logsrv`.
|
||||
"""
|
||||
def hello do
|
||||
:world
|
||||
end
|
||||
|
||||
def dir do
|
||||
Application.get_env(:logsrv, :dir) <> "/"
|
||||
@ -43,6 +46,12 @@ defmodule Logsrv do
|
||||
{conflicts(journals()), conflicts(pages())}
|
||||
end
|
||||
|
||||
def conflicts! do
|
||||
[conflicts(journals()), conflicts(pages())]
|
||||
|> List.flatten()
|
||||
end
|
||||
|
||||
|
||||
def conflicts(list) do
|
||||
list
|
||||
|> Enum.filter( fn (fd) ->
|
||||
@ -58,7 +67,7 @@ defmodule Logsrv do
|
||||
|> Enum.map( fn(fd) ->
|
||||
%{
|
||||
:type => :journal,
|
||||
:date => fd |> Logsrv.Helpers.to_date,
|
||||
:date => fd |> Logsrv.Helpers.to_date!,
|
||||
:file => fd,
|
||||
:diff => compare(dir(:journals) <> fd),
|
||||
}
|
||||
@ -76,4 +85,13 @@ defmodule Logsrv do
|
||||
|
||||
end
|
||||
|
||||
def add_thought(:journals, data) do
|
||||
journal_date = data.date
|
||||
date_formatted = journal_date
|
||||
|> Calendar.strftime("%Y_%m_%d")
|
||||
content = data.content
|
||||
|
||||
{:ok, date_formatted}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -5,6 +5,12 @@ defmodule Logsrv.Helpers do
|
||||
end
|
||||
|
||||
def to_date(str) do
|
||||
str
|
||||
|> String.replace(~r/\..*/,"")
|
||||
|> String.replace("_","-")
|
||||
|> Date.from_iso8601()
|
||||
end
|
||||
def to_date!(str) do
|
||||
str
|
||||
|> String.replace(~r/\..*/,"")
|
||||
|> String.replace("_","-")
|
||||
|
||||
@ -22,7 +22,40 @@ defmodule Logsrv.Router do
|
||||
|
||||
# Handler for GET request with "/" path
|
||||
get "/" do
|
||||
|
||||
send_resp(conn, 200, "OK")
|
||||
|
||||
end
|
||||
|
||||
# Handler for GET request to "/status"
|
||||
get "/status" do
|
||||
|
||||
most_recent = Logsrv.journals
|
||||
|> Enum.sort
|
||||
|> List.last
|
||||
|> Logsrv.Helpers.to_date
|
||||
|
||||
conflicts = Logsrv.conflicts! |> length
|
||||
|
||||
status = case conflicts do
|
||||
0 ->
|
||||
:ok
|
||||
_ ->
|
||||
:conflicts
|
||||
end
|
||||
|
||||
summary = %{
|
||||
:status => status,
|
||||
:journals => Logsrv.journals |> length,
|
||||
:pages => Logsrv.pages|> length,
|
||||
:most_recent => most_recent,
|
||||
:conflicts => conflicts
|
||||
}
|
||||
|> Jason.encode!
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(200, summary)
|
||||
end
|
||||
|
||||
get "/journals" do
|
||||
|
||||
@ -23,7 +23,8 @@ defmodule Logsrv.MixProject do
|
||||
defp deps do
|
||||
[
|
||||
{:plug_cowboy, "~> 2.5"},
|
||||
{:jason, "~> 1.3"}
|
||||
{:jason, "~> 1.3"},
|
||||
{:tz, "~> 0.21.1"}
|
||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
||||
]
|
||||
|
||||
@ -9,4 +9,5 @@
|
||||
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
|
||||
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
|
||||
"tz": {:hex, :tz, "0.21.1", "9aad76e2ae54aead5c6b3fbd3cc7c062c2cccfff63fd4945dd81768b55d22889", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:mint, "~> 1.4", [hex: :mint, repo: "hexpm", optional: true]}], "hexpm", "42caf2056655577d5247d46d4572f193707bd08200d50eac0de5d686b3232b5f"},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user