Geoffrey-rs/geoffrey_models/src/models/link.rs

41 lines
848 B
Rust

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