summaryrefslogtreecommitdiff
path: root/src/admin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/admin.rs')
-rw-r--r--src/admin.rs48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/admin.rs b/src/admin.rs
index dec6b7d..344a953 100644
--- a/src/admin.rs
+++ b/src/admin.rs
@@ -3,7 +3,10 @@ use lazy_static::lazy_static;
use rand::{distributions::Alphanumeric, Rng};
use tokio::sync::Mutex;
-use crate::{types::{user::User, http::ResponseCode, post::Post, session::Session}, console::{self, sanatize}};
+use crate::{
+ console::{self, sanatize},
+ types::{http::ResponseCode, post::Post, session::Session, user::User},
+};
lazy_static! {
static ref SECRET: Mutex<String> = Mutex::new(String::new());
@@ -22,17 +25,16 @@ pub async fn get_secret() -> String {
if secret.is_empty() {
*secret = new_secret();
}
- return secret.clone();
+ secret.clone()
}
pub async fn regen_secret() -> String {
let mut secret = SECRET.lock().await;
*secret = new_secret();
- return secret.clone();
+ secret.clone()
}
pub fn generate_users() -> Response {
-
let users = match User::reterieve_all() {
Ok(users) => users,
Err(err) => return err,
@@ -51,7 +53,8 @@ pub fn generate_users() -> Response {
<th>Month</th>
<th>Year</th>
</tr>
- "#.to_string();
+ "#
+ .to_string();
for user in users {
html.push_str(
@@ -66,7 +69,6 @@ pub fn generate_users() -> Response {
}
pub fn generate_posts() -> Response {
-
let posts = match Post::reterieve_all() {
Ok(posts) => posts,
Err(err) => return err,
@@ -81,26 +83,28 @@ pub fn generate_posts() -> Response {
<th>Comments</th>
<th>Date</th>
</tr>
- "#.to_string();
+ "#
+ .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>",
- post.post_id, post.user_id, sanatize(post.content), console::beautify(likes),
- console::beautify(comments), post.date
- )
- );
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td><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
+ ));
}
ResponseCode::Success.text(&html)
}
pub fn generate_sessions() -> Response {
-
let sessions = match Session::reterieve_all() {
Ok(sessions) => sessions,
Err(err) => return err,
@@ -111,15 +115,15 @@ pub fn generate_sessions() -> Response {
<th>User ID</th>
<th>Token</th>
</tr>
- "#.to_string();
+ "#
+ .to_string();
for session in sessions {
- html.push_str(
- &format!("<tr><td>{}</td><td>{}</td></tr>",
- session.user_id, session.token
- )
- );
+ html.push_str(&format!(
+ "<tr><td>{}</td><td>{}</td></tr>",
+ session.user_id, session.token
+ ));
}
ResponseCode::Success.text(&html)
-} \ No newline at end of file
+}