mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
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:
committed by
GitHub
parent
c611b81455
commit
e186a0f4f4
@ -52,6 +52,8 @@ pub struct CustomerListRequest {
|
|||||||
/// Limit
|
/// Limit
|
||||||
#[schema(example = 32)]
|
#[schema(example = 32)]
|
||||||
pub limit: Option<u16>,
|
pub limit: Option<u16>,
|
||||||
|
/// Unique identifier for a customer
|
||||||
|
pub customer_id: Option<id_type::CustomerId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
|
|||||||
@ -20,6 +20,7 @@ impl CustomerNew {
|
|||||||
pub struct CustomerListConstraints {
|
pub struct CustomerListConstraints {
|
||||||
pub limit: i64,
|
pub limit: i64,
|
||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
|
pub customer_id: Option<id_type::CustomerId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Customer {
|
impl Customer {
|
||||||
@ -54,19 +55,66 @@ impl Customer {
|
|||||||
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(conn, id.to_owned()).await
|
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(conn, id.to_owned()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "v1")]
|
||||||
pub async fn list_by_merchant_id(
|
pub async fn list_by_merchant_id(
|
||||||
conn: &PgPooledConn,
|
conn: &PgPooledConn,
|
||||||
merchant_id: &id_type::MerchantId,
|
merchant_id: &id_type::MerchantId,
|
||||||
constraints: CustomerListConstraints,
|
constraints: CustomerListConstraints,
|
||||||
) -> StorageResult<Vec<Self>> {
|
) -> 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,
|
conn,
|
||||||
dsl::merchant_id.eq(merchant_id.to_owned()),
|
predicate,
|
||||||
Some(constraints.limit),
|
Some(constraints.limit),
|
||||||
constraints.offset,
|
constraints.offset,
|
||||||
Some(dsl::created_at),
|
Some(dsl::created_at),
|
||||||
)
|
)
|
||||||
.await
|
.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")]
|
#[cfg(feature = "v2")]
|
||||||
|
|||||||
@ -538,6 +538,7 @@ impl From<CustomerUpdate> for CustomerUpdateInternal {
|
|||||||
pub struct CustomerListConstraints {
|
pub struct CustomerListConstraints {
|
||||||
pub limit: u16,
|
pub limit: u16,
|
||||||
pub offset: Option<u32>,
|
pub offset: Option<u32>,
|
||||||
|
pub customer_id: Option<id_type::CustomerId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CustomerListConstraints> for query::CustomerListConstraints {
|
impl From<CustomerListConstraints> for query::CustomerListConstraints {
|
||||||
@ -545,6 +546,7 @@ impl From<CustomerListConstraints> for query::CustomerListConstraints {
|
|||||||
Self {
|
Self {
|
||||||
limit: i64::from(value.limit),
|
limit: i64::from(value.limit),
|
||||||
offset: value.offset.map(i64::from),
|
offset: value.offset.map(i64::from),
|
||||||
|
customer_id: value.customer_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -590,6 +590,7 @@ pub async fn list_customers(
|
|||||||
.limit
|
.limit
|
||||||
.unwrap_or(crate::consts::DEFAULT_LIST_API_LIMIT),
|
.unwrap_or(crate::consts::DEFAULT_LIST_API_LIMIT),
|
||||||
offset: request.offset,
|
offset: request.offset,
|
||||||
|
customer_id: request.customer_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let domain_customers = db
|
let domain_customers = db
|
||||||
|
|||||||
@ -54,6 +54,7 @@ pub async fn rust_locker_migration(
|
|||||||
let constraints = CustomerListConstraints {
|
let constraints = CustomerListConstraints {
|
||||||
limit: u16::MAX,
|
limit: u16::MAX,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
customer_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let domain_customers = db
|
let domain_customers = db
|
||||||
|
|||||||
Reference in New Issue
Block a user