mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
fix(customers): include address details in customer list response
Added address lookup for customers in list endpoints to include complete customer information with addresses when available. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -588,6 +588,7 @@ pub async fn list_customers(
|
|||||||
request: customers::CustomerListRequest,
|
request: customers::CustomerListRequest,
|
||||||
) -> errors::CustomerResponse<Vec<customers::CustomerResponse>> {
|
) -> errors::CustomerResponse<Vec<customers::CustomerResponse>> {
|
||||||
let db = state.store.as_ref();
|
let db = state.store.as_ref();
|
||||||
|
let key_manager_state = &(&state).into();
|
||||||
|
|
||||||
let customer_list_constraints = crate::db::customers::CustomerListConstraints {
|
let customer_list_constraints = crate::db::customers::CustomerListConstraints {
|
||||||
limit: request
|
limit: request
|
||||||
@ -600,7 +601,7 @@ pub async fn list_customers(
|
|||||||
|
|
||||||
let domain_customers = db
|
let domain_customers = db
|
||||||
.list_customers_by_merchant_id(
|
.list_customers_by_merchant_id(
|
||||||
&(&state).into(),
|
key_manager_state,
|
||||||
&merchant_id,
|
&merchant_id,
|
||||||
&key_store,
|
&key_store,
|
||||||
customer_list_constraints,
|
customer_list_constraints,
|
||||||
@ -609,10 +610,24 @@ pub async fn list_customers(
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
let customers = domain_customers
|
let customers = {
|
||||||
.into_iter()
|
let mut customers = Vec::with_capacity(domain_customers.len());
|
||||||
.map(|domain_customer| customers::CustomerResponse::foreign_from((domain_customer, None)))
|
for domain_customer in domain_customers {
|
||||||
.collect();
|
let address = match &domain_customer.address_id {
|
||||||
|
Some(address_id) => Some(api_models::payments::AddressDetails::from(
|
||||||
|
db.find_address_by_address_id(key_manager_state, address_id, &key_store)
|
||||||
|
.await
|
||||||
|
.switch()?,
|
||||||
|
)),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
customers.push(customers::CustomerResponse::foreign_from((
|
||||||
|
domain_customer,
|
||||||
|
address,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
customers
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
let customers = domain_customers
|
let customers = domain_customers
|
||||||
@ -632,6 +647,8 @@ pub async fn list_customers_with_count(
|
|||||||
request: customers::CustomerListRequestWithConstraints,
|
request: customers::CustomerListRequestWithConstraints,
|
||||||
) -> errors::CustomerResponse<customers::CustomerListResponse> {
|
) -> errors::CustomerResponse<customers::CustomerListResponse> {
|
||||||
let db = state.store.as_ref();
|
let db = state.store.as_ref();
|
||||||
|
let key_manager_state = &(&state).into();
|
||||||
|
|
||||||
let limit = utils::customer_validation::validate_customer_list_limit(request.limit)
|
let limit = utils::customer_validation::validate_customer_list_limit(request.limit)
|
||||||
.change_context(errors::CustomersErrorResponse::InvalidRequestData {
|
.change_context(errors::CustomersErrorResponse::InvalidRequestData {
|
||||||
message: format!(
|
message: format!(
|
||||||
@ -646,9 +663,9 @@ pub async fn list_customers_with_count(
|
|||||||
time_range: request.time_range,
|
time_range: request.time_range,
|
||||||
};
|
};
|
||||||
|
|
||||||
let domain_customers = db
|
let (domain_customers, total_count) = db
|
||||||
.list_customers_by_merchant_id_with_count(
|
.list_customers_by_merchant_id_with_count(
|
||||||
&(&state).into(),
|
key_manager_state,
|
||||||
&merchant_id,
|
&merchant_id,
|
||||||
&key_store,
|
&key_store,
|
||||||
customer_list_constraints,
|
customer_list_constraints,
|
||||||
@ -657,15 +674,27 @@ pub async fn list_customers_with_count(
|
|||||||
.switch()?;
|
.switch()?;
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
let customers: Vec<customers::CustomerResponse> = domain_customers
|
let customers = {
|
||||||
.0
|
let mut customers = Vec::with_capacity(domain_customers.len());
|
||||||
.into_iter()
|
for domain_customer in domain_customers {
|
||||||
.map(|domain_customer| customers::CustomerResponse::foreign_from((domain_customer, None)))
|
let address = match &domain_customer.address_id {
|
||||||
.collect();
|
Some(address_id) => Some(api_models::payments::AddressDetails::from(
|
||||||
|
db.find_address_by_address_id(key_manager_state, address_id, &key_store)
|
||||||
|
.await
|
||||||
|
.switch()?,
|
||||||
|
)),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
customers.push(customers::CustomerResponse::foreign_from((
|
||||||
|
domain_customer,
|
||||||
|
address,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
customers
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
let customers: Vec<customers::CustomerResponse> = domain_customers
|
let customers: Vec<customers::CustomerResponse> = domain_customers
|
||||||
.0
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(customers::CustomerResponse::foreign_from)
|
.map(customers::CustomerResponse::foreign_from)
|
||||||
.collect();
|
.collect();
|
||||||
@ -673,7 +702,7 @@ pub async fn list_customers_with_count(
|
|||||||
Ok(services::ApplicationResponse::Json(
|
Ok(services::ApplicationResponse::Json(
|
||||||
customers::CustomerListResponse {
|
customers::CustomerListResponse {
|
||||||
data: customers.into_iter().map(|c| c.0).collect(),
|
data: customers.into_iter().map(|c| c.0).collect(),
|
||||||
total_count: domain_customers.1,
|
total_count,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user