Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(card_issuer): List all card issuers (#14349)

Ayush Anandcf950989146a
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index eccc7bff21..b8a6a0464b 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -10631,32 +10631,8 @@
"Card Issuer"
],
"summary": "Card Issuer - List",
- "description": "Lists card issuers with optional search filter",
+ "description": "Lists all card issuers",
"operationId": "List Card Issuers",
- "parameters": [
- {
- "name": "query",
- "in": "query",
- "description": "Optional search term to filter issuers by name",
- "required": false,
- "schema": {
- "type": "string",
- "nullable": true
- }
- },
- {
- "name": "limit",
- "in": "query",
- "description": "Maximum number of results to return",
- "required": false,
- "schema": {
- "type": "integer",
- "format": "int32",
- "nullable": true,
- "minimum": 0
- }
- }
- ],
"responses": {
"200": {
"description": "Card issuers listed",
@@ -18425,26 +18401,6 @@
}
}
},
- "CardIssuerListQuery": {
- "type": "object",
- "properties": {
- "query": {
- "type": "string",
- "description": "Optional search term to filter issuers by name (case-insensitive prefix match)",
- "example": "hdfc",
- "nullable": true
- },
- "limit": {
- "type": "integer",
- "format": "int32",
- "description": "Maximum number of results to return (default: 30, max: 255)",
- "default": 30,
- "example": 30,
- "maximum": 255,
- "minimum": 0
- }
- }
- },
"CardIssuerListResponse": {
"type": "object",
"required": [
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 39c601e2b7..f492c42c70 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2688,6 +2688,7 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen
"payments.should_enable_mit_with_limited_card_data" = { value = false, schema = { type = "boolean" }, description = "Whether to allow merchant-initiated transactions (MIT) with limited card data", change_reason = "Initial setup" }
"payments.should_perform_eligibility" = { value = false, schema = { type = "boolean" }, description = "Whether the SDK should perform an eligibility check before confirming payment", change_reason = "Initial setup" }
"payments.should_return_raw_payment_method_details" = { value = false, schema = { type = "boolean" }, description = "Whether to return raw payment method details (v2 only)", change_reason = "Initial setup" }
+"card_issuer.list_max_limit" = { value = 18000, schema = { maximum = 4294967295, minimum = 0, type = "integer" }, description = "Maximum number of card issuers the card issuer list endpoint reads", change_reason = "Initial setup" }
"payments.network_token_fetch_timeout_in_secs" = { value = 4, schema = { maximum = 4294967295, minimum = 0, type = "integer" }, description = "Timeout in seconds for network token fetch", change_reason = "Initial setup" }
should_schedule_modular_backward_compat = { value = false, schema = { type = "boolean" }, description = "Whether to schedule PM modular backward compatibility PT for a provider merchant, with organization fallback", change_reason = "Initial setup" }
"system.should_schedule_modular_forward_compat" = { value = false, schema = { type = "boolean" }, description = "Whether to schedule PM modular forward compatibility PT for a provider merchant, with organization fallback", change_reason = "Initial setup" }
diff --git a/crates/api_models/src/card_issuer.rs b/crates/api_models/src/card_issuer.rs
index 66cf9248fc..2cca9576fd 100644
--- a/crates/api_models/src/card_issuer.rs
+++ b/crates/api_models/src/card_issuer.rs
@@ -16,21 +16,6 @@ pub struct CardIssuerResponse {
pub issuer_name: CardIssuerName,
}
-#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
-pub struct CardIssuerListQuery {
- /// Optional search term to filter issuers by name (case-insensitive prefix match)
- #[schema(example = "hdfc")]
- pub query: Option<String>,
- /// Maximum number of results to return (default: 30, max: 255)
- #[schema(example = 30, default = 30, maximum = 255, value_type = u8)]
- #[serde(default = "default_card_issuer_list_limit")]
- pub limit: u8,
-}
-
-fn default_card_issuer_list_limit() -> u8 {
- common_utils::consts::DEFAULT_CARD_ISSUER_LIST_LIMIT
-}
-
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CardIssuerListResponse {
pub issuers: Vec<CardIssuerResponse>,
@@ -86,8 +71,3 @@ impl ApiEventMetric for CardIssuerListResponse {
Some(common_utils::events::ApiEventsType::CardIssuers)
}
}
-impl ApiEventMetric for CardIssuerListQuery {
- fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
- Some(common_utils::events::ApiEventsType::CardIssuers)
- }
-}
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index 56b76b6b7e..128ff46ff4 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -277,8 +277,5 @@ pub const REQUEST_TIME_OUT: u64 = 30;
/// API client request timeout for ai service (in seconds)
pub const REQUEST_TIME_OUT_FOR_AI_SERVICE: u64 = 120;
-/// Default number of card issuers returned in a list request
-pub const DEFAULT_CARD_ISSUER_LIST_LIMIT: u8 = 30;
-
/// Length of a generated card issuer ID
pub const CARD_ISSUER_ID_LENGTH: u8 = 5;
diff --git a/crates/diesel_models/src/card_issuer.rs b/crates/diesel_models/src/card_issuer.rs
index 24adf2999f..bb870c374f 100644
--- a/crates/diesel_models/src/card_issuer.rs
+++ b/crates/diesel_models/src/card_issuer.rs
@@ -15,6 +15,12 @@ pub struct CardIssuer {
pub last_modified_at: PrimitiveDateTime,
}
+#[derive(Clone, Debug, Queryable, serde::Serialize, serde::Deserialize)]
+pub struct CardIssuerListItem {
+ pub id: id_type::CardIssuerId,
+ pub issuer_name: String,
+}
+
#[derive(Clone, Debug, AsChangeset, serde::Serialize, serde::Deserialize)]
#[diesel(table_name = card_issuers)]
pub struct UpdateCardIssuer {
diff --git a/crates/diesel_models/src/query/card_issuer.rs b/crates/diesel_models/src/query/card_issuer.rs
index e7c43b8c36..4ef89b243a 100644
--- a/crates/diesel_models/src/query/card_issuer.rs
+++ b/crates/diesel_models/src/query/card_issuer.rs
@@ -1,28 +1,38 @@
+use async_bb8_diesel::AsyncRunQueryDsl;
use common_utils::id_type;
-use diesel::{associations::HasTable, ExpressionMethods, PgTextExpressionMethods};
+use diesel::{associations::HasTable, ExpressionMethods, QueryDsl};
+use error_stack::ResultExt;
-use super::generics;
+use super::{
+ generics,
+ generics::db_metrics::{track_database_call, DatabaseOperation},
+};
use crate::{
- card_issuer::{CardIssuer, NewCardIssuer, UpdateCardIssuer},
+ card_issuer::{CardIssuer, CardIssuerListItem, NewCardIssuer, UpdateCardIssuer},
+ errors,
schema::card_issuers::dsl,
DatabaseConnectionWithContext, StorageResult,
};
impl CardIssuer {
- pub async fn list_filtered(
+ pub async fn list_all(
conn: &DatabaseConnectionWithContext<'_>,
- query: Option<String>,
- limit: Option<i64>,
- ) -> StorageResult<Vec<Self>> {
- let pattern = query.map_or("%".to_string(), |q| format!("{}%", q));
- generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
- conn,
- dsl::issuer_name.ilike(pattern),
- limit,
- None,
- Some(dsl::issuer_name.asc()),
+ limit: i64,
+ ) -> StorageResult<Vec<CardIssuerListItem>> {
+ let query =
+ crate::list::into_boxed_list(<Self as HasTable>::table().order(dsl::issuer_name.asc()))
+ .select((dsl::id, dsl::issuer_name))
+ .limit(limit);
+
+ track_database_call::<Self, _, _>(
+ conn.request_id(),
+ conn.event_emitter(),
+ DatabaseOperation::Filter,
+ query.get_results_async::<CardIssuerListItem>(conn.raw_connection()),
)
.await
+ .change_context(errors::DatabaseError::Others)
+ .attach_printable("Error while listing card issuers")
}
pub async fn find_by_ids(
diff --git a/crates/hyperswitch_domain_models/src/card_issuer.rs b/crates/hyperswitch_domain_models/src/card_issuer.rs
index 082e95df99..57ae6581dd 100644
--- a/crates/hyperswitch_domain_models/src/card_issuer.rs
+++ b/crates/hyperswitch_domain_models/src/card_issuer.rs
@@ -22,9 +22,8 @@ pub trait CardIssuersInterface {
async fn list_card_issuers(
&self,
- query: Option<String>,
- limit: Option<u8>,
- ) -> errors::CustomResult<Vec<card_issuer::CardIssuer>, Self::Error>;
+ limit: i64,
+ ) -> errors::CustomResult<Vec<card_issuer::CardIssuerListItem>, Self::Error>;
async fn get_card_issuers_by_ids(
&self,
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 572cb5d3ef..58b556bb62 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -577,7 +577,6 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::card_issuer::CardIssuerResponse,
api_models::card_issuer::CardIssuerUpdateRequest,
api_models::card_issuer::CardIssuerDeleteResponse,
- api_models::card_issuer::CardIssuerListQuery,
api_models::card_issuer::CardIssuerListResponse,
api_models::gsm::GsmCreateRequest,
api_models::gsm::GsmRetrieveRequest,
diff --git a/crates/openapi/src/routes/card_issuer.rs b/crates/openapi/src/routes/card_issuer.rs
index d54b72b92f..a32bf89711 100644
--- a/crates/openapi/src/routes/card_issuer.rs
+++ b/crates/openapi/src/routes/card_issuer.rs
@@ -62,14 +62,10 @@ pub async fn delete_card_issuer() {}
/// Card Issuer - List
///
-/// Lists card issuers with optional search filter
+/// Lists all card issuers
#[utoipa::path(
get,
path = "/card_issuers",
- params(
- ("query" = Option<String>, Query, description = "Optional search term to filter issuers by name"),
- ("limit" = Option<u8>, Query, description = "Maximum number of results to return"),
- ),
responses(
(status = 200, description = "Card issuers listed", body = CardIssuerListResponse),
),
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 5265d3ef9d..033bd7d2b1 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -531,6 +531,8 @@ pub mod superposition {
pub const PRE_FRM_FAILURE_MODE: &str = "frm.pre_frm_failure_mode";
/// Payout FRM call configuration key
pub const PAYOUT_FRM_CALL: &str = "payouts.payout_frm_call";
+ /// Maximum number of card issuers a list request reads
+ pub const CARD_ISSUER_LIST_MAX_LIMIT: &str = "card_issuer.list_max_limit";
}
/// The value substituted for sensitive webhook header values in event retrieval responses.
diff --git a/crates/router/src/core/card_issuer.rs b/crates/router/src/core/card_issuer.rs
index 14c8ecaa74..d6da93aefc 100644
--- a/crates/router/src/core/card_issuer.rs
+++ b/crates/router/src/core/card_issuer.rs
@@ -1,10 +1,13 @@
use api_models::card_issuer as api_types;
use common_utils::{date_time, id_type};
use diesel_models::card_issuer::{NewCardIssuer, UpdateCardIssuer};
-use router_env::{instrument, tracing};
+use router_env::{instrument, logger, tracing};
use crate::{
- core::errors::{self, RouterResponse, StorageErrorExt},
+ core::{
+ configs::dimension_state,
+ errors::{self, RouterResponse, StorageErrorExt},
+ },
routes::SessionState,
services::ApplicationResponse,
types::transformers::ForeignTryInto,
@@ -81,14 +84,27 @@ pub async fn delete_card_issuer(
#[instrument(skip_all)]
pub async fn list_card_issuers(
state: SessionState,
- query: api_types::CardIssuerListQuery,
) -> RouterResponse<api_types::CardIssuerListResponse> {
+ let dimensions: dimension_state::DimensionsGlobal = dimension_state::Dimensions::new();
+ let limit = dimensions
+ .get_card_issuer_list_max_limit(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ None,
+ )
+ .await;
+
let issuers = state
.store
- .list_card_issuers(query.query, Some(query.limit))
+ .list_card_issuers(limit)
.await
.map_err(|error| error.change_context(errors::ApiErrorResponse::InternalServerError))?;
+ usize::try_from(limit)
+ .ok()
+ .filter(|max_count| issuers.len() >= *max_count)
+ .inspect(|_| logger::warn!(limit, "Card issuer list hit the configured limit"));
+
Ok(ApplicationResponse::Json(
api_types::CardIssuerListResponse {
issuers: issuers
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index 3ca35863e1..c709864daf 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -1047,3 +1047,15 @@ impl DatabaseBackedConfig for PayoutFrmCall {
.map(|id| format!("{}_{}", Self::KEY, id.get_string_repr()))
}
}
+
+config! {
+ superposition_key = CARD_ISSUER_LIST_MAX_LIMIT,
+ output = i64,
+ default = 18_000,
+ requires = dimension_state::DimensionsGlobal,
+ targeting_key = id_type::MerchantId
+}
+
+impl DatabaseBackedConfig for CardIssuerListMaxLimit {
+ const KEY: &'static str = "card_issuer_list_max_limit";
+}
diff --git a/crates/router/src/db/card_issuer.rs b/crates/router/src/db/card_issuer.rs
index 2135a5f535..51c1c51bf9 100644
--- a/crates/router/src/db/card_issuer.rs
+++ b/crates/router/src/db/card_issuer.rs
@@ -40,10 +40,9 @@ impl CardIssuersInterface for KafkaStore {
#[instrument(skip_all)]
async fn list_card_issuers(
&self,
- query: Option<String>,
- limit: Option<u8>,
- ) -> CustomResult<Vec<storage::CardIssuer>, errors::StorageError> {
- self.diesel_store.list_card_issuers(query, limit).await
+ limit: i64,
+ ) -> CustomResult<Vec<storage::CardIssuerListItem>, errors::StorageError> {
+ self.diesel_store.list_card_issuers(limit).await
}
#[instrument(skip_all)]
diff --git a/crates/router/src/routes/card_issuer.rs b/crates/router/src/routes/card_issuer.rs
index 38d2c2accb..45bd2b4246 100644
--- a/crates/router/src/routes/card_issuer.rs
+++ b/crates/router/src/routes/card_issuer.rs
@@ -74,19 +74,14 @@ pub async fn delete_card_issuer(
}
#[instrument(skip_all, fields(flow = ?Flow::ListCardIssuers))]
-pub async fn list_card_issuers(
- state: web::Data<AppState>,
- req: HttpRequest,
- query: web::Query<api_types::CardIssuerListQuery>,
-) -> HttpResponse {
+pub async fn list_card_issuers(state: web::Data<AppState>, req: HttpRequest) -> HttpResponse {
let flow = Flow::ListCardIssuers;
- let query = query.into_inner();
Box::pin(api::server_wrap(
flow,
state,
&req,
- query,
- |state, _, query, _| card_issuer::list_card_issuers(state, query),
+ (),
+ |state, _, _, _| card_issuer::list_card_issuers(state),
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
allow_connected_scope_operation: false,
diff --git a/crates/router/src/types/storage/card_issuer.rs b/crates/router/src/types/storage/card_issuer.rs
index a7b3d779c0..edecad0bf2 100644
--- a/crates/router/src/types/storage/card_issuer.rs
+++ b/crates/router/src/types/storage/card_issuer.rs
@@ -1 +1,3 @@
-pub use diesel_models::card_issuer::{CardIssuer, NewCardIssuer, UpdateCardIssuer};
+pub use diesel_models::card_issuer::{
+ CardIssuer, CardIssuerListItem, NewCardIssuer, UpdateCardIssuer,
+};
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 8bdea78b68..492a9de661 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -2911,6 +2911,22 @@ impl ForeignFrom<&revenue_recovery_redis_operation::PaymentProcessorTokenStatus>
}
}
+impl ForeignTryFrom<storage::CardIssuerListItem> for card_issuer_types::CardIssuerResponse {
+ type Error = error_stack::Report<errors::ApiErrorResponse>;
+
+ fn foreign_try_from(from: storage::CardIssuerListItem) -> Result<Self, Self::Error> {
+ let issuer_name = CardIssuerName::try_new(from.issuer_name).change_context(
+ errors::ApiErrorResponse::InvalidDataValue {
+ field_name: "issuer_name".into(),
+ },
+ )?;
+ Ok(Self {
+ id: from.id,
+ issuer_name,
+ })
+ }
+}
+
impl ForeignTryFrom<storage::CardIssuer> for card_issuer_types::CardIssuerResponse {
type Error = error_stack::Report<errors::ApiErrorResponse>;
diff --git a/crates/storage_impl/src/card_issuer.rs b/crates/storage_impl/src/card_issuer.rs
index a09bc80533..8f3a7fb5a2 100644
--- a/crates/storage_impl/src/card_issuer.rs
+++ b/crates/storage_impl/src/card_issuer.rs
@@ -1,5 +1,7 @@
use common_utils::id_type;
-pub use diesel_models::card_issuer::{CardIssuer, NewCardIssuer, UpdateCardIssuer};
+pub use diesel_models::card_issuer::{
+ CardIssuer, CardIssuerListItem, NewCardIssuer, UpdateCardIssuer,
+};
use error_stack::report;
use hyperswitch_domain_models::card_issuer::CardIssuersInterface;
use router_env::{instrument, tracing};
@@ -7,10 +9,13 @@ use router_env::{instrument, tracing};
use crate::{
errors::StorageError,
kv_router_store::KVRouterStore,
+ redis::cache::{self, CacheKind, CONFIG_CACHE},
utils::{pg_connection_read, pg_connection_write},
CustomResult, DatabaseStore, MockDb, RouterStore,
};
+const CARD_ISSUERS_LIST_CACHE_KEY: &str = "card_issuers_list";
+
#[async_trait::async_trait]
impl<T: DatabaseStore> CardIssuersInterface for RouterStore<T> {
type Error = StorageError;
@@ -20,10 +25,18 @@ impl<T: DatabaseStore> CardIssuersInterface for RouterStore<T> {
&self,
new: NewCardIssuer,
) -> CustomResult<CardIssuer, StorageError> {
- let conn = pg_connection_write(self).await?;
- new.insert(&conn)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ let insert_call = || async {
+ let conn = pg_connection_write(self).await?;
+ new.insert(&conn)
+ .await
+ .map_err(|error| report!(StorageError::from(error)))
+ };
+ cache::publish_and_redact(
+ self,
+ CacheKind::Config(CARD_ISSUERS_LIST_CACHE_KEY.into()),
+ insert_call,
+ )
+ .await
}
#[instrument(skip_all)]
@@ -32,10 +45,18 @@ impl<T: DatabaseStore> CardIssuersInterface for RouterStore<T> {
id: id_type::CardIssuerId,
update: UpdateCardIssuer,
) -> CustomResult<CardIssuer, StorageError> {
- let conn = pg_connection_write(self).await?;
- CardIssuer::update(&conn, id, update)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ let update_call = || async {
+ let conn = pg_connection_write(self).await?;
+ CardIssuer::update(&conn, id, update)
+ .await
+ .map_err(|error| report!(StorageError::from(error)))
+ };
+ cache::publish_and_redact(
+ self,
+ CacheKind::Config(CARD_ISSUERS_LIST_CACHE_KEY.into()),
+ update_call,
+ )
+ .await
}
#[instrument(skip_all)]
@@ -43,22 +64,38 @@ impl<T: DatabaseStore> CardIssuersInterface for RouterStore<T> {
&self,
id: id_type::CardIssuerId,
) -> CustomResult<bool, StorageError> {
- let conn = pg_connection_write(self).await?;
- CardIssuer::delete_by_id(&conn, id)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ let delete_call = || async {
+ let conn = pg_connection_write(self).await?;
+ CardIssuer::delete_by_id(&conn, id)
+ .await
+ .map_err(|error| report!(StorageError::from(error)))
+ };
+ cache::publish_and_redact(
+ self,
+ CacheKind::Config(CARD_ISSUERS_LIST_CACHE_KEY.into()),
+ delete_call,
+ )
+ .await
}
#[instrument(skip_all)]
async fn list_card_issuers(
&self,
- query: Option<String>,
- limit: Option<u8>,
- ) -> CustomResult<Vec<CardIssuer>, StorageError> {
- let conn = pg_connection_read(self).await?;
- CardIssuer::list_filtered(&conn, query, limit.map(i64::from))
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ limit: i64,
+ ) -> CustomResult<Vec<CardIssuerListItem>, StorageError> {
+ let fetch_func = || async {
+ let conn = pg_connection_read(self).await?;
+ CardIssuer::list_all(&conn, limit)
+ .await
+ .map_err(|error| report!(StorageError::from(error)))
+ };
+ cache::get_or_populate_in_memory(
+ self,
+ CARD_ISSUERS_LIST_CACHE_KEY,
+ fetch_func,
+ &CONFIG_CACHE,
+ )
+ .await
}
#[instrument(skip_all)]
@@ -82,10 +119,7 @@ impl<T: DatabaseStore> CardIssuersInterface for KVRouterStore<T> {
&self,
new: NewCardIssuer,
) -> CustomResult<CardIssuer, StorageError> {
- let conn = pg_connection_write(self).await?;
- new.insert(&conn)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ self.router_store.insert_card_issuer(new).await
}
#[instrument(skip_all)]
@@ -94,10 +128,7 @@ impl<T: DatabaseStore> CardIssuersInterface for KVRouterStore<T> {
id: id_type::CardIssuerId,
update: UpdateCardIssuer,
) -> CustomResult<CardIssuer, StorageError> {
- let conn = pg_connection_write(self).await?;
- CardIssuer::update(&conn, id, update)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ self.router_store.update_card_issuer(id, update).await
}
#[instrument(skip_all)]
@@ -105,22 +136,15 @@ impl<T: DatabaseStore> CardIssuersInterface for KVRouterStore<T> {
&self,
id: id_type::CardIssuerId,
) -> CustomResult<bool, StorageError> {
- let conn = pg_connection_write(self).await?;
- CardIssuer::delete_by_id(&conn, id)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ self.router_store.delete_card_issuer(id).await
}
#[instrument(skip_all)]
async fn list_card_issuers(
&self,
- query: Option<String>,
- limit: Option<u8>,
- ) -> CustomResult<Vec<CardIssuer>, StorageError> {
- let conn = pg_connection_read(self).await?;
- CardIssuer::list_filtered(&conn, query, limit.map(i64::from))
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ limit: i64,
+ ) -> CustomResult<Vec<CardIssuerListItem>, StorageError> {
+ self.router_store.list_card_issuers(limit).await
}
#[instrument(skip_all)]
@@ -128,10 +152,7 @@ impl<T: DatabaseStore> CardIssuersInterface for KVRouterStore<T> {
&self,
ids: Vec<id_type::CardIssuerId>,
) -> CustomResult<Vec<CardIssuer>, StorageError> {
- let conn = pg_connection_read(self).await?;
- CardIssuer::find_by_ids(&conn, ids)
- .await
- .map_err(|error| report!(StorageError::from(error)))
+ self.router_store.get_card_issuers_by_ids(ids).await
}
}
@@ -188,21 +209,21 @@ impl CardIssuersInterface for MockDb {
async fn list_card_issuers(
&self,
- query: Option<String>,
- limit: Option<u8>,
- ) -> CustomResult<Vec<CardIssuer>, StorageError> {
- let card_issuers = self.card_issuers.lock().await;
- let filtered: Vec<CardIssuer> = card_issuers
+ limit: i64,
+ ) -> CustomResult<Vec<CardIssuerListItem>, StorageError> {
+ let mut card_issuers_list = self
+ .card_issuers
+ .lock()
+ .await
.iter()
- .filter(|ci| {
- query
- .as_ref()
- .is_none_or(|q| ci.issuer_name.contains(q.as_str()))
+ .map(|card_issuer| CardIssuerListItem {
+ id: card_issuer.id.clone(),
+ issuer_name: card_issuer.issuer_name.clone(),
})
- .take(limit.map_or(usize::MAX, usize::from))
- .cloned()
- .collect();
- Ok(filtered)
+ .collect::<Vec<_>>();
+ card_issuers_list.sort_by(|a, b| a.issuer_name.cmp(&b.issuer_name));
+ card_issuers_list.truncate(usize::try_from(limit).unwrap_or(usize::MAX));
+ Ok(card_issuers_list)
}
async fn get_card_issuers_by_ids(
diff --git a/cypress-tests/cypress/e2e/spec/Misc/00002-CardIssuerManagement.cy.js b/cypress-tests/cypress/e2e/spec/Misc/00002-CardIssuerManagement.cy.js
index cde49e71f4..84492397b0 100644
--- a/cypress-tests/cypress/e2e/spec/Misc/00002-CardIssuerManagement.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Misc/00002-CardIssuerManagement.cy.js
@@ -35,7 +35,7 @@ describe("Card Issuer Management", () => {
});
it("should list card issuers", () => {
- cy.listCardIssuers("", 30, globalState);
+ cy.listCardIssuers(globalState);
});
it("should update an existing card issuer", () => {
@@ -46,11 +46,6 @@ describe("Card Issuer Management", () => {
globalState
);
});
-
- it("should list card issuers with query filter", () => {
- const query = "Updated";
- cy.listCardIssuers(query, 30, globalState);
- });
});
context("Negative Tests", () => {
@@ -66,12 +61,8 @@ describe("Card Issuer Management", () => {
});
context("Edge Case Tests", () => {
- it("should handle listing with limit of 1", () => {
- cy.listCardIssuers("", 1, globalState);
- });
-
it("should handle listing with empty query", () => {
- cy.listCardIssuers("", 50, globalState);
+ cy.listCardIssuers(globalState);
});
it("should fail to update non-existent issuer", () => {
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 4678c210c2..c5084dcf91 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -10357,17 +10357,13 @@ Cypress.Commands.add("createCardIssuer", (body, globalState) => {
});
});
-Cypress.Commands.add("listCardIssuers", (query, limit, globalState) => {
+Cypress.Commands.add("listCardIssuers", (globalState) => {
const apiKey = globalState.get("apiKey");
const baseUrl = globalState.get("baseUrl");
- const queryParams = [];
- if (query) queryParams.push(`query=${encodeURIComponent(query)}`);
- if (limit) queryParams.push(`limit=${limit}`);
- const queryString = queryParams.length > 0 ? `?${queryParams.join("&")}` : "";
cy.request({
method: "GET",
- url: `${baseUrl}/card_issuers${queryString}`,
+ url: `${baseUrl}/card_issuers`,
headers: {
"Content-Type": "application/json",
"api-key": apiKey,
@@ -10378,12 +10374,7 @@ Cypress.Commands.add("listCardIssuers", (query, limit, globalState) => {
cy.wrap(response).then(() => {
expect(response.status).to.equal(200);
- if (response.body.data) {
- expect(Array.isArray(response.body.data)).to.be.true;
- if (limit && response.body.data.length > 0) {
- expect(response.body.data.length).to.be.at.most(limit);
- }
- }
+ expect(Array.isArray(response.body.issuers)).to.be.true;
});
});
});