From 3d71da490947aacc52a3b77efdc13d5f0458c57f Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 12 Feb 2023 14:11:50 -0500 Subject: refactor --- src/public/docs.rs | 96 +++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 45 deletions(-) (limited to 'src/public/docs.rs') diff --git a/src/public/docs.rs b/src/public/docs.rs index 1f1448b..f4e26be 100644 --- a/src/public/docs.rs +++ b/src/public/docs.rs @@ -2,7 +2,10 @@ use axum::response::Response; use lazy_static::lazy_static; use tokio::sync::Mutex; -use crate::{api::{admin, users, posts, auth}, types::http::ResponseCode}; +use crate::{ + api::{admin, auth, posts, users}, + types::http::ResponseCode, +}; use super::console::beautify; @@ -40,10 +43,10 @@ fn generate_body(body: Option<&'static str>) -> String { return String::new() }; let html = r#" -

Body

-
- $body -
+

Body

+
+ $body +
"# .to_string(); let body = body.trim(); @@ -60,20 +63,20 @@ fn generate_body(body: Option<&'static str>) -> String { fn generate_responses(responses: &[(u16, &'static str)]) -> String { let mut html = r#" -

Responses

- $responses +

Responses

+ $responses "# .to_string(); for response in responses { let res = format!( r#" -
- {} - {} -
- $responses - "#, +
+ {} + {} +
+ $responses + "#, response.0, response.1 ); html = html.replace("$responses", &res); @@ -93,18 +96,18 @@ fn generate_cookie(cookie: Option<&'static str>) -> String { fn generate_endpoint(doc: &EndpointDocumentation) -> String { let html = r#" -
-
- $method - $uri - $description - $cookie -
-
- $body - $responses -
+
+
+ $method + $uri + $description + $cookie
+
+ $body + $responses +
+
"#; html.replace("$method_class", &doc.method.to_string().to_lowercase()) @@ -123,6 +126,7 @@ pub async fn init() { auth::AUTH_LOGOUT, posts::POSTS_CREATE, posts::POSTS_PAGE, + posts::COMMENTS_PAGE, posts::POSTS_USER, posts::POSTS_COMMENT, posts::POSTS_LIKE, @@ -136,6 +140,8 @@ pub async fn init() { admin::ADMIN_POSTS, admin::ADMIN_USERS, admin::ADMIN_SESSIONS, + admin::ADMIN_COMMENTS, + admin::ADMIN_LIKES ]; let mut endpoints = ENDPOINTS.lock().await; for doc in docs { @@ -154,27 +160,27 @@ pub async fn generate() -> Response { let html = format!( r#" - - - - - - - - - XSSBook - API Documentation - - - -
- {data} -
- - - "# + + + + + + + + + XSSBook - API Documentation + + + +
+ {data} +
+ + + "# ); ResponseCode::Success.html(&html) -- cgit v1.2.3-freya