follower.rs

 1use super::{FollowerId, ProjectId, RoomId, ServerId};
 2use rpc::ConnectionId;
 3use sea_orm::entity::prelude::*;
 4use serde::Serialize;
 5
 6#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel, Serialize)]
 7#[sea_orm(table_name = "followers")]
 8pub struct Model {
 9    #[sea_orm(primary_key)]
10    pub id: FollowerId,
11    pub room_id: RoomId,
12    pub project_id: ProjectId,
13    pub leader_connection_server_id: ServerId,
14    pub leader_connection_id: i32,
15    pub follower_connection_server_id: ServerId,
16    pub follower_connection_id: i32,
17}
18
19impl Model {
20    pub fn leader_connection(&self) -> ConnectionId {
21        ConnectionId {
22            owner_id: self.leader_connection_server_id.0 as u32,
23            id: self.leader_connection_id as u32,
24        }
25    }
26
27    pub fn follower_connection(&self) -> ConnectionId {
28        ConnectionId {
29            owner_id: self.follower_connection_server_id.0 as u32,
30            id: self.follower_connection_id as u32,
31        }
32    }
33}
34
35#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
36pub enum Relation {
37    #[sea_orm(
38        belongs_to = "super::room::Entity",
39        from = "Column::RoomId",
40        to = "super::room::Column::Id"
41    )]
42    Room,
43}
44
45impl Related<super::room::Entity> for Entity {
46    fn to() -> RelationDef {
47        Relation::Room.def()
48    }
49}
50
51impl ActiveModelBehavior for ActiveModel {}