feat: add last_seen field to sessions

Jef Roosens 2025-03-15 16:12:46 +01:00
parent b5ec2e40de
commit 78a274e01f
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
3 changed files with 12 additions and 5 deletions

View File

@ -11,16 +11,21 @@ use crate::db::{schema::*, DbPool, DbResult};
pub struct Session {
pub id: i64,
pub user_id: i64,
pub last_seen: i64,
}
impl Session {
pub fn new_for_user(pool: &DbPool, user_id: i64) -> DbResult<Self> {
pub fn new_for_user(pool: &DbPool, user_id: i64, last_seen: i64) -> DbResult<Self> {
let id: i64 = rand::thread_rng().gen();
Ok(Self { id, user_id }
.insert_into(sessions::table)
.returning(Self::as_returning())
.get_result(&mut pool.get()?)?)
Ok(Self {
id,
user_id,
last_seen,
}
.insert_into(sessions::table)
.returning(Self::as_returning())
.get_result(&mut pool.get()?)?)
}
pub fn user_from_id(pool: &DbPool, id: i64) -> DbResult<Option<super::user::User>> {

View File

@ -77,6 +77,7 @@ impl gpodder::AuthRepository for SqliteRepository {
let session_id = db::Session {
id,
user_id: user.id,
last_seen: chrono::Utc::now().timestamp(),
}
.insert_into(sessions::table)
.returning(sessions::id)

View File

@ -41,6 +41,7 @@ diesel::table! {
sessions (id) {
id -> BigInt,
user_id -> BigInt,
last_seen -> BigInt,
}
}