Refactor InternalUser to InternalNewUser

This commit is contained in:
2025-11-30 20:15:53 +01:00
parent a3e6563912
commit 6f55add34d
7 changed files with 25 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ tower = { version = "0.5.2", features = ["tokio", "tracing"] }
tower-http = { version = "0.6.7", features = ["cors"] }
tracing = { version = "0.1.43", features = ["max_level_debug"] }
tracing-subscriber = "0.3.22"
uuid = { version = "1.18.1", features = ["v4", "serde"] }
validator = { version = "0.20.0", features = ["derive"] }
[build-dependencies]

View File

@@ -0,0 +1 @@
pub mod user_routines;

View File

@@ -0,0 +1,5 @@
use std::sync::Arc;
use crate::{domain::user::NewUser, state::AppState};
pub async fn create(state: Arc<AppState>, new_user: NewUser) -> Result<User> {}

View File

@@ -28,7 +28,17 @@ pub struct NewUser {
}
#[derive(Debug, Clone, Deserialize)]
pub struct InternalNewUser {
username: String,
email: Option<String>,
password_hash: String,
first_name: Option<String>,
last_name: Option<String>,
}
#[derive(Debug, Clone)]
pub struct InternalUser {
id: i64,
username: String,
email: Option<String>,
password_hash: String,
@@ -38,6 +48,7 @@ pub struct InternalUser {
#[derive(Debug, Clone, Serialize)]
pub struct User {
id: i64,
username: String,
email: Option<String>,
first_name: Option<String>,
@@ -49,7 +60,7 @@ pub enum UserConversionError {
HashFailed(password_hash::Error),
}
impl TryFrom<NewUser> for InternalUser {
impl TryFrom<NewUser> for InternalNewUser {
type Error = UserConversionError;
fn try_from(value: NewUser) -> Result<Self, Self::Error> {
let password_hash =
@@ -67,6 +78,7 @@ impl TryFrom<NewUser> for InternalUser {
impl From<InternalUser> for User {
fn from(value: InternalUser) -> Self {
Self {
id: value.id,
username: value.username,
email: value.email,
first_name: value.first_name,

View File

@@ -1,4 +1,5 @@
pub mod auth;
pub mod core;
pub mod domain;
pub mod router;
pub mod state;

View File

@@ -6,7 +6,7 @@ use tracing::{debug, error, info, warn};
use validator::Validate;
use crate::{
domain::user::{InternalUser, NewUser, User},
domain::user::{InternalNewUser, NewUser, User},
state::AppState,
};
@@ -18,7 +18,7 @@ pub async fn create(
return Err(StatusCode::BAD_REQUEST);
}
let internal = InternalUser::try_from(new_user).map_err(|e| {
let internal = InternalNewUser::try_from(new_user).map_err(|e| {
error!("Conversion to InternalUser failed: {e}");
StatusCode::INTERNAL_SERVER_ERROR
})?;

View File

@@ -1,9 +1,9 @@
use std::collections::HashMap;
use crate::domain::user::InternalUser;
use crate::domain::user::InternalNewUser;
pub struct AppState {
pub users: HashMap<String, InternalUser>,
pub users: HashMap<String, InternalNewUser>,
}
impl AppState {