From c8edab57a8ffe52f69e28a3fe6024a1484ca67e8 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 17 May 2024 23:22:15 +0530 Subject: [PATCH] feat: db: username_exists port --- .../application/port/output/db/errors.rs | 14 +++++++ .../application/port/output/db/mod.rs | 10 +++++ .../port/output/db/username_exists.rs | 42 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/identity/application/port/output/db/errors.rs create mode 100644 src/identity/application/port/output/db/mod.rs create mode 100644 src/identity/application/port/output/db/username_exists.rs diff --git a/src/identity/application/port/output/db/errors.rs b/src/identity/application/port/output/db/errors.rs new file mode 100644 index 0000000..09a9874 --- /dev/null +++ b/src/identity/application/port/output/db/errors.rs @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use derive_more::Display; +use serde::{Deserialize, Serialize}; + +pub type OutDBPortResult = Result; + +#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +pub enum OutDBPortError { + InternalError, + VerificationOTPSecretExists, +} diff --git a/src/identity/application/port/output/db/mod.rs b/src/identity/application/port/output/db/mod.rs new file mode 100644 index 0000000..b3e3eeb --- /dev/null +++ b/src/identity/application/port/output/db/mod.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub mod create_verification_secret; +pub mod email_exists; +pub mod errors; +pub mod username_exists; +//pub mod get_verification_secret; +//pub mod delete_verification_secret; diff --git a/src/identity/application/port/output/db/username_exists.rs b/src/identity/application/port/output/db/username_exists.rs new file mode 100644 index 0000000..2bcacbc --- /dev/null +++ b/src/identity/application/port/output/db/username_exists.rs @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use mockall::predicate::*; +use mockall::*; + +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[automock] +#[async_trait::async_trait] +pub trait UsernameExistsOutDBPort: Send + Sync { + async fn username_exists(&self, username: &str) -> OutDBPortResult; +} + +pub type UsernameExistsOutDBPortObj = std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_username_exists_db_port( + times: Option, + returning: bool, + ) -> UsernameExistsOutDBPortObj { + let mut m = MockUsernameExistsOutDBPort::new(); + if let Some(times) = times { + m.expect_username_exists() + .times(times) + .returning(move |_| Ok(returning)); + } else { + m.expect_username_exists().returning(move |_| Ok(returning)); + } + + Arc::new(m) + } +}