nerak repo
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#include <nerak.h>
|
||||
#include <sqlite.h>
|
||||
#include <pubsub.h>
|
||||
#include <session_auth.h>
|
||||
|
||||
config(activity){
|
||||
middleware(logged_in(), session());
|
||||
|
||||
sqlite_config(
|
||||
"activity_db",
|
||||
"file:activity.db?mode=rwc",
|
||||
{"create_activity_table"}
|
||||
);
|
||||
|
||||
subscribe("todo_created", {
|
||||
sqlite_query({"activity_db", "insert_activity"})
|
||||
});
|
||||
|
||||
resource("activity", "/activity",
|
||||
.get = {
|
||||
sqlite_query({"activity_db", "get_activities", "activity"}),
|
||||
mustache("activity", "activity_s"),
|
||||
respond("activity_s")
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{< layout}}
|
||||
{{$body}}
|
||||
{{^activity}}
|
||||
<p>no activity</p>
|
||||
{{/activity}}
|
||||
{{#activity}}
|
||||
<p>activity</p>
|
||||
{{#.}}
|
||||
<p>{{action}}: {{title}} ({{created_at}})</p>
|
||||
{{/.}}
|
||||
{{/activity}}
|
||||
{{/body}}
|
||||
{{/layout}}
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS activity (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
action TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_activity_user_id ON activity(user_id);
|
||||
@@ -0,0 +1,5 @@
|
||||
select action, title, created_at
|
||||
from activity
|
||||
where user_id = {{user_id}}
|
||||
order by created_at desc
|
||||
limit 50;
|
||||
@@ -0,0 +1,2 @@
|
||||
insert into activity(user_id, action, title)
|
||||
values({{user_id}}, 'created', {{title}});
|
||||
Reference in New Issue
Block a user