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