From f297798e71483942d9f04063db52a7c9537718f2 Mon Sep 17 00:00:00 2001 From: iho Date: Mon, 9 Sep 2024 00:57:26 +0300 Subject: [PATCH 1/2] fmt --- priv/static/add_post.html | 193 +++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 98 deletions(-) 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 + + + - - - + + + - -
- - - - - -
-
- -
-
-
-
-
-
- - - - -
-
- - - + +
+ + + - - + +
+
+
+
+
+
+
+ + + +
+
+ + + + + + From 2f63a80d8494dd7577b13c8e958f1ada3b48c358 Mon Sep 17 00:00:00 2001 From: iho Date: Mon, 9 Sep 2024 00:57:46 +0300 Subject: [PATCH 2/2] records --- .tool-versions | 4 +++ lib/application.ex | 2 +- lib/records.ex | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .tool-versions create mode 100644 lib/records.ex 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