Feat(Customer): Added search Feature to the Customer Page (#9619)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sandeep Kumar <83278309+tsdk02@users.noreply.github.com>
This commit is contained in:
Venu Madhav Bandarupalli
2025-10-03 14:59:49 +05:30
committed by GitHub
parent c611b81455
commit e186a0f4f4
5 changed files with 62 additions and 8 deletions

View File

@ -52,6 +52,8 @@ pub struct CustomerListRequest {
/// Limit
#[schema(example = 32)]
pub limit: Option<u16>,
/// Unique identifier for a customer
pub customer_id: Option<id_type::CustomerId>,
}
#[cfg(feature = "v1")]

View File

@ -20,6 +20,7 @@ impl CustomerNew {
pub struct CustomerListConstraints {
pub limit: i64,
pub offset: Option<i64>,
pub customer_id: Option<id_type::CustomerId>,
}
impl Customer {
@ -54,19 +55,66 @@ impl Customer {
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(conn, id.to_owned()).await
}
#[cfg(feature = "v1")]
pub async fn list_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &id_type::MerchantId,
constraints: CustomerListConstraints,
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
if let Some(customer_id) = constraints.customer_id {
let predicate = dsl::merchant_id
.eq(merchant_id.clone())
.and(dsl::customer_id.eq(customer_id));
generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()),
predicate,
Some(constraints.limit),
constraints.offset,
Some(dsl::created_at),
)
.await
} else {
let predicate = dsl::merchant_id.eq(merchant_id.clone());
generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
conn,
predicate,
Some(constraints.limit),
constraints.offset,
Some(dsl::created_at),
)
.await
}
}
#[cfg(feature = "v2")]
pub async fn list_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &id_type::MerchantId,
constraints: CustomerListConstraints,
) -> StorageResult<Vec<Self>> {
if let Some(customer_id) = constraints.customer_id {
let predicate = dsl::merchant_id
.eq(merchant_id.clone())
.and(dsl::merchant_reference_id.eq(customer_id));
generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
conn,
predicate,
Some(constraints.limit),
constraints.offset,
Some(dsl::created_at),
)
.await
} else {
let predicate = dsl::merchant_id.eq(merchant_id.clone());
generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
conn,
predicate,
Some(constraints.limit),
constraints.offset,
Some(dsl::created_at),
)
.await
}
}
#[cfg(feature = "v2")]

View File

@ -538,6 +538,7 @@ impl From<CustomerUpdate> for CustomerUpdateInternal {
pub struct CustomerListConstraints {
pub limit: u16,
pub offset: Option<u32>,
pub customer_id: Option<id_type::CustomerId>,
}
impl From<CustomerListConstraints> for query::CustomerListConstraints {
@ -545,6 +546,7 @@ impl From<CustomerListConstraints> for query::CustomerListConstraints {
Self {
limit: i64::from(value.limit),
offset: value.offset.map(i64::from),
customer_id: value.customer_id,
}
}
}

View File

@ -590,6 +590,7 @@ pub async fn list_customers(
.limit
.unwrap_or(crate::consts::DEFAULT_LIST_API_LIMIT),
offset: request.offset,
customer_id: request.customer_id,
};
let domain_customers = db

View File

@ -54,6 +54,7 @@ pub async fn rust_locker_migration(
let constraints = CustomerListConstraints {
limit: u16::MAX,
offset: None,
customer_id: None,
};
let domain_customers = db