summaryrefslogtreecommitdiff
path: root/src/public/admin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/public/admin.rs')
-rw-r--r--src/public/admin.rs64
1 files changed, 54 insertions, 10 deletions
diff --git a/src/public/admin.rs b/src/public/admin.rs
index 1da2f1e..25941f1 100644
--- a/src/public/admin.rs
+++ b/src/public/admin.rs
@@ -4,8 +4,8 @@ use rand::{distributions::Alphanumeric, Rng};
use tokio::sync::Mutex;
use crate::{
- console::{self, sanatize},
- types::{http::ResponseCode, post::Post, session::Session, user::User},
+ console::sanatize,
+ types::{http::ResponseCode, post::Post, session::Session, user::User, comment::Comment, like::Like},
};
lazy_static! {
@@ -79,24 +79,17 @@ pub fn generate_posts() -> Response {
<th>Post ID</th>
<th>User ID</th>
<th>Content</th>
- <th>Likes</th>
- <th>Comments</th>
<th>Date</th>
</tr>
"#
.to_string();
for post in posts {
- let Ok(likes) = serde_json::to_string(&post.likes) else { continue };
- let Ok(comments) = serde_json::to_string(&post.comments) else { continue };
-
html.push_str(&format!(
- "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
+ "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
post.post_id,
post.user_id,
sanatize(&post.content),
- console::beautify(&likes),
- console::beautify(&comments),
post.date
));
}
@@ -127,3 +120,54 @@ pub fn generate_sessions() -> Response {
ResponseCode::Success.text(&html)
}
+
+pub fn generate_comments() -> Response {
+ let comments = match Comment::reterieve_all() {
+ Ok(comments) => comments,
+ Err(err) => return err,
+ };
+
+ let mut html = r#"
+ <tr>
+ <th>Comment ID</th>
+ <th>User ID</th>
+ <th>Post ID</th>
+ <th>Content</th>
+ <th>Date</th>
+ </tr>
+ "#
+ .to_string();
+
+ for comment in comments {
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>",
+ comment.comment_id, comment.user_id, comment.post_id, sanatize(&comment.content), comment.date
+ ));
+ }
+
+ ResponseCode::Success.text(&html)
+}
+
+pub fn generate_likes() -> Response {
+ let likes = match Like::reterieve_all() {
+ Ok(likes) => likes,
+ Err(err) => return err,
+ };
+
+ let mut html = r#"
+ <tr>
+ <th>User ID</th>
+ <th>Post ID</th>
+ </tr>
+ "#
+ .to_string();
+
+ for like in likes {
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td></tr>",
+ like.user_id, like.post_id
+ ));
+ }
+
+ ResponseCode::Success.text(&html)
+}