use serde::{Deserialize, Serialize}; use sqlx::{FromRow, SqlitePool}; #[derive(FromRow, Debug, Serialize, Deserialize)] pub struct Log { pub msg: String, pub created_at: String, } impl Log { pub async fn create(db: &SqlitePool, msg: String) -> bool { sqlx::query!("INSERT INTO log(msg) VALUES (?)", msg,) .execute(db) .await .is_ok() } async fn last(db: &SqlitePool) -> Vec { sqlx::query_as!( Log, " SELECT msg, created_at FROM log ORDER BY id DESC LIMIT 1000 " ) .fetch_all(db) .await .unwrap() } pub async fn generate_feed(db: &SqlitePool) -> String { let mut ret = String::from( r#" Ruder App Admin Feed app.rudernlinz.at An RSS feed with activities from app.rudernlinz.at"#, ); for log in Self::last(db).await { ret.push_str(""); ret.push_str(&format!("({}) {}", log.created_at, log.msg)); ret.push_str(""); } ret.push_str(""); ret.push_str(""); ret.replace("\n", "") } }