feat(customers): add time range filtering and count functionality to customer list endpoints#9767
feat(customers): add time range filtering and count functionality to customer list endpoints#9767likhinbopanna merged 26 commits intomainfrom
Conversation
…customer list endpoints
crates/api_models/src/customers.rs
Outdated
| /// List of customers | ||
| pub data: Vec<CustomerResponse>, | ||
| /// Total count of customers | ||
| pub count: usize, |
There was a problem hiding this comment.
can we call it total_count? count can be the size of data list like we have in other apis.
|
|
||
| impl ApiEventMetric for CustomerListResponse { | ||
| fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
| None |
| AER::InternalServerError(ApiError::new("HE", 0, "Something went wrong", None)) | ||
| } | ||
| Self::InvalidRequestData { message } => { | ||
| AER::BadRequest(ApiError::new("IR", 400, message, None)) |
There was a problem hiding this comment.
pass appropriate values as per this doc. https://api-reference.hyperswitch.io/essentials/error_codes
Also pass some meaningful error message
| pub const CUSTOMER_LIST_UPPER_LIMIT: u16 = 100; | ||
| pub const CUSTOMER_LIST_DEFAULT_LIMIT: u16 = 10; | ||
|
|
||
| pub fn validate_customer_list_limit( |
There was a problem hiding this comment.
can have a domain wrapper type for u16. Which can only exist if the value is within 1 and 100. And 10 as default trait impl.
refer to https://github.com/juspay/hyperswitch/blob/main/crates/common_types/src/primitive_wrappers.rs
| pub async fn list_customers_with_count( | ||
| state: SessionState, | ||
| merchant_id: id_type::MerchantId, | ||
| _profile_id_list: Option<Vec<id_type::ProfileId>>, |
There was a problem hiding this comment.
This can be removed if not used
|
Also start_time and end_time is not very descriptive. created_lt, created_lte created_gt would be nice. |
crates/router/src/core/customers.rs
Outdated
| customer_id: None, | ||
| time_range: None, | ||
| }; |
There was a problem hiding this comment.
Why this is changed to None?
crates/router/src/core/customers.rs
Outdated
| ) -> errors::CustomerResponse<customers::CustomerListResponse> { | ||
| let db = state.store.as_ref(); | ||
| let limit = | ||
| crate::core::utils::customer_validation::validate_customer_list_limit(request.limit) |
There was a problem hiding this comment.
Nitpick*: Instead of bid qualification paths, we can import some part always, and then qualify it as utils::something, and this can be done at most of the places.
hrithikesh026
left a comment
There was a problem hiding this comment.
Please Generate Openapi spec for the new api. If not here, then in a separate PR.
…customer list endpoints (#9767) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
…customer list endpoints (juspay#9767) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
…customer list endpoints (#9767) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Type of Change
Description
Additional Changes
Motivation and Context
This change enhances the customer list endpoints by adding time range filtering and count functionality. Previously, the API did not allow merchants to filter customers by their creation date, making it difficult to fetch customers within a specific time window.
Additionally, the count functionality enables accurate pagination on the client side by returning the total number of filtered customers along with the list.
Together, these improvements make the customer list API more flexible, efficient, and suitable for large datasets, improving the overall user experience for merchants.
How did you test it?
{ "data": [ { "customer_id": "cus_123", "name": "venu 12", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:06.395Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null }, { "customer_id": "cus_124", "name": "venu 13", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:11.296Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null }, { "customer_id": "cus_123125", "name": "venu 14", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:16.067Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null } ], "count": 22 }{ "data": [ { "customer_id": "cus_123", "name": "venu 12", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:06.395Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null }, { "customer_id": "cus_124", "name": "venu 13", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:11.296Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null }, { "customer_id": "cus_123125", "name": "venu 14", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:16.067Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null } ], "count": 22 }{ "data": [ { "customer_id": "cus_123", "name": "venu 12", "email": "guest@example.com", "phone": "999999999", "phone_country_code": "+65", "description": "First customer", "address": null, "created_at": "2025-10-08T08:10:06.395Z", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "default_payment_method_id": null, "tax_registration_id": null } ], "count": 22 }Checklist
cargo +nightly fmt --allcargo clippy