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