Skip to content

Commit

Permalink
refactor(users): Separate signup and signin (#2921)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
ThisIsMani and hyperswitch-bot[bot] authored Dec 4, 2023
1 parent 9d93533 commit 80efeb7
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 109 deletions.
15 changes: 9 additions & 6 deletions crates/api_models/src/events/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use crate::user::{
dashboard_metadata::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
},
ChangePasswordRequest, ConnectAccountRequest, ConnectAccountResponse,
CreateInternalUserRequest, GetUsersResponse, SwitchMerchantIdRequest, UserMerchantCreate,
AuthorizeResponse, ChangePasswordRequest, ConnectAccountRequest, CreateInternalUserRequest,
DashboardEntryResponse, GetUsersResponse, SignUpRequest, SignUpWithMerchantIdRequest,
SwitchMerchantIdRequest, UserMerchantCreate,
};

impl ApiEventMetric for ConnectAccountResponse {
impl ApiEventMetric for DashboardEntryResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::User {
merchant_id: self.merchant_id.clone(),
Expand All @@ -19,9 +20,9 @@ impl ApiEventMetric for ConnectAccountResponse {
}
}

impl ApiEventMetric for ConnectAccountRequest {}

common_utils::impl_misc_api_event_type!(
SignUpRequest,
SignUpWithMerchantIdRequest,
ChangePasswordRequest,
GetMultipleMetaDataPayload,
GetMetaDataResponse,
Expand All @@ -30,7 +31,9 @@ common_utils::impl_misc_api_event_type!(
SwitchMerchantIdRequest,
CreateInternalUserRequest,
UserMerchantCreate,
GetUsersResponse
GetUsersResponse,
AuthorizeResponse,
ConnectAccountRequest
);

#[cfg(feature = "dummy_connector")]
Expand Down
40 changes: 38 additions & 2 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ pub mod dashboard_metadata;
pub mod sample_data;

#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct ConnectAccountRequest {
pub struct SignUpWithMerchantIdRequest {
pub name: Secret<String>,
pub email: pii::Email,
pub password: Secret<String>,
pub company_name: String,
}

pub type SignUpWithMerchantIdResponse = AuthorizeResponse;

#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct SignUpRequest {
pub email: pii::Email,
pub password: Secret<String>,
}

pub type SignUpResponse = DashboardEntryResponse;

#[derive(serde::Serialize, Debug, Clone)]
pub struct ConnectAccountResponse {
pub struct DashboardEntryResponse {
pub token: Secret<String>,
pub merchant_id: String,
pub name: Secret<String>,
Expand All @@ -25,6 +37,28 @@ pub struct ConnectAccountResponse {
pub user_id: String,
}

pub type SignInRequest = SignUpRequest;

pub type SignInResponse = DashboardEntryResponse;

#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct ConnectAccountRequest {
pub email: pii::Email,
}

pub type ConnectAccountResponse = AuthorizeResponse;

#[derive(serde::Serialize, Debug, Clone)]
pub struct AuthorizeResponse {
pub is_email_sent: bool,
//this field is added for audit/debug reasons
#[serde(skip_serializing)]
pub user_id: String,
//this field is added for audit/debug reasons
#[serde(skip_serializing)]
pub merchant_id: String,
}

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct ChangePasswordRequest {
pub new_password: Secret<String>,
Expand All @@ -36,6 +70,8 @@ pub struct SwitchMerchantIdRequest {
pub merchant_id: String,
}

pub type SwitchMerchantResponse = DashboardEntryResponse;

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct CreateInternalUserRequest {
pub name: Secret<String>,
Expand Down
Loading

0 comments on commit 80efeb7

Please sign in to comment.