Minor refactoring
Some checks failed
Rust Build / Check (pull_request) Failing after 53s
Rust Build / Test Suite (pull_request) Failing after 49s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Failing after 50s
Rust Build / build (pull_request) Failing after 57s

This commit is contained in:
2025-04-05 00:10:11 -04:00
parent 2577332612
commit dc1f417c4f
2 changed files with 7 additions and 27 deletions

View File

@@ -235,6 +235,10 @@ mod tests {
usr.username, returned_usr.username, usr.username, returned_usr.username,
"Usernames do not match" "Usernames do not match"
); );
assert!(
!returned_usr.date_created.is_empty(),
"Date Created is empty"
);
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err.to_string()); assert!(false, "Error: {:?}", err.to_string());

View File

@@ -1,12 +1,8 @@
pub mod user { pub mod user {
// use crate::models;
// use serde::Serialize;
#[derive(Debug, serde::Serialize, sqlx::FromRow)] #[derive(Debug, serde::Serialize, sqlx::FromRow)]
pub struct InsertedData { pub struct InsertedData {
pub id: uuid::Uuid, pub id: uuid::Uuid,
pub date_created: Option<time::OffsetDateTime>, pub date_created: Option<time::OffsetDateTime>,
// pub email: String,
} }
pub async fn insert( pub async fn insert(
@@ -16,11 +12,11 @@ pub mod user {
let result = sqlx::query_as!( let result = sqlx::query_as!(
InsertedData, InsertedData,
r#" r#"
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, date_created) INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW()) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, date_created; RETURNING id, date_created;
"#, "#,
&user.username, // Bind the input message securely &user.username,
&user.password, &user.password,
&user.email, &user.email,
&user.phone, &user.phone,
@@ -40,25 +36,5 @@ pub mod user {
Ok(id) => Ok(id.id), Ok(id) => Ok(id.id),
Err(err) => Err(err), Err(err) => Err(err),
} }
/*
let insert_sql = "INSERT INTO \"user\" (username, password, email, phone, firstname, lastname, email_verified, status) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id";
match sqlx::query_scalar(insert_sql)
.bind(&user.username) // Bind the input message securely
.bind(&user.password)
.bind(&user.email)
.bind(&user.phone)
.bind(&user.firstname)
.bind(&user.lastname)
.bind(user.email_verified)
.bind(&user.status)
.fetch_one(pool) // Execute and expect exactly ONE row with ONE column back
.await
{
Ok(o) => Ok(o),
Err(err) => Err(err), // _ => uuid::Uuid::nil(),
}
*/
} }
} }