use crate::GeoffreyDatabaseModel; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Link { id: Option, pub player_id: u64, pub link_code: String, pub expires: DateTime, } impl Link { pub fn new(player_id: u64, link_code: String, expires: DateTime) -> Self { Self { id: None, player_id, link_code, expires, } } pub fn is_valid(&self, link_code: String) -> bool { self.expires > Utc::now() && self.link_code == link_code } } impl GeoffreyDatabaseModel for Link { fn id(&self) -> Option { self.id } fn set_id(&mut self, id: u64) { self.id = Some(id); } fn tree() -> String { "link".to_string() } }