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_many = "super::access_token::Entity")]
25    AccessToken,
26    #[sea_orm(has_one = "super::room_participant::Entity")]
27    RoomParticipant,
28    #[sea_orm(has_many = "super::project::Entity")]
29    HostedProjects,
30    #[sea_orm(has_many = "super::channel_member::Entity")]
31    ChannelMemberships,
32}
33
34impl Related<super::access_token::Entity> for Entity {
35    fn to() -> RelationDef {
36        Relation::AccessToken.def()
37    }
38}
39
40impl Related<super::room_participant::Entity> for Entity {
41    fn to() -> RelationDef {
42        Relation::RoomParticipant.def()
43    }
44}
45
46impl Related<super::project::Entity> for Entity {
47    fn to() -> RelationDef {
48        Relation::HostedProjects.def()
49    }
50}
51
52impl Related<super::channel_member::Entity> for Entity {
53    fn to() -> RelationDef {
54        Relation::ChannelMemberships.def()
55    }
56}
57
58impl ActiveModelBehavior for ActiveModel {}