From 6a468ff8a89f4f65aff2d923cf331e5d3d3a3f0d Mon Sep 17 00:00:00 2001 From: franklinblanco Date: Mon, 15 Aug 2022 11:52:51 -0400 Subject: [PATCH] Added user domain objs --- src/domain/mod.rs | 1 + src/domain/user/mod.rs | 2 ++ src/domain/user/token.rs | 31 +++++++++++++++++++++++++++++ src/domain/user/user.rs | 42 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 3 ++- 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/domain/mod.rs create mode 100644 src/domain/user/mod.rs create mode 100644 src/domain/user/token.rs create mode 100644 src/domain/user/user.rs diff --git a/src/domain/mod.rs b/src/domain/mod.rs new file mode 100644 index 0000000..018ff2e --- /dev/null +++ b/src/domain/mod.rs @@ -0,0 +1 @@ +pub mod user; \ No newline at end of file diff --git a/src/domain/user/mod.rs b/src/domain/user/mod.rs new file mode 100644 index 0000000..05e678b --- /dev/null +++ b/src/domain/user/mod.rs @@ -0,0 +1,2 @@ +pub mod token; +pub mod user; \ No newline at end of file diff --git a/src/domain/user/token.rs b/src/domain/user/token.rs new file mode 100644 index 0000000..041a667 --- /dev/null +++ b/src/domain/user/token.rs @@ -0,0 +1,31 @@ +use chrono::NaiveDateTime; +use serde::{Serialize, Deserialize}; + +pub const AUTH_TOKEN_EXPIRATION_TIME_IN_DAYS:i32 = 1; +pub const REFRESH_TOKEN_EXPIRATION_TIME_IN_DAYS: i32 = 20; + +#[derive(Serialize, Deserialize)] +pub struct Token { + #[serde(skip_serializing)] + pub id: i32, + pub user_id: i32, + #[serde(skip_serializing)] + pub time_created: Option, + #[serde(skip_serializing)] + pub last_updated: Option, + pub auth_token: String, + pub refresh_token: String +} + +impl Token{ + pub fn new(user_id: i32, auth_token: String, refresh_token: String) -> Token{ + Token { + id: 0, + user_id, + time_created: None, + last_updated: None, + auth_token, + refresh_token + } + } +} \ No newline at end of file diff --git a/src/domain/user/user.rs b/src/domain/user/user.rs new file mode 100644 index 0000000..0417d4d --- /dev/null +++ b/src/domain/user/user.rs @@ -0,0 +1,42 @@ +use chrono::{NaiveDateTime}; +use serde::{Serialize, Deserialize}; + +use crate::dtos::user::user_dtos::UserForCreationDto; + +#[derive(Serialize, Deserialize, Debug)] +pub struct User{ + pub id: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub time_created: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub last_updated: Option, + pub app: String, + pub email: String, + pub name: String, + #[serde(skip_serializing)] + pub password: String, + #[serde(skip_serializing)] + pub salt: String +} +impl User { + pub fn _new() -> User { + User { id: 0, + time_created: None, // This will be automatically generated from the database + last_updated: None, // This will be automatically generated from the database + app: "".to_string(), + email: "".to_string(), + name:"".to_string(), + password:"".to_string(), + salt: "".to_string() } + } + pub fn new_for_creation(incoming_user: &UserForCreationDto) -> User{ + User { id: 0, + time_created: None, // This will be automatically generated from the database + last_updated: None, // This will be automatically generated from the database + app: incoming_user.app.to_string(), + email: incoming_user.email.to_string(), + name: incoming_user.name.to_string(), + password: incoming_user.password.to_string(), + salt: "".to_string() } + } +} diff --git a/src/lib.rs b/src/lib.rs index a4da8a1..0f0238e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ #[forbid(unsafe_code)] -pub mod dtos; \ No newline at end of file +pub mod dtos; +pub mod domain; \ No newline at end of file