1use crate::db::{ChannelId, MessageId, UserId};
2use sea_orm::entity::prelude::*;
3use time::PrimitiveDateTime;
4
5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
6#[sea_orm(table_name = "channel_messages")]
7pub struct Model {
8 #[sea_orm(primary_key)]
9 pub id: MessageId,
10 pub channel_id: ChannelId,
11 pub sender_id: UserId,
12 pub body: String,
13 pub sent_at: PrimitiveDateTime,
14 pub edited_at: Option<PrimitiveDateTime>,
15 pub nonce: Uuid,
16 pub reply_to_message_id: Option<MessageId>,
17}
18
19impl ActiveModelBehavior for ActiveModel {}
20
21#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
22pub enum Relation {
23 #[sea_orm(
24 belongs_to = "super::channel::Entity",
25 from = "Column::ChannelId",
26 to = "super::channel::Column::Id"
27 )]
28 Channel,
29 #[sea_orm(
30 belongs_to = "super::user::Entity",
31 from = "Column::SenderId",
32 to = "super::user::Column::Id"
33 )]
34 Sender,
35}
36
37impl Related<super::channel::Entity> for Entity {
38 fn to() -> RelationDef {
39 Relation::Channel.def()
40 }
41}
42
43impl Related<super::user::Entity> for Entity {
44 fn to() -> RelationDef {
45 Relation::Sender.def()
46 }
47}