show-all-activities #999
@@ -1,7 +1,7 @@
 | 
			
		||||
use std::ops::DerefMut;
 | 
			
		||||
 | 
			
		||||
use super::{role::Role, user::User};
 | 
			
		||||
use chrono::NaiveDateTime;
 | 
			
		||||
use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc};
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
 | 
			
		||||
 | 
			
		||||
@@ -110,4 +110,30 @@ ORDER BY created_at DESC;
 | 
			
		||||
        .await
 | 
			
		||||
        .unwrap()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn last(db: &SqlitePool) -> Vec<Self> {
 | 
			
		||||
        sqlx::query_as!(
 | 
			
		||||
            Self,
 | 
			
		||||
            "
 | 
			
		||||
SELECT id, created_at, text, relevant_for, keep_until FROM activity 
 | 
			
		||||
ORDER BY id DESC
 | 
			
		||||
LIMIT 1000
 | 
			
		||||
    "
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_all(db)
 | 
			
		||||
        .await
 | 
			
		||||
        .unwrap()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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!("- {local_time}: {}\n", log.text));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ret
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
use csv::ReaderBuilder;
 | 
			
		||||
use rocket::{FromForm, Route, State, form::Form, get, post, routes};
 | 
			
		||||
use rocket_dyn_templates::{Template, context};
 | 
			
		||||
use rocket::{form::Form, get, post, routes, FromForm, Route, State};
 | 
			
		||||
use rocket_dyn_templates::{context, Template};
 | 
			
		||||
use sqlx::SqlitePool;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    model::{log::Log, role::Role, user::AdminUser},
 | 
			
		||||
    model::{activity::Activity, log::Log, role::Role, user::AdminUser},
 | 
			
		||||
    tera::Config,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -25,11 +25,16 @@ async fn rss(db: &State<SqlitePool>, key: &str, config: &State<Config>) -> Strin
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/rss", rank = 2)]
 | 
			
		||||
#[get("/rss/old", rank = 2)]
 | 
			
		||||
async fn show_rss(db: &State<SqlitePool>, _admin: AdminUser) -> String {
 | 
			
		||||
    Log::show(db).await
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/rss", rank = 2)]
 | 
			
		||||
async fn show_activities(db: &State<SqlitePool>, _admin: AdminUser) -> String {
 | 
			
		||||
    Activity::show(db).await
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/list")]
 | 
			
		||||
async fn show_list(_admin: AdminUser) -> Template {
 | 
			
		||||
    Template::render("admin/list/index", context!())
 | 
			
		||||
@@ -83,6 +88,12 @@ pub fn routes() -> Vec<Route> {
 | 
			
		||||
    ret.append(&mut mail::routes());
 | 
			
		||||
    ret.append(&mut event::routes());
 | 
			
		||||
    ret.append(&mut role::routes());
 | 
			
		||||
    ret.append(&mut routes![rss, show_rss, show_list, list]);
 | 
			
		||||
    ret.append(&mut routes![
 | 
			
		||||
        rss,
 | 
			
		||||
        show_rss,
 | 
			
		||||
        show_activities,
 | 
			
		||||
        show_list,
 | 
			
		||||
        list
 | 
			
		||||
    ]);
 | 
			
		||||
    ret
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user