db/herodb/src/models/gov/user.rs
2025-04-19 09:02:35 +02:00

58 lines
1.3 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::db::{SledModel, Storable}; // Import Sled traits
// use std::collections::HashMap; // Removed unused import
/// User represents a user in the Freezone Manager system
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: u32,
pub name: String,
pub email: String,
pub password: String,
pub company: String, // here its just a best effort
pub role: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
// Removed old Model trait implementation
impl User {
/// Create a new user with default timestamps
pub fn new(
id: u32,
name: String,
email: String,
password: String,
company: String,
role: String,
) -> Self {
let now = Utc::now();
Self {
id,
name,
email,
password,
company,
role,
created_at: now,
updated_at: now,
}
}
}
// Implement Storable trait (provides default dump/load)
impl Storable for User {}
// Implement SledModel trait
impl SledModel for User {
fn get_id(&self) -> String {
self.id.to_string()
}
fn db_prefix() -> &'static str {
"user"
}
}