Added user domain objs
This commit is contained in:
parent
cda54f0005
commit
6a468ff8a8
1
src/domain/mod.rs
Normal file
1
src/domain/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod user;
|
2
src/domain/user/mod.rs
Normal file
2
src/domain/user/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod token;
|
||||
pub mod user;
|
31
src/domain/user/token.rs
Normal file
31
src/domain/user/token.rs
Normal file
@ -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<NaiveDateTime>,
|
||||
#[serde(skip_serializing)]
|
||||
pub last_updated: Option<NaiveDateTime>,
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
42
src/domain/user/user.rs
Normal file
42
src/domain/user/user.rs
Normal file
@ -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<NaiveDateTime>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_updated: Option<NaiveDateTime>,
|
||||
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() }
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#[forbid(unsafe_code)]
|
||||
|
||||
pub mod dtos;
|
||||
pub mod domain;
|
Loading…
Reference in New Issue
Block a user