add functionality to show log

This commit is contained in:
philipp 2023-10-28 14:48:08 +02:00
parent cfd0ccc8c2
commit 08a1d16f88
4 changed files with 29 additions and 9 deletions

View File

@ -51,4 +51,16 @@ LIMIT 1000
ret.push_str("</rss>"); ret.push_str("</rss>");
ret.replace('\n', "") 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> = 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
}
} }

View File

@ -1,25 +1,34 @@
use rocket::{get, routes, Route, State}; use rocket::{get, routes, Route, State};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::{model::log::Log, tera::Config}; use crate::{
model::{log::Log, user::AdminUser},
tera::Config,
};
pub mod boat; pub mod boat;
pub mod planned_event; pub mod planned_event;
pub mod user; pub mod user;
#[get("/rss?<key>")] #[get("/rss?<key>")]
async fn rss(db: &State<SqlitePool>, key: Option<&str>, config: &State<Config>) -> String { async fn rss(db: &State<SqlitePool>, key: &str, config: &State<Config>) -> String {
match key { if key.eq(&config.rss_key) {
Some(key) if key.eq(&config.rss_key) => Log::generate_feed(db).await, Log::generate_feed(db).await
_ => "Not allowed".to_string(), } else {
"Not allowed".into()
} }
} }
#[get("/rss", rank = 2)]
async fn show_rss(db: &State<SqlitePool>, _admin: AdminUser) -> String {
Log::show(db).await
}
pub fn routes() -> Vec<Route> { pub fn routes() -> Vec<Route> {
let mut ret = Vec::new(); let mut ret = Vec::new();
ret.append(&mut user::routes()); ret.append(&mut user::routes());
ret.append(&mut boat::routes()); ret.append(&mut boat::routes());
ret.append(&mut planned_event::routes()); ret.append(&mut planned_event::routes());
ret.append(&mut routes![rss]); ret.append(&mut routes![rss, show_rss]);
ret ret
} }

View File

@ -1,8 +1,7 @@
use rocket::{get, http::ContentType, routes, Route, State}; use rocket::{get, http::ContentType, routes, Route, State};
use rocket_dyn_templates::{context, Template};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::model::{planned_event::PlannedEvent, user::User}; use crate::model::planned_event::PlannedEvent;
#[get("/cal")] #[get("/cal")]
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) { async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {

View File

@ -4,7 +4,7 @@ use sqlx::SqlitePool;
use crate::model::{ use crate::model::{
stat::{self, Stat}, stat::{self, Stat},
user::{NonGuestUser, User}, user::NonGuestUser,
}; };
use super::log::KioskCookie; use super::log::KioskCookie;