room.rs

 1use crate::db::{ChannelId, RoomId};
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Default, Debug, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "rooms")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: RoomId,
 9    pub live_kit_room: String,
10    pub channel_id: Option<ChannelId>,
11}
12
13#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
14pub enum Relation {
15    #[sea_orm(has_many = "super::room_participant::Entity")]
16    RoomParticipant,
17    #[sea_orm(has_many = "super::project::Entity")]
18    Project,
19    #[sea_orm(has_many = "super::follower::Entity")]
20    Follower,
21    #[sea_orm(
22        belongs_to = "super::channel::Entity",
23        from = "Column::ChannelId",
24        to = "super::channel::Column::Id"
25    )]
26    Channel,
27}
28
29impl Related<super::room_participant::Entity> for Entity {
30    fn to() -> RelationDef {
31        Relation::RoomParticipant.def()
32    }
33}
34
35impl Related<super::project::Entity> for Entity {
36    fn to() -> RelationDef {
37        Relation::Project.def()
38    }
39}
40
41impl Related<super::follower::Entity> for Entity {
42    fn to() -> RelationDef {
43        Relation::Follower.def()
44    }
45}
46
47impl Related<super::channel::Entity> for Entity {
48    fn to() -> RelationDef {
49        Relation::Channel.def()
50    }
51}
52
53impl ActiveModelBehavior for ActiveModel {}