Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
161f94fd41
|
||
|
|
3980acf79e
|
||
|
|
e126e4bc06
|
||
|
|
d99aa2587a
|
||
|
|
e965cdeed9 | ||
|
|
34c47ac529 | ||
|
|
e5ae5e1828 | ||
|
|
179a550034 | ||
|
|
a8e173d831 |
@@ -1,4 +1,5 @@
|
||||
pub mod config;
|
||||
pub mod contact;
|
||||
pub mod message;
|
||||
pub mod token;
|
||||
pub mod user;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct MessageEventResponse {
|
||||
pub id: uuid::Uuid,
|
||||
pub scheduled_message_event_id: uuid::Uuid,
|
||||
// Json field
|
||||
pub response: String,
|
||||
pub user_id: uuid::Uuid,
|
||||
pub contact_id: uuid::Uuid,
|
||||
pub message_id: uuid::Uuid,
|
||||
pub status: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub sent: Option<time::OffsetDateTime>,
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pub mod event;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct Message {
|
||||
pub id: uuid::Uuid,
|
||||
pub content: String,
|
||||
pub user_id: uuid::Uuid,
|
||||
}
|
||||
@@ -15,3 +15,88 @@ pub struct User {
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub last_login: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct ServiceUser {
|
||||
pub id: uuid::Uuid,
|
||||
pub username: String,
|
||||
pub passphrase: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub created: Option<time::OffsetDateTime>,
|
||||
// When serializing to json, if empty do not populate
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub last_login: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct Organization {
|
||||
pub id: uuid::Uuid,
|
||||
pub name: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub created: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct UserLoginHistory {
|
||||
pub id: uuid::Uuid,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub login_time: Option<time::OffsetDateTime>,
|
||||
pub user_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct ServiceUserLoginHistory {
|
||||
pub id: uuid::Uuid,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub login_time: Option<time::OffsetDateTime>,
|
||||
pub service_user_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct UserProfile {
|
||||
pub user_id: uuid::Uuid,
|
||||
pub phone_number: String,
|
||||
pub username: String,
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub created: Option<time::OffsetDateTime>,
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub last_login: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
pub fn init_user_profile(usr: &User) -> UserProfile {
|
||||
UserProfile {
|
||||
user_id: usr.id,
|
||||
phone_number: usr.phone_number.clone(),
|
||||
username: usr.username.clone(),
|
||||
firstname: usr.firstname.clone(),
|
||||
lastname: usr.lastname.clone(),
|
||||
created: usr.created,
|
||||
last_login: usr.last_login,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_init_user_profile() {
|
||||
let usr = super::User {
|
||||
id: uuid::Uuid::new_v4(),
|
||||
phone_number: String::from("+12308438462"),
|
||||
username: String::from("Cowboy99"),
|
||||
password: String::from("238n7cyr2q89d3xhe2"),
|
||||
firstname: String::from("BillyBob"),
|
||||
lastname: String::from("Jones"),
|
||||
created: Some(time::OffsetDateTime::now_utc()),
|
||||
last_login: Some(time::OffsetDateTime::now_utc()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let profile = super::init_user_profile(&usr);
|
||||
assert_eq!(
|
||||
usr.phone_number, profile.phone_number,
|
||||
"Phone numbers are not equal"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user