951a522
use sea_orm::entity::prelude::*;
use sea_orm::{EntityTrait, QueryFilter, Select};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Default,
EnumIter,
DeriveActiveEnum,
Serialize,
Deserialize,
utoipa::ToSchema,
)]
#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
pub enum ProfileVisibility {
#[default]
#[sea_orm(num_value = 0)]
Public,
#[sea_orm(num_value = 1)]
RegisteredOnly,
#[sea_orm(num_value = 2)]
MembersOnly,
#[sea_orm(num_value = 3)]
Private,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Default,
EnumIter,
DeriveActiveEnum,
Serialize,
Deserialize,
utoipa::ToSchema,
)]
#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
pub enum Audience {
#[default]
#[sea_orm(num_value = 0)]
Everyone,
#[sea_orm(num_value = 1)]
FollowingOnly,
#[sea_orm(num_value = 2)]
Nobody,
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uid: i64,
pub username: String,
#[sea_orm(unique)]
pub lower_name: String,
pub display_name: String,
pub avatar_url: String,
pub is_active: bool,
pub is_restricted: bool,
pub prohibit_login: bool,
pub visibility: ProfileVisibility,
#[sea_orm(default_value = "false")]
pub bot: bool,
#[sea_orm(default_value = "false")]
pub system: bool,
pub last_login_at: Option<OffsetDateTime>,
pub last_login_ip_hash: Option<String>,
pub version: i32,
pub passwd_hash: Option<String>,
pub password_last_changed_at: Option<OffsetDateTime>,
pub passwd_version: Option<i64>,
pub totp_encrypted_secret: Option<String>,
#[sea_orm(default_value = "false")]
pub totp_enabled: bool,
pub totp_last_used_at: Option<OffsetDateTime>,
pub totp_last_counter: Option<i64>,
pub timezone: Option<String>,
pub locale: Option<String>,
pub language: Option<String>,
pub created_at: OffsetDateTime,
pub updated_at: OffsetDateTime,
#[sea_orm(has_many)]
pub emails: HasMany<super::user_emails::Entity>,
#[sea_orm(has_many, relation_enum = "User")]
pub notifications: HasMany<super::user_notifications::Entity>,
#[sea_orm(has_one)]
pub profile: HasOne<super::user_profiles::Entity>,
#[sea_orm(has_one)]
pub preferences: HasOne<super::user_preferences::Entity>,
#[sea_orm(
self_ref,
has_many,
via = "user_followers",
from = "Followed",
to = "Follower"
)]
pub followers: HasMany<Entity>,
#[sea_orm(self_ref, has_many, via = "user_followers", reverse)]
pub following: HasMany<Entity>,
#[sea_orm(
self_ref,
has_many,
via = "user_blocks",
from = "Blocked",
to = "Blocker"
)]
pub blocked_by: HasMany<Entity>,
#[sea_orm(self_ref, has_many, via = "user_blocks", reverse)]
pub blocking: HasMany<Entity>,
}
impl Entity {
pub fn active() -> Select<Self> {
Self::find().filter(COLUMN.is_active.eq(true))
}
}
impl ActiveModelBehavior for ActiveModel {}