|
1 | 1 | use std::fmt::Debug;
|
2 | 2 |
|
| 3 | +use common_utils::events::ApiEventMetric; |
3 | 4 | use utoipa::ToSchema;
|
4 | 5 |
|
| 6 | +use crate::enums; |
| 7 | + |
5 | 8 | #[derive(serde::Deserialize, ToSchema)]
|
6 | 9 | pub struct CardsInfoRequestParams {
|
7 | 10 | #[schema(example = "pay_OSERgeV9qAy7tlK7aKpc_secret_TuDUoh11Msxh12sXn3Yp")]
|
@@ -29,3 +32,97 @@ pub struct CardInfoResponse {
|
29 | 32 | #[schema(example = "INDIA")]
|
30 | 33 | pub card_issuing_country: Option<String>,
|
31 | 34 | }
|
| 35 | + |
| 36 | +#[derive(serde::Serialize, Debug, ToSchema)] |
| 37 | +pub struct CardInfoMigrateResponseRecord { |
| 38 | + pub card_iin: Option<String>, |
| 39 | + pub card_issuer: Option<String>, |
| 40 | + pub card_network: Option<String>, |
| 41 | + pub card_type: Option<String>, |
| 42 | + pub card_sub_type: Option<String>, |
| 43 | + pub card_issuing_country: Option<String>, |
| 44 | +} |
| 45 | + |
| 46 | +#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)] |
| 47 | +pub struct CardInfoCreateRequest { |
| 48 | + pub card_iin: String, |
| 49 | + pub card_issuer: Option<String>, |
| 50 | + pub card_network: Option<enums::CardNetwork>, |
| 51 | + pub card_type: Option<String>, |
| 52 | + pub card_subtype: Option<String>, |
| 53 | + pub card_issuing_country: Option<String>, |
| 54 | + pub bank_code_id: Option<String>, |
| 55 | + pub bank_code: Option<String>, |
| 56 | + pub country_code: Option<String>, |
| 57 | + pub last_updated_provider: Option<String>, |
| 58 | +} |
| 59 | + |
| 60 | +impl ApiEventMetric for CardInfoCreateRequest {} |
| 61 | + |
| 62 | +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)] |
| 63 | +pub struct CardInfoUpdateRequest { |
| 64 | + pub card_iin: String, |
| 65 | + pub card_issuer: Option<String>, |
| 66 | + pub card_network: Option<enums::CardNetwork>, |
| 67 | + pub card_type: Option<String>, |
| 68 | + pub card_subtype: Option<String>, |
| 69 | + pub card_issuing_country: Option<String>, |
| 70 | + pub bank_code_id: Option<String>, |
| 71 | + pub bank_code: Option<String>, |
| 72 | + pub country_code: Option<String>, |
| 73 | + pub last_updated_provider: Option<String>, |
| 74 | + pub line_number: Option<i64>, |
| 75 | +} |
| 76 | + |
| 77 | +impl ApiEventMetric for CardInfoUpdateRequest {} |
| 78 | + |
| 79 | +#[derive(Debug, Default, serde::Serialize)] |
| 80 | +pub enum CardInfoMigrationStatus { |
| 81 | + Success, |
| 82 | + #[default] |
| 83 | + Failed, |
| 84 | +} |
| 85 | +#[derive(Debug, Default, serde::Serialize)] |
| 86 | +pub struct CardInfoMigrationResponse { |
| 87 | + pub line_number: Option<i64>, |
| 88 | + pub card_iin: String, |
| 89 | + pub card_issuer: Option<String>, |
| 90 | + pub card_network: Option<String>, |
| 91 | + pub card_type: Option<String>, |
| 92 | + pub card_sub_type: Option<String>, |
| 93 | + pub card_issuing_country: Option<String>, |
| 94 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 95 | + pub migration_error: Option<String>, |
| 96 | + pub migration_status: CardInfoMigrationStatus, |
| 97 | +} |
| 98 | +impl ApiEventMetric for CardInfoMigrationResponse {} |
| 99 | + |
| 100 | +type CardInfoMigrationResponseType = ( |
| 101 | + Result<CardInfoMigrateResponseRecord, String>, |
| 102 | + CardInfoUpdateRequest, |
| 103 | +); |
| 104 | + |
| 105 | +impl From<CardInfoMigrationResponseType> for CardInfoMigrationResponse { |
| 106 | + fn from((response, record): CardInfoMigrationResponseType) -> Self { |
| 107 | + match response { |
| 108 | + Ok(res) => Self { |
| 109 | + card_iin: record.card_iin, |
| 110 | + line_number: record.line_number, |
| 111 | + card_issuer: res.card_issuer, |
| 112 | + card_network: res.card_network, |
| 113 | + card_type: res.card_type, |
| 114 | + card_sub_type: res.card_sub_type, |
| 115 | + card_issuing_country: res.card_issuing_country, |
| 116 | + migration_status: CardInfoMigrationStatus::Success, |
| 117 | + migration_error: None, |
| 118 | + }, |
| 119 | + Err(e) => Self { |
| 120 | + card_iin: record.card_iin, |
| 121 | + migration_status: CardInfoMigrationStatus::Failed, |
| 122 | + migration_error: Some(e), |
| 123 | + line_number: record.line_number, |
| 124 | + ..Self::default() |
| 125 | + }, |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments