chore: rename *Exists error to Dupliate* error
This commit is contained in:
parent
5a9043e226
commit
1565e56737
7 changed files with 24 additions and 12 deletions
|
@ -48,7 +48,7 @@ mod tests {
|
||||||
// duplicate: secret exists
|
// duplicate: secret exists
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.create_verification_secret(msg).await.err(),
|
db.create_verification_secret(msg).await.err(),
|
||||||
Some(OutDBPortError::VerificationOTPSecretExists)
|
Some(OutDBPortError::DuplicateVerificationOTPSecret)
|
||||||
);
|
);
|
||||||
|
|
||||||
settings.drop_db().await;
|
settings.drop_db().await;
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl From<SqlxError> for OutDBPortError {
|
||||||
} else if msg.contains("user_query_email_key") {
|
} else if msg.contains("user_query_email_key") {
|
||||||
return Self::InternalError;
|
return Self::InternalError;
|
||||||
} else if msg.contains("verification_otp_secret_key") {
|
} else if msg.contains("verification_otp_secret_key") {
|
||||||
return Self::VerificationOTPSecretExists;
|
return Self::DuplicateVerificationOTPSecret;
|
||||||
} else {
|
} else {
|
||||||
println!("{msg}");
|
println!("{msg}");
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,12 @@ impl From<SqlxError> for OutDBPortError {
|
||||||
Self::InternalError
|
Self::InternalError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// map custom row not found error to DB error
|
||||||
|
pub fn map_row_not_found_err(e: SqlxError, row_not_found: OutDBPortError) -> OutDBPortError {
|
||||||
|
if let SqlxError::RowNotFound = e {
|
||||||
|
row_not_found
|
||||||
|
} else {
|
||||||
|
e.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,5 +10,6 @@ pub type OutDBPortResult<V> = Result<V, OutDBPortError>;
|
||||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum OutDBPortError {
|
pub enum OutDBPortError {
|
||||||
InternalError,
|
InternalError,
|
||||||
VerificationOTPSecretExists,
|
DuplicateVerificationOTPSecret,
|
||||||
|
VerificationOTPSecretNotFound,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,6 @@ pub mod create_verification_secret;
|
||||||
pub mod delete_verification_secret;
|
pub mod delete_verification_secret;
|
||||||
pub mod email_exists;
|
pub mod email_exists;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
pub mod get_verification_secret;
|
||||||
pub mod username_exists;
|
pub mod username_exists;
|
||||||
pub mod verification_secret_exists;
|
pub mod verification_secret_exists;
|
||||||
|
|
|
@ -10,9 +10,9 @@ pub type IdentityResult<V> = Result<V, IdentityError>;
|
||||||
|
|
||||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum IdentityError {
|
pub enum IdentityError {
|
||||||
UsernameExists,
|
DuplicateUsername,
|
||||||
VerificationOTPSecretDoesntExist,
|
VerificationOTPSecretNotFound,
|
||||||
EmailExists,
|
DuplicateEmail,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type IdentityCommandResult<V> = Result<V, IdentityCommandError>;
|
pub type IdentityCommandResult<V> = Result<V, IdentityCommandError>;
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl MarkUserVerifiedUseCase for MarkUserVerifiedService {
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
return Err(IdentityError::VerificationOTPSecretDoesntExist);
|
return Err(IdentityError::VerificationOTPSecretNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.db_delete_verification_secret_adapter
|
self.db_delete_verification_secret_adapter
|
||||||
|
@ -86,7 +86,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s.mark_user_verified(cmd.clone()).await.err(),
|
s.mark_user_verified(cmd.clone()).await.err(),
|
||||||
Some(IdentityError::VerificationOTPSecretDoesntExist)
|
Some(IdentityError::VerificationOTPSecretNotFound)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::identity::application::port::output::{
|
||||||
use crate::utils::random_string::*;
|
use crate::utils::random_string::*;
|
||||||
|
|
||||||
pub const SECRET_LEN: usize = 20;
|
pub const SECRET_LEN: usize = 20;
|
||||||
|
pub const REGISTRATION_SECRET_PURPOSE: &str = "account_validation";
|
||||||
|
|
||||||
#[derive(Builder)]
|
#[derive(Builder)]
|
||||||
pub struct RegisterUserService {
|
pub struct RegisterUserService {
|
||||||
|
@ -35,7 +36,7 @@ impl RegisterUserUseCase for RegisterUserService {
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
return Err(IdentityError::UsernameExists);
|
return Err(IdentityError::DuplicateUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self
|
if self
|
||||||
|
@ -44,7 +45,7 @@ impl RegisterUserUseCase for RegisterUserService {
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
return Err(IdentityError::EmailExists);
|
return Err(IdentityError::DuplicateEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
let secret = self.random_string_adapter.get_random(SECRET_LEN);
|
let secret = self.random_string_adapter.get_random(SECRET_LEN);
|
||||||
|
@ -152,7 +153,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s.register_user(cmd.clone()).await.err(),
|
s.register_user(cmd.clone()).await.err(),
|
||||||
Some(IdentityError::UsernameExists)
|
Some(IdentityError::DuplicateUsername)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s.register_user(cmd.clone()).await.err(),
|
s.register_user(cmd.clone()).await.err(),
|
||||||
Some(IdentityError::EmailExists)
|
Some(IdentityError::DuplicateEmail)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue