admin dashboard: apps, users, roles, logins in the last 24 hours

This commit is contained in:
Philippe Loctaux 2023-05-08 19:43:44 +02:00
parent 264eee9044
commit a05646a19b
8 changed files with 217 additions and 1 deletions

View file

@ -22,6 +22,26 @@ impl From<DatabaseAuthorizationCodes> for AuthorizationCode {
}
impl AuthorizationCode {
pub async fn get_all(conn: impl SqliteExecutor<'_>) -> Result<Vec<Self>, Error> {
Ok(DatabaseAuthorizationCodes::get_all(conn)
.await?
.into_iter()
.map(Self::from)
.collect::<Vec<_>>())
}
pub async fn used_in_last_24_hours(conn: impl SqliteExecutor<'_>) -> Result<usize, Error> {
let all = Self::get_all(conn).await?;
let last_24_hours = Utc::now() - Duration::hours(24);
Ok(all
.into_iter()
.filter_map(|code| code.used_at)
.filter(|&date| date >= last_24_hours)
.count())
}
pub async fn insert(
conn: impl SqliteExecutor<'_>,
code: &str,