feat: add last_seen field to sessions
parent
b5ec2e40de
commit
78a274e01f
|
@ -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>> {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -41,6 +41,7 @@ diesel::table! {
|
|||
sessions (id) {
|
||||
id -> BigInt,
|
||||
user_id -> BigInt,
|
||||
last_seen -> BigInt,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue