diff --git a/src/model/log.rs b/src/model/log.rs index c2b04a3..b862c79 100644 --- a/src/model/log.rs +++ b/src/model/log.rs @@ -51,4 +51,16 @@ LIMIT 1000 ret.push_str(""); ret.replace('\n', "") } + + pub async fn show(db: &SqlitePool) -> String { + let mut ret = String::new(); + + for log in Self::last(db).await { + let utc_time: DateTime = Utc::from_utc_datetime(&Utc, &log.created_at); + let local_time = utc_time.with_timezone(&Local); + ret.push_str(&format!("- {} - {}\n", local_time, log.msg)); + } + + ret + } } diff --git a/src/tera/admin/mod.rs b/src/tera/admin/mod.rs index ee4f5fb..0bf05e7 100644 --- a/src/tera/admin/mod.rs +++ b/src/tera/admin/mod.rs @@ -1,25 +1,34 @@ use rocket::{get, routes, Route, State}; use sqlx::SqlitePool; -use crate::{model::log::Log, tera::Config}; +use crate::{ + model::{log::Log, user::AdminUser}, + tera::Config, +}; pub mod boat; pub mod planned_event; pub mod user; #[get("/rss?")] -async fn rss(db: &State, key: Option<&str>, config: &State) -> String { - match key { - Some(key) if key.eq(&config.rss_key) => Log::generate_feed(db).await, - _ => "Not allowed".to_string(), +async fn rss(db: &State, key: &str, config: &State) -> String { + if key.eq(&config.rss_key) { + Log::generate_feed(db).await + } else { + "Not allowed".into() } } +#[get("/rss", rank = 2)] +async fn show_rss(db: &State, _admin: AdminUser) -> String { + Log::show(db).await +} + pub fn routes() -> Vec { let mut ret = Vec::new(); ret.append(&mut user::routes()); ret.append(&mut boat::routes()); ret.append(&mut planned_event::routes()); - ret.append(&mut routes![rss]); + ret.append(&mut routes![rss, show_rss]); ret } diff --git a/src/tera/misc.rs b/src/tera/misc.rs index 24eb431..100890f 100644 --- a/src/tera/misc.rs +++ b/src/tera/misc.rs @@ -1,8 +1,7 @@ use rocket::{get, http::ContentType, routes, Route, State}; -use rocket_dyn_templates::{context, Template}; use sqlx::SqlitePool; -use crate::model::{planned_event::PlannedEvent, user::User}; +use crate::model::planned_event::PlannedEvent; #[get("/cal")] async fn cal(db: &State) -> (ContentType, String) { @@ -16,10 +15,7 @@ pub fn routes() -> Vec { #[cfg(test)] mod test { - use rocket::{ - http::{ContentType, Status}, - local::asynchronous::Client, - }; + use rocket::{http::Status, local::asynchronous::Client}; use sqlx::SqlitePool; use crate::testdb; diff --git a/src/tera/stat.rs b/src/tera/stat.rs index 86449a3..e2d23ba 100644 --- a/src/tera/stat.rs +++ b/src/tera/stat.rs @@ -4,7 +4,7 @@ use sqlx::SqlitePool; use crate::model::{ stat::{self, Stat}, - user::{NonGuestUser, User}, + user::NonGuestUser, }; use super::log::KioskCookie;