diff --git a/src/functions/harms.rs b/src/functions/harms.rs index b1e4dc4..fb1a81e 100644 --- a/src/functions/harms.rs +++ b/src/functions/harms.rs @@ -69,6 +69,7 @@ impl Harm { } */ + /// get list of all harm record pub fn get_all(connection: &SqliteConnection) -> Box> { Box::new( harms @@ -78,6 +79,7 @@ impl Harm { ) } + /// get harm record pub fn get( param_id_harm: &str, connection: &SqliteConnection, @@ -91,6 +93,7 @@ impl Harm { Ok(query) } + /// update harm record pub fn update( param_id: i32, param_id_harm: &str, @@ -106,6 +109,7 @@ impl Harm { } } +/// set a test harm record pub fn set_harms_single_column(connection: &SqliteConnection) -> QueryResult { insert_into(harms) .values(id_harm.eq("123456789")) @@ -113,6 +117,7 @@ pub fn set_harms_single_column(connection: &SqliteConnection) -> QueryResult(json).unwrap(); + let user_struct = serde_json::from_str::<'_>(json).unwrap(); let query = diesel::insert_into(users).values(&user_struct); let sql = "INSERT INTO `users` (`last_name`, `email`, `email_confirmed`, `initials`, `password_hash`, `id_changed`) \ VALUES (?, ?, ?, ?, ?, ?) \ diff --git a/src/functions/users.rs b/src/functions/users.rs index 7ea6070..4ab983c 100644 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -13,7 +13,8 @@ use diesel::sqlite::Sqlite; #[cfg(test)] use diesel::sqlite::SqliteConnection; use diesel::{QueryDsl, RunQueryDsl}; -use serde_json; +// WIP: json functionality need work! +// use serde_json; use std::error::Error; //use crate::models::users::{NewUser, RegisterUser, User, UserList}; @@ -95,12 +96,12 @@ impl User { Ok(()) } - // create a hash value for the user password + /// create a hash value for the user password pub fn hash_password(plain: &str) -> Result> { Ok(hash(plain, DEFAULT_COST)?) } - /// update the confirmation status of a user emak address + /// update the confirmation status of a user emak address pub fn set_users_email_confirmed(connection: &SqliteConnection) -> QueryResult { diesel::update(users) .set(email_confirmed.eq(1)) diff --git a/src/models/users.rs b/src/models/users.rs index 76ee455..544c89b 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -43,15 +43,25 @@ pub struct User { #[derive(Debug, Deserialize, Insertable, Serialize)] #[table_name = "users"] pub struct NewUser<'a> { + /// Lifetime for users last name pub last_name: &'a str, + /// Lifetime for users first name pub first_name: Option<&'a str>, + /// Lifetime for users alias name pub alias_name: Option<&'a str>, + /// Lifetime for users users email pub email: Option<&'a str>, + /// Lifetime for users email-confirmed pub email_confirmed: Option, + /// Lifetime for users initials pub initials: Option<&'a str>, + /// Lifetime for users password hash pub password_hash: &'a str, + /// Optional timestamp for cration date pub date_created: Option, + /// Optional userid that changed the record pub id_changed: i32, + /// Optional timestamp for the change date pub date_changed: Option, } @@ -63,12 +73,19 @@ pub struct RegisterUser<'a> { pub last_name: &'a str, /// Lifetime of users first name pub first_name: Option<&'a str>, + /// Lifetime for users alias name column pub alias: Option<&'a str>, + /// Lifetime for users email column pub email: Option<&'a str>, - pub email_confirmed: Option, + /// Lifetime for users email confirmed column + pub email_confirmed: Option, + /// Lifetime for users initials pub initials: Option<&'a str>, + /// Lifetime for users password hash pub password_hash: &'a str, + /// Lifetime for users password confirmation pub password_confirmation: &'a str, + /// Optional userid that changed the record pub id_changed: i32, }