46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
use crate::{DateTimeUtc, UserId};
|
|
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Per-user billing account.
|
|
/// Each user gets a default $10 balance on creation.
|
|
/// Pro users additionally have a monthly quota that resets each cycle.
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "user_billing")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
#[sea_orm(column_name = "user_uuid")]
|
|
pub user: UserId,
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))")]
|
|
pub balance: Decimal,
|
|
#[sea_orm(column_type = "Text", default_value = "USD")]
|
|
pub currency: String,
|
|
#[sea_orm(default_value = false)]
|
|
pub is_pro: bool,
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub monthly_quota: Decimal,
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub month_used: Decimal,
|
|
pub cycle_start: Option<DateTimeUtc>,
|
|
pub cycle_end: Option<DateTimeUtc>,
|
|
pub updated_at: DateTimeUtc,
|
|
pub created_at: DateTimeUtc,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(
|
|
belongs_to = "crate::users::user::Entity",
|
|
from = "Column::User",
|
|
to = "crate::users::user::Column::Uid"
|
|
)]
|
|
User,
|
|
}
|
|
|
|
impl Related<crate::users::user::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::User.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {} |