93 lines
2.0 KiB
Rust
93 lines
2.0 KiB
Rust
//! User entity for authentication.
|
|
|
|
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "users")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
pub id: i32,
|
|
|
|
#[sea_orm(unique)]
|
|
pub username: String,
|
|
|
|
#[sea_orm(column_type = "Text")]
|
|
pub password_hash: String,
|
|
|
|
/// Foreign key to roles table
|
|
pub role_id: i32,
|
|
|
|
/// Display name (optional, separate from username)
|
|
pub name: Option<String>,
|
|
|
|
// Profile fields
|
|
/// Height in centimeters
|
|
pub height_cm: Option<f32>,
|
|
|
|
/// Blood type (A+, B-, O+, etc.)
|
|
pub blood_type: Option<String>,
|
|
|
|
/// Date of birth
|
|
pub birthdate: Option<Date>,
|
|
|
|
// Lifestyle / Habits
|
|
/// Whether the user smokes
|
|
pub smoking: Option<bool>,
|
|
|
|
/// Whether the user consumes alcohol
|
|
pub alcohol: Option<bool>,
|
|
|
|
/// Foreign key to diet types
|
|
pub diet_id: Option<i32>,
|
|
|
|
/// URL to profile avatar icon
|
|
pub avatar_url: Option<String>,
|
|
|
|
/// User's own Mistral API key (BYOK - Bring Your Own Key)
|
|
pub mistral_api_key: Option<String>,
|
|
|
|
pub created_at: DateTime,
|
|
pub updated_at: DateTime,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(has_many = "super::session::Entity")]
|
|
Sessions,
|
|
|
|
#[sea_orm(
|
|
belongs_to = "super::role::Entity",
|
|
from = "Column::RoleId",
|
|
to = "super::role::Column::Id"
|
|
)]
|
|
Role,
|
|
|
|
#[sea_orm(
|
|
belongs_to = "super::diet::Entity",
|
|
from = "Column::DietId",
|
|
to = "super::diet::Column::Id"
|
|
)]
|
|
Diet,
|
|
}
|
|
|
|
impl Related<super::session::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Sessions.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::role::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Role.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::diet::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Diet.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|