60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(
|
|
Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, DeriveDisplay,
|
|
)]
|
|
#[sea_orm(
|
|
rs_type = "String",
|
|
db_type = "Enum",
|
|
enum_name = "subscription_category"
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum SubscriptionCategory {
|
|
#[sea_orm(string_value = "mikan")]
|
|
Mikan,
|
|
#[sea_orm(string_value = "manual")]
|
|
Manual,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "subscriptions")]
|
|
pub struct Model {
|
|
#[sea_orm(column_type = "Timestamp")]
|
|
pub created_at: DateTime,
|
|
#[sea_orm(column_type = "Timestamp")]
|
|
pub updated_at: DateTime,
|
|
#[sea_orm(primary_key)]
|
|
pub id: i32,
|
|
pub display_name: String,
|
|
pub subscriber_id: i32,
|
|
pub category: SubscriptionCategory,
|
|
pub source_url: String,
|
|
pub aggregate: bool,
|
|
pub enabled: bool,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(
|
|
belongs_to = "super::subscribers::Entity",
|
|
from = "Column::SubscriberId",
|
|
to = "super::subscribers::Column::Id"
|
|
)]
|
|
Subscriber,
|
|
#[sea_orm(has_many = "super::bangumi::Entity")]
|
|
Bangumi,
|
|
}
|
|
|
|
impl Related<super::subscribers::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Subscriber.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::bangumi::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Bangumi.def()
|
|
}
|
|
}
|