forked from Ruderverein-Donau-Linz/rowt
add rss feed with common actions
This commit is contained in:
48
src/model/log.rs
Normal file
48
src/model/log.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use rss::{ChannelBuilder, Item};
|
||||
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<Log> {
|
||||
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 channel = ChannelBuilder::default()
|
||||
.title("Ruder App Admin Feed")
|
||||
.description("An RSS feed with activities from app.rudernlinz.at")
|
||||
.build();
|
||||
let mut items: Vec<Item> = vec![];
|
||||
for log in Self::last(db).await {
|
||||
let mut item = Item::default();
|
||||
item.set_title(format!("({}) {}", log.created_at, log.msg));
|
||||
items.append(&mut vec![item]);
|
||||
}
|
||||
channel.set_items(items);
|
||||
channel.to_string()
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use self::{
|
||||
trip::{Trip, TripWithUser},
|
||||
};
|
||||
|
||||
pub mod log;
|
||||
pub mod planned_event;
|
||||
pub mod trip;
|
||||
pub mod tripdetails;
|
||||
|
Reference in New Issue
Block a user