use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use crate::domain::ids::{SessionId, UserId}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Session { pub id: SessionId, pub user_id: UserId, pub session_token_hash: String, pub created_at: DateTime, pub expires_at: DateTime, } impl Session { pub fn new( id: SessionId, user_id: UserId, session_token_hash: String, created_at: DateTime, expires_at: DateTime, ) -> Self { Self { id, user_id, session_token_hash, created_at, expires_at, } } pub fn is_expired(&self) -> bool { Utc::now() > self.expires_at } } #[derive(Debug, Clone)] pub struct NewSession { pub user_id: UserId, pub session_token_hash: String, pub created_at: DateTime, pub expires_at: DateTime, } impl NewSession { pub fn new( user_id: UserId, session_token_hash: String, created_at: DateTime, expires_at: DateTime, ) -> Self { Self { user_id, session_token_hash, created_at, expires_at, } } }