debt-pirate/api/src/db/user.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

use sqlx::prelude::FromRow;
2024-08-22 17:29:24 -04:00
use uuid::Uuid;
use super::DbPool;
#[derive(Debug)]
pub struct NewUserEntity {
pub email: String,
pub name: String,
2024-08-22 17:29:24 -04:00
pub user_id: Uuid,
}
impl NewUserEntity {
2024-08-22 17:29:24 -04:00
pub fn new(name: String, email: String) -> Self {
Self {
name,
2024-08-22 17:29:24 -04:00
email,
user_id: Uuid::now_v7(),
}
}
}
#[allow(dead_code)]
#[derive(Debug, FromRow)]
pub struct UserEntity {
pub id: i32,
pub name: String,
2024-08-22 17:29:24 -04:00
pub email: String,
pub user_id: Uuid,
pub status_id: i32,
}
2024-08-22 17:29:24 -04:00
// pub async fn _insert_new_user(
// pool: &DbPool,
// new_user: NewUserEntity,
// ) -> Result<UserEntity, AppError> {
// let NewUserEntity {
// name,
// email,
// user_id,
// } = new_user;
2024-08-22 17:29:24 -04:00
// sqlx::query_as::<_, UserEntity>("INSERT INTO public.user (username, email, password, name) VALUES ($1, $2, $3, $4) RETURNING id, username, email, name, status_id;")
// .bind(username)
// .bind(email)
// .bind(password)
// .bind(name)
// .fetch_one(pool).await
// .map_err(|err| {
// eprintln!("Error inserting NewUserEntity {err:?}");
// AppError::from(err)
// })
// }
2024-08-22 17:29:24 -04:00
// pub async fn verify_user(pool: &DbPool, user_id: i32) -> Result<(), AppError> {
// sqlx::query("UPDATE public.user SET status_id = 1, updated_at = now() WHERE id = $1;")
// .bind(user_id)
// .execute(pool)
// .await
// .map_err(|err| {
// eprintln!("Error verifying user with id '{user_id}'.");
// AppError::from(err)
// })
// .map(|_| ())
// }