1use crate::db::channel_member;
2
3use super::{ChannelId, ChannelMemberId, UserId};
4use sea_orm::entity::prelude::*;
5
6#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "channel_members")]
8pub struct Model {
9 #[sea_orm(primary_key)]
10 pub id: ChannelMemberId,
11 pub channel_id: ChannelId,
12 pub user_id: UserId,
13 pub accepted: bool,
14 pub admin: bool,
15}
16
17impl ActiveModelBehavior for ActiveModel {}
18
19#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20pub enum Relation {
21 #[sea_orm(
22 belongs_to = "super::channel::Entity",
23 from = "Column::ChannelId",
24 to = "super::channel::Column::Id"
25 )]
26 Channel,
27 #[sea_orm(
28 belongs_to = "super::user::Entity",
29 from = "Column::UserId",
30 to = "super::user::Column::Id"
31 )]
32 User,
33}
34
35impl Related<super::channel::Entity> for Entity {
36 fn to() -> RelationDef {
37 Relation::Channel.def()
38 }
39}
40
41impl Related<super::user::Entity> for Entity {
42 fn to() -> RelationDef {
43 Relation::User.def()
44 }
45}
46
47#[derive(Debug)]
48pub struct UserToChannel;
49
50impl Linked for UserToChannel {
51 type FromEntity = super::user::Entity;
52
53 type ToEntity = super::channel::Entity;
54
55 fn link(&self) -> Vec<RelationDef> {
56 vec![
57 channel_member::Relation::User.def().rev(),
58 channel_member::Relation::Channel.def(),
59 ]
60 }
61}