48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use crate::{DateTimeUtc, UserId};
|
|
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Stored as `"follow"` or `"block"` in the database.
|
|
/// Use `FromStr` / `ToString` for type-safe access.
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum RelationType {
|
|
Follow,
|
|
Block,
|
|
}
|
|
|
|
impl std::fmt::Display for RelationType {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
RelationType::Follow => write!(f, "follow"),
|
|
RelationType::Block => write!(f, "block"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::str::FromStr for RelationType {
|
|
type Err = &'static str;
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
match s {
|
|
"follow" => Ok(RelationType::Follow),
|
|
"block" => Ok(RelationType::Block),
|
|
_ => Err("unknown relation type"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "user_relation")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
pub id: i64,
|
|
pub user: UserId,
|
|
pub target: UserId,
|
|
pub relation_type: String,
|
|
pub created_at: DateTimeUtc,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|