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