|
| 1 | +//! Gateway status mapping |
| 2 | +
|
| 3 | +use common_utils::custom_serde; |
| 4 | +use diesel::{AsChangeset, Identifiable, Insertable, Queryable}; |
| 5 | +use time::PrimitiveDateTime; |
| 6 | + |
| 7 | +use crate::schema::gateway_status_map; |
| 8 | + |
| 9 | +#[derive( |
| 10 | + Clone, |
| 11 | + Debug, |
| 12 | + Eq, |
| 13 | + PartialEq, |
| 14 | + router_derive::DebugAsDisplay, |
| 15 | + Identifiable, |
| 16 | + Queryable, |
| 17 | + serde::Serialize, |
| 18 | +)] |
| 19 | +#[diesel(table_name = gateway_status_map, primary_key(connector, flow, sub_flow, code, message))] |
| 20 | +pub struct GatewayStatusMap { |
| 21 | + pub connector: String, |
| 22 | + pub flow: String, |
| 23 | + pub sub_flow: String, |
| 24 | + pub code: String, |
| 25 | + pub message: String, |
| 26 | + pub status: String, |
| 27 | + pub router_error: Option<String>, |
| 28 | + pub decision: String, |
| 29 | + #[serde(with = "custom_serde::iso8601")] |
| 30 | + pub created_at: PrimitiveDateTime, |
| 31 | + #[serde(with = "custom_serde::iso8601")] |
| 32 | + pub last_modified: PrimitiveDateTime, |
| 33 | + pub step_up_possible: bool, |
| 34 | +} |
| 35 | + |
| 36 | +#[derive(Clone, Debug, Eq, PartialEq, Insertable)] |
| 37 | +#[diesel(table_name = gateway_status_map)] |
| 38 | +pub struct GatewayStatusMappingNew { |
| 39 | + pub connector: String, |
| 40 | + pub flow: String, |
| 41 | + pub sub_flow: String, |
| 42 | + pub code: String, |
| 43 | + pub message: String, |
| 44 | + pub status: String, |
| 45 | + pub router_error: Option<String>, |
| 46 | + pub decision: String, |
| 47 | + pub step_up_possible: bool, |
| 48 | +} |
| 49 | + |
| 50 | +#[derive( |
| 51 | + Clone, |
| 52 | + Debug, |
| 53 | + PartialEq, |
| 54 | + Eq, |
| 55 | + AsChangeset, |
| 56 | + router_derive::DebugAsDisplay, |
| 57 | + Default, |
| 58 | + serde::Deserialize, |
| 59 | +)] |
| 60 | +#[diesel(table_name = gateway_status_map)] |
| 61 | +pub struct GatewayStatusMapperUpdateInternal { |
| 62 | + pub connector: Option<String>, |
| 63 | + pub flow: Option<String>, |
| 64 | + pub sub_flow: Option<String>, |
| 65 | + pub code: Option<String>, |
| 66 | + pub message: Option<String>, |
| 67 | + pub status: Option<String>, |
| 68 | + pub router_error: Option<Option<String>>, |
| 69 | + pub decision: Option<String>, |
| 70 | + pub step_up_possible: Option<bool>, |
| 71 | +} |
| 72 | + |
| 73 | +#[derive(Debug)] |
| 74 | +pub struct GatewayStatusMappingUpdate { |
| 75 | + pub status: Option<String>, |
| 76 | + pub router_error: Option<Option<String>>, |
| 77 | + pub decision: Option<String>, |
| 78 | + pub step_up_possible: Option<bool>, |
| 79 | +} |
| 80 | + |
| 81 | +impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal { |
| 82 | + fn from(value: GatewayStatusMappingUpdate) -> Self { |
| 83 | + let GatewayStatusMappingUpdate { |
| 84 | + decision, |
| 85 | + status, |
| 86 | + router_error, |
| 87 | + step_up_possible, |
| 88 | + } = value; |
| 89 | + Self { |
| 90 | + status, |
| 91 | + router_error, |
| 92 | + decision, |
| 93 | + step_up_possible, |
| 94 | + ..Default::default() |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments