diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..29f4b24 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,4 @@ +elixir 1.17.2-otp-25 +erlang 26.2.5.3 +nodejs 22.8.0 +python 3.12.5 diff --git a/lib/application.ex b/lib/application.ex index 459bbeb..bc49274 100644 --- a/lib/application.ex +++ b/lib/application.ex @@ -7,7 +7,7 @@ defmodule Forum.Application do def route(<<"login", _::binary>>), do: Forum.Login def route(<<"signup", _::binary>>), do: Forum.Signup - def finish(state, ctx), do: {:ok, state, ctx} + def finish(state , ctx), do: {:ok, state, ctx} def init(state, context) do %{path: path} = N2O.cx(context, :req) {:ok, state, N2O.cx(context, path: path, module: route(path))} diff --git a/lib/records.ex b/lib/records.ex new file mode 100644 index 0000000..f8f22c1 --- /dev/null +++ b/lib/records.ex @@ -0,0 +1,75 @@ +defmodule User do + require Record + require KVS + + Record.defrecord(:user,[ + id: :kvs.seq([], []), + next: [], + prev: [], + email: [], + password: [], + posts: "/posts/:user_id", + comments: "/comments/:user_id/:post_id", + date: {2015, 1, 1}, + last_login: {2015, 1, 1} + ]) + + def login(user, password) do + if user.password == password do + user(user, last_login: :erlang.date()) + else + user + end + end + + def save(id, user) do + :kvs.append(user, Enum.join(["users/", id])) + end + + def find_by_id(id) do + res = :kvs.get(:writer, Enum.join(["users/", id])) + res + # case res do + # {:ok, {:writer, _, _, user , _, _}} -> + # # IO.puts("User ID: #{user}") + # user + # _ -> + # IO.puts("No user found") + # end + end + + def put(user) do + :kvs.cut(Enum.join(["users/", user]), user) + end +end + +defmodule Post do + require Record + + Record.defrecord(:post, + id: :kvs.seq([], []), + next: [], + prev: [], + title: [], + body: [], + comments: "/comms_by_post/:post_id" + ) +end + +defmodule Comment do + require Record + + Record.defrecord(:comment, + id: :kvs.seq([], []), + perent: [], + children: [], + body: [], + post: [], + user: [] + ) +end + +defmodule Counter do + require Record + Record.defrecord(:counter, count: 0) +end diff --git a/priv/static/add_post.html b/priv/static/add_post.html index 184a6d0..b9b3a18 100644 --- a/priv/static/add_post.html +++ b/priv/static/add_post.html @@ -1,103 +1,100 @@ - + - - Add post - - - + + Add post + + + - - - + + + - -
- - - - - -
-
- -
-
-
-
-
-
- - - - -
-
- - - + +
+ + + - - + +
+
+
+
+
+
+
+ + + +
+
+ + + + + +