user.rs

 1use crate::db::UserId;
 2use chrono::NaiveDateTime;
 3use sea_orm::entity::prelude::*;
 4use serde::Serialize;
 5
 6/// A user model.
 7#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel, Serialize)]
 8#[sea_orm(table_name = "users")]
 9pub struct Model {
10    #[sea_orm(primary_key)]
11    pub id: UserId,
12    pub github_login: String,
13    pub github_user_id: i32,
14    pub github_user_created_at: Option<NaiveDateTime>,
15    pub email_address: Option<String>,
16    pub name: Option<String>,
17    pub admin: bool,
18    pub connected_once: bool,
19    pub created_at: NaiveDateTime,
20}
21
22#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
23pub enum Relation {
24    #[sea_orm(has_one = "super::room_participant::Entity")]
25    RoomParticipant,
26    #[sea_orm(has_many = "super::project::Entity")]
27    HostedProjects,
28    #[sea_orm(has_many = "super::channel_member::Entity")]
29    ChannelMemberships,
30}
31
32impl Related<super::room_participant::Entity> for Entity {
33    fn to() -> RelationDef {
34        Relation::RoomParticipant.def()
35    }
36}
37
38impl Related<super::project::Entity> for Entity {
39    fn to() -> RelationDef {
40        Relation::HostedProjects.def()
41    }
42}
43
44impl Related<super::channel_member::Entity> for Entity {
45    fn to() -> RelationDef {
46        Relation::ChannelMemberships.def()
47    }
48}
49
50impl ActiveModelBehavior for ActiveModel {}