update the inline documentation strings

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-06-28 17:43:15 +02:00
parent 2ce66aef09
commit 953c4c6783
19 changed files with 115 additions and 66 deletions

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,15 +0,0 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
// table specific functions
pub mod db_connection;
pub mod harms;
pub mod roles;
pub mod user_roles;
pub mod users;
//pub mod wip;
pub mod tests;

View File

@@ -12,7 +12,7 @@ use diesel::sqlite::Sqlite;
use dotenv::dotenv; use dotenv::dotenv;
use std::env; use std::env;
// generic functions /// establish a sqlite connection
pub fn establish_connection() -> SqliteConnection { pub fn establish_connection() -> SqliteConnection {
// load our .env file // load our .env file
dotenv().ok(); dotenv().ok();
@@ -22,17 +22,18 @@ pub fn establish_connection() -> SqliteConnection {
// establish a new SQLite connection (taking the reference from database_url) // establish a new SQLite connection (taking the reference from database_url)
SqliteConnection::establish(&database_url) SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", &database_url)) .unwrap_or_else(|_| panic!("Error connecting to {}", &database_url))
/* /*
* WIP: integrate tracing! * WIP: integrate tracing!
trace!( trace!(
target: "diesel", target: "diesel",
type: "Sqlite3", type: "Sqlite3",
status: "connected" status: "connected"
); );
*/ */
} }
/// show the sql query
pub fn show_query<T>(query: &T) pub fn show_query<T>(query: &T)
where where
T: diesel::query_builder::QueryFragment<Sqlite>, T: diesel::query_builder::QueryFragment<Sqlite>,

View File

@@ -28,6 +28,7 @@ impl Harm {
// set- -> Update // set- -> Update
// remove- -> Delete // remove- -> Delete
/// create a new harm record
pub fn new( pub fn new(
param_id_harm: &str, param_id_harm: &str,
param_id_policyholder: Option<&str>, param_id_policyholder: Option<&str>,

View File

@@ -28,6 +28,7 @@ impl Role {
// update- -> Update // update- -> Update
// delete- -> Delete // delete- -> Delete
/// create a new role record
pub fn new( pub fn new(
param_role_name: &str, param_role_name: &str,
param_id_user_changed: i32, param_id_user_changed: i32,
@@ -64,6 +65,7 @@ impl Role {
} }
*/ */
/// get all role records
pub fn get_all(connection: &SqliteConnection) -> Box<Vec<Role>> { pub fn get_all(connection: &SqliteConnection) -> Box<Vec<Role>> {
Box::new( Box::new(
roles roles
@@ -73,6 +75,7 @@ impl Role {
) )
} }
/// get a role record
pub fn get( pub fn get(
param_role_name: &str, param_role_name: &str,
connection: &SqliteConnection, //) -> Vec<Role> { connection: &SqliteConnection, //) -> Vec<Role> {
@@ -86,6 +89,7 @@ impl Role {
Ok(query) Ok(query)
} }
/// update a role record
pub fn update( pub fn update(
param_id: i32, param_id: i32,
param_role_name: &str, param_role_name: &str,

View File

@@ -19,6 +19,7 @@ use crate::schema::user_roles::dsl::*;
use crate::schema::user_roles::*; use crate::schema::user_roles::*;
impl UserRole { impl UserRole {
/// create a new user role record
pub fn new( pub fn new(
param_id_user: i32, param_id_user: i32,
param_id_role: i32, param_id_role: i32,
@@ -38,6 +39,7 @@ impl UserRole {
Ok(()) Ok(())
} }
/// get a list of all user role records
pub fn get_all(connection: &SqliteConnection) -> Box<Vec<UserRole>> { pub fn get_all(connection: &SqliteConnection) -> Box<Vec<UserRole>> {
Box::new( Box::new(
user_roles user_roles
@@ -47,6 +49,7 @@ impl UserRole {
) )
} }
/// get a user role record
pub fn get( pub fn get(
param_id_role: i32, param_id_role: i32,
connection: &SqliteConnection, connection: &SqliteConnection,
@@ -60,6 +63,7 @@ impl UserRole {
Ok(query) Ok(query)
} }
/// update a user role record
pub fn update( pub fn update(
param_id_user: i32, param_id_user: i32,
param_id_role: i32, param_id_role: i32,

View File

@@ -28,6 +28,7 @@ impl User {
// set- -> Update // set- -> Update
// remove- -> Delete // remove- -> Delete
/// create a new user record
pub fn new( pub fn new(
param_last_name: &str, param_last_name: &str,
param_first_name: Option<&str>, param_first_name: Option<&str>,
@@ -60,6 +61,7 @@ impl User {
Ok(()) Ok(())
} }
/// get a list of all user records
pub fn get_all(connection: &SqliteConnection) -> Box<Vec<User>> { pub fn get_all(connection: &SqliteConnection) -> Box<Vec<User>> {
Box::new( Box::new(
users users
@@ -84,6 +86,7 @@ impl User {
} }
*/ */
/// update a user record
pub fn update(param_id: i32, connection: &SqliteConnection) -> Result<(), Box<dyn Error>> { pub fn update(param_id: i32, connection: &SqliteConnection) -> Result<(), Box<dyn Error>> {
let query = users.filter(id.eq(param_id)).execute(connection)?; let query = users.filter(id.eq(param_id)).execute(connection)?;
@@ -92,24 +95,26 @@ impl User {
Ok(()) Ok(())
} }
// helper functions // create a hash value for the user password
pub fn hash_password(plain: &str) -> Result<String, Box<dyn Error>> { pub fn hash_password(plain: &str) -> Result<String, Box<dyn Error>> {
Ok(hash(plain, DEFAULT_COST)?) Ok(hash(plain, DEFAULT_COST)?)
} }
// tests /// update the confirmation status of a user emak address
pub fn set_users_email_confirmed(connection: &SqliteConnection) -> QueryResult<usize> { pub fn set_users_email_confirmed(connection: &SqliteConnection) -> QueryResult<usize> {
diesel::update(users) diesel::update(users)
.set(email_confirmed.eq(1)) .set(email_confirmed.eq(1))
.execute(connection) .execute(connection)
} }
/// update a singel column of a given user record
pub fn set_users_single_column(connection: &SqliteConnection) -> QueryResult<usize> { pub fn set_users_single_column(connection: &SqliteConnection) -> QueryResult<usize> {
diesel::insert_into(users) diesel::insert_into(users)
.values(alias_name.eq("Hiedemann")) .values(alias_name.eq("Hiedemann"))
.execute(connection) .execute(connection)
} }
/// update multiple columns of a given user record
pub fn set_users_multiple_columns(connection: &SqliteConnection) -> QueryResult<usize> { pub fn set_users_multiple_columns(connection: &SqliteConnection) -> QueryResult<usize> {
diesel::insert_into(users) diesel::insert_into(users)
.values(( .values((
@@ -120,6 +125,7 @@ impl User {
.execute(connection) .execute(connection)
} }
/// update multiple columns of a given user record with a json string
pub fn set_user_struct_json(connection: &SqliteConnection) -> Result<(), Box<dyn Error>> { pub fn set_user_struct_json(connection: &SqliteConnection) -> Result<(), Box<dyn Error>> {
let json = r#"{ "first_name": "Daniela", "last_name": "Knocke", "alias_name": "Sekretariat", "email": "knocke@kanzlei.hiedemann.de", "email_confirmed": 1, "password_hash": "", "initials": "dkn" }"#; let json = r#"{ "first_name": "Daniela", "last_name": "Knocke", "alias_name": "Sekretariat", "email": "knocke@kanzlei.hiedemann.de", "email_confirmed": 1, "password_hash": "", "initials": "dkn" }"#;
let user_struct = serde_json::from_str::<NewUser>(json)?; let user_struct = serde_json::from_str::<NewUser>(json)?;
@@ -147,6 +153,7 @@ impl User {
impl<'a> RegisterUser<'a> { impl<'a> RegisterUser<'a> {
//pub fn validates(self) -> Result<(), Error> { //pub fn validates(self) -> Result<(), Error> {
/// validate the password hash
pub fn validates(self) -> Result<RegisterUser<'a>, &'static str> { pub fn validates(self) -> Result<RegisterUser<'a>, &'static str> {
let password_are_equal = self.password_hash == self.password_confirmation; let password_are_equal = self.password_hash == self.password_confirmation;
let password_not_empty = self.password_hash.len() > 0; let password_not_empty = self.password_hash.len() > 0;

View File

@@ -5,16 +5,26 @@
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
// backend database crate #![warn(missing_docs, rust_2018_idioms, rust_2018_compatibility)]
//#![recursion_limit = "128"] //#![recursion_limit = "128"]
#![warn(clippy::pedantic)] //#![warn(clippy::pedantic)]
#![warn(clippy::nursery)] //#![warn(clippy::nursery)]
// modules //! advotracker database
pub mod models; //! Supports lawyers to capture relevant data encountered during an
pub mod schema; //! online legal advice.
//! This SQL database backend will consuming Diesel to make use of
//! sql features.
// ?? is this needed in edition 2018 anymore ??
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
/// SQL functions and methods
pub mod functions; pub mod functions;
/// SQL models definitions
pub mod models;
/// SQL schema definitions
pub mod schema;

View File

@@ -1,16 +0,0 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
// bring models into scope
pub mod roles;
pub mod harms;
pub mod users;
pub mod user_roles;
// methods used for: INSERT
//pub mod insert;
//use insert::types::*;

View File

@@ -1,26 +1,32 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
use crait::schema::claim.rs; use crate::schema::claim;
//#[derive(Debug, Deserialize, PartialEq, Queryable)] /// Stucture of a claim record
#[derive(Debug, Queryable)] #[derive(Debug, Queryable)]
pub struct Claim { pub struct Claim {
// id: the auto incremented primary index /// the auto incremented primary index
pub id: i32, pub id: i32,
/// the user id
pub user_id: i32, pub user_id: i32,
/// the type of the user
pub type_: Option<String>, pub type_: Option<String>,
/// the name string of the claim type
pub value: Option<String>, pub value: Option<String>,
} }
/// Structure of a new claim record
#[derive(Debug, Deserialize, Insertable)] #[derive(Debug, Deserialize, Insertable)]
#[table_name = "claims"] #[table_name = "claims"]
pub struct NewClaim<'a> { pub struct NewClaim<'a> {
//pub user_id: &'a i32, //pub user_id: &'a i32,
/// Lifetime to the claim type
pub type_: Option<&'a str>, pub type_: Option<&'a str>,
/// Lifetime to the name of the claim type
pub value: Option<&'a str>, pub value: Option<&'a str>,
} }

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
@@ -11,33 +11,51 @@ use serde_derive::*;
use crate::schema::harms; use crate::schema::harms;
//usage: SELECT, UPDATE, DELETE /// Manage harm records (SELECT, UPDATE, DELETE)
#[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable)] #[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable)]
pub struct Harm { pub struct Harm {
// id: the auto incremented primary index /// the auto incremented primary index
pub id: i32, pub id: i32,
/// the harm name
pub id_harm: String, pub id_harm: String,
/// the policy holder name
pub id_policyholder: Option<String>, pub id_policyholder: Option<String>,
/// the callback number
pub id_callback: Option<String>, pub id_callback: Option<String>,
/// the fallback date
pub date_fallback: Option<NaiveDateTime>, pub date_fallback: Option<NaiveDateTime>,
/// the date the record was recorded
pub date_recording: NaiveDateTime, pub date_recording: NaiveDateTime,
/// the user id
pub id_user: i32, pub id_user: i32,
/// the date the record was created
pub date_created: NaiveDateTime, pub date_created: NaiveDateTime,
/// the user id that has chanced the record
pub id_user_changed: i32, pub id_user_changed: i32,
/// the date the record was changed
pub date_changed: NaiveDateTime, pub date_changed: NaiveDateTime,
} }
// usage: INSERT /// Structure of a new harm
#[derive(Debug, Deserialize, Insertable, Serialize)] #[derive(Debug, Deserialize, Insertable, Serialize)]
#[table_name = "harms"] #[table_name = "harms"]
pub struct NewHarm<'a> { pub struct NewHarm<'a> {
/// Lifetime to the harm name
pub id_harm: &'a str, pub id_harm: &'a str,
/// Lifetime to the policyholder
pub id_policyholder: Option<&'a str>, pub id_policyholder: Option<&'a str>,
/// Lifetime to the callback number
pub id_callback: Option<&'a str>, pub id_callback: Option<&'a str>,
/// the fallback date
pub date_fallback: Option<NaiveDateTime>, pub date_fallback: Option<NaiveDateTime>,
/// the date the record was recorded
pub date_recording: NaiveDateTime, pub date_recording: NaiveDateTime,
/// the user id that has chanced the record
pub id_user: i32, pub id_user: i32,
/// the date the record was created
pub date_created: Option<NaiveDateTime>, pub date_created: Option<NaiveDateTime>,
/// the user id that has chanced the record
pub id_user_changed: i32, pub id_user_changed: i32,
/// Lifetime to the date the record was changed
pub date_changed: Option<NaiveDateTime>, pub date_changed: Option<NaiveDateTime>,
} }

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
@@ -11,23 +11,33 @@ use serde_derive::*;
use crate::schema::roles; use crate::schema::roles;
/// Structure of a role record
#[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable)] #[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable)]
#[table_name = "roles"] #[table_name = "roles"]
pub struct Role { pub struct Role {
// id: the auto incremented primary index /// The auto incremented primary index
pub id: i32, pub id: i32,
/// The role name
pub name: String, pub name: String,
/// Creation date of the role
pub date_created: NaiveDateTime, pub date_created: NaiveDateTime,
/// The user id, that has changed the record
pub id_user_changed: i32, pub id_user_changed: i32,
/// The timestamp, when the record was changed
pub date_changed: NaiveDateTime, pub date_changed: NaiveDateTime,
} }
/// Structure of a new claim record
#[derive(Debug, Deserialize, Insertable, Serialize)] #[derive(Debug, Deserialize, Insertable, Serialize)]
#[table_name = "roles"] #[table_name = "roles"]
pub struct NewRole<'a> { pub struct NewRole<'a> {
/// Lifetime of the role name
pub name: &'a str, pub name: &'a str,
/// Creation date of the role
pub date_created: Option<NaiveDateTime>, pub date_created: Option<NaiveDateTime>,
/// The user id, that has changed the record
pub id_user_changed: i32, pub id_user_changed: i32,
/// The timestamp, when the record was changed
pub date_changed: Option<NaiveDateTime>, pub date_changed: Option<NaiveDateTime>,
} }

View File

@@ -1,23 +1,28 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
use crate::schema::user_roles; use crate::schema::user_roles;
use serde_derive::*; use serde_derive::*;
/// Structure of a user role record
#[derive(Debug, Queryable, PartialEq)] #[derive(Debug, Queryable, PartialEq)]
pub struct UserRole { pub struct UserRole {
/// id of the referenced user
pub id_user: i32, pub id_user: i32,
/// id of the referenced role
pub id_role: i32, pub id_role: i32,
} }
//#[derive(Deserialize)] /// Structure of a new user role record
#[derive(Deserialize, Insertable)] #[derive(Deserialize, Insertable)]
#[table_name = "user_roles"] #[table_name = "user_roles"]
pub struct NewUserRole { pub struct NewUserRole {
/// id of the referenced user
pub id_user: i32, pub id_user: i32,
/// id of the referenced role
pub id_role: i32, pub id_role: i32,
} }

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
@@ -11,25 +11,35 @@ use serde_derive::*;
use crate::schema::users; use crate::schema::users;
// usage: SELECT, UPDATE, DELETE /// Structure of a user record
#[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable, Serialize)] #[derive(AsChangeset, Debug, Deserialize, Identifiable, PartialEq, Queryable, Serialize)]
pub struct User { pub struct User {
// id: the auto incremented primary index /// the auto incremented primary index
pub id: i32, pub id: i32,
/// last name of the user
pub last_name: String, pub last_name: String,
// Option -> returns "None", if db value is null // Option -> returns "None", if db value is null
/// first name of the user
pub first_name: Option<String>, pub first_name: Option<String>,
/// alias of the user name
pub alias_name: Option<String>, pub alias_name: Option<String>,
/// users email address
pub email: Option<String>, pub email: Option<String>,
/// confirmation state of users email address
pub email_confirmed: Option<i32>, pub email_confirmed: Option<i32>,
/// users initials
pub initials: Option<String>, pub initials: Option<String>,
/// users password hash
pub password_hash: Option<String>, pub password_hash: Option<String>,
/// timestamp when the record was created
pub date_created: NaiveDateTime, pub date_created: NaiveDateTime,
/// user id that has changed the record
pub id_changed: i32, pub id_changed: i32,
/// timestamp when the record was changed
pub date_changed: NaiveDateTime, pub date_changed: NaiveDateTime,
} }
// usage: INSERT /// Structure of a new user record
#[derive(Debug, Deserialize, Insertable, Serialize)] #[derive(Debug, Deserialize, Insertable, Serialize)]
#[table_name = "users"] #[table_name = "users"]
pub struct NewUser<'a> { pub struct NewUser<'a> {
@@ -45,9 +55,13 @@ pub struct NewUser<'a> {
pub date_changed: Option<NaiveDateTime>, pub date_changed: Option<NaiveDateTime>,
} }
/// Structure of a user registration
#[derive(Debug, Deserialize, Queryable)] #[derive(Debug, Deserialize, Queryable)]
pub struct RegisterUser<'a> { pub struct RegisterUser<'a> {
/// Lifetime of users last name
pub last_name: &'a str, pub last_name: &'a str,
/// Lifetime of users first name
pub first_name: Option<&'a str>, pub first_name: Option<&'a str>,
pub alias: Option<&'a str>, pub alias: Option<&'a str>,
pub email: Option<&'a str>, pub email: Option<&'a str>,