From 82603054e3ed28ce3168f953138ef5f900f5a6ce Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 19 Feb 2024 17:44:55 +0800 Subject: [PATCH] add visit count --- cfg/feather.cfg | 2 +- entity.h | 3 +- feather.sql | 3 +- purecpp/html/detail.html | 110 ++++++++++++++++-------------- purecpp/html/home.html | 144 ++++++++++++++++++++------------------- purecpp_controller.hpp | 6 ++ 6 files changed, 143 insertions(+), 125 deletions(-) diff --git a/cfg/feather.cfg b/cfg/feather.cfg index 8091daa..9ee6ec3 100644 --- a/cfg/feather.cfg +++ b/cfg/feather.cfg @@ -7,7 +7,7 @@ "db_name": "feather", "timeout": 2, "db_conn_num": 4, - "drop_all_table": 0, + "drop_all_table": false, "log_path": "/tmp", "log_name": "feather.log", "roll_file_size": 2 diff --git a/entity.h b/entity.h index f0529e3..3ae3a50 100644 --- a/entity.h +++ b/entity.h @@ -19,10 +19,11 @@ struct pp_posts { int comment_count; std::string category; std::string raw_content; + int visit_count; }; REFLECTION(pp_posts, ID, post_author, post_date, post_title, post_content, post_status, post_modified, content_abstract, url, comment_count, - category, raw_content); + category, raw_content, visit_count); struct pp_user { int ID; diff --git a/feather.sql b/feather.sql index 9a4069e..24948ec 100644 --- a/feather.sql +++ b/feather.sql @@ -167,6 +167,7 @@ CREATE TABLE `pp_posts` ( `content_abstract` text NOT NULL, `url` varchar(255) NOT NULL, `comment_count` bigint(20) NOT NULL, + `visit_count` bigint(20) NOT NULL, `category` varchar(255) NOT NULL, `raw_content` text NOT NULL, PRIMARY KEY (`ID`) @@ -179,7 +180,7 @@ CREATE TABLE `pp_posts` ( LOCK TABLES `pp_posts` WRITE; /*!40000 ALTER TABLE `pp_posts` DISABLE KEYS */; -INSERT INTO `pp_posts` VALUES (2058,2535,'2018-12-12 10:16:44','1','# 初始数据放这里','publish','2018-12-12 10:16:44','# 初始数据放这里...','',0,'3',''); +INSERT INTO `pp_posts` VALUES (2058,2535,'2018-12-12 10:16:44','1','# 初始数据放这里','publish','2018-12-12 10:16:44','# 初始数据放这里...','',0,0,'3',''); /*!40000 ALTER TABLE `pp_posts` ENABLE KEYS */; UNLOCK TABLES; diff --git a/purecpp/html/detail.html b/purecpp/html/detail.html index e228edd..b3df66d 100644 --- a/purecpp/html/detail.html +++ b/purecpp/html/detail.html @@ -15,29 +15,29 @@ - - + + @@ -67,10 +67,13 @@ 编辑时间:${post_modified} 作者:${user_login} ${total}条评论 + 总访问量: ${visit_count}

-

+ +
+


    出自:purecpp

@@ -85,28 +88,31 @@

- +
来说两句吧
-
-
- -
-
+
+
+ +
+
- +
$if has_login{{ - + }} $else{{ - - 登录才能发表评论。 + + 登录才能发表评论。 }}
@@ -114,46 +120,48 @@
最新评论
$inline {{ - ./purecpp/html/righter.html - }} + ./purecpp/html/righter.html + }}
$inline {{ - ./purecpp/html/footer.html + ./purecpp/html/footer.html }}
@@ -161,14 +169,14 @@ - - + + - - + + \ No newline at end of file diff --git a/purecpp/html/home.html b/purecpp/html/home.html index 94079a4..1407577 100644 --- a/purecpp/html/home.html +++ b/purecpp/html/home.html @@ -13,12 +13,12 @@ }}
- - + + @@ -37,31 +37,31 @@
- $inline {{ - ./purecpp/html/notice.html - }} + $inline {{ + ./purecpp/html/notice.html + }}
-
- -
+
+ +
$for item in article_list{{
@@ -85,39 +85,40 @@

   ${item.category} - $if item.is_owner{{ - + 总访问量: ${item.visit_count} + $if item.is_owner{{ + 编辑 - - }} - $if item.is_admin{{ - + + }} + $if item.is_admin{{ + 编辑 - - + + 删除 - - + + 通过 - - }} + + }}

}} -
+
$inline {{ - ./purecpp/html/righter.html - }} + ./purecpp/html/righter.html + }}
-$inline {{ - ./purecpp/html/footer.html -}} + $inline {{ + ./purecpp/html/footer.html + }}
@@ -128,33 +129,34 @@

- + + \ No newline at end of file diff --git a/purecpp_controller.hpp b/purecpp_controller.hpp index 1db7b8d..05ab394 100644 --- a/purecpp_controller.hpp +++ b/purecpp_controller.hpp @@ -145,6 +145,10 @@ class purecpp_controller { nlohmann::json article; article["comment_list"] = std::move(comment_list); auto& post = std::get<0>(v[0]); + post.visit_count++; + int rows = dao.execute( + "update pp_posts set visit_count=" + std::to_string(post.visit_count) + + " where ID=" + std::to_string(post.ID)); article["post_id"] = post_id; article["post_title"] = post.post_title; article["post_modified"] = post.post_modified; @@ -155,6 +159,7 @@ class purecpp_controller { article["has_login"] = !login_user_name.empty(); article["login_user_name"] = login_user_name; article["category"] = "all"; + article["visit_count"] = post.visit_count; res.add_header("Content-Type", "text/html; charset=utf-8"); res.set_status_and_content( status_type::ok, @@ -818,6 +823,7 @@ class purecpp_controller { item["post_title"] = post.post_title; item["category"] = category_map_[post.category]; item["comment_count"] = post.comment_count; + item["visit_count"] = post.visit_count; std::string user_login = std::get<1>(o); item["user_login"] = user_login;