Skip to main content

rbp_auth/
member.rs

1use rbp_core::ID;
2use rbp_core::Unique;
3
4/// Authenticated user with verified identity.
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct Member {
7    id: ID<Self>,
8    username: String,
9    email: String,
10}
11
12impl Member {
13    pub fn new(id: ID<Self>, username: String, email: String) -> Self {
14        Self {
15            id,
16            username,
17            email,
18        }
19    }
20    pub fn username(&self) -> &str {
21        &self.username
22    }
23    pub fn email(&self) -> &str {
24        &self.email
25    }
26}
27
28impl Unique for Member {
29    fn id(&self) -> ID<Self> {
30        self.id
31    }
32}
33
34#[cfg(feature = "database")]
35mod schema {
36    use super::*;
37    use rbp_database::*;
38
39    /// Schema implementation for Member (users table).
40    /// Note: hashword is a database-only field, not part of Member domain type.
41    impl Schema for Member {
42        fn name() -> &'static str {
43            USERS
44        }
45        fn columns() -> &'static [tokio_postgres::types::Type] {
46            &[
47                tokio_postgres::types::Type::UUID,
48                tokio_postgres::types::Type::VARCHAR,
49                tokio_postgres::types::Type::VARCHAR,
50                tokio_postgres::types::Type::TEXT,
51            ]
52        }
53        fn creates() -> &'static str {
54            const_format::concatcp!(
55                "CREATE TABLE IF NOT EXISTS ",
56                USERS,
57                " (
58                    id          UUID PRIMARY KEY,
59                    username    VARCHAR(32) UNIQUE NOT NULL,
60                    email       VARCHAR(255) UNIQUE NOT NULL,
61                    hashword    TEXT NOT NULL
62                );"
63            )
64        }
65        fn indices() -> &'static str {
66            const_format::concatcp!(
67                "CREATE INDEX IF NOT EXISTS idx_users_username ON ",
68                USERS,
69                " (username);
70                 CREATE INDEX IF NOT EXISTS idx_users_email ON ",
71                USERS,
72                " (email);"
73            )
74        }
75        fn copy() -> &'static str {
76            unimplemented!()
77        }
78        fn truncates() -> &'static str {
79            unimplemented!()
80        }
81        fn freeze() -> &'static str {
82            unimplemented!()
83        }
84    }
85}