-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): add
gateway_status_map
interface (#2804)
- Loading branch information
1 parent
7623ea9
commit a429b23
Showing
11 changed files
with
436 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//! Gateway status mapping | ||
use common_utils::custom_serde; | ||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable}; | ||
use time::PrimitiveDateTime; | ||
|
||
use crate::schema::gateway_status_map; | ||
|
||
#[derive( | ||
Clone, | ||
Debug, | ||
Eq, | ||
PartialEq, | ||
router_derive::DebugAsDisplay, | ||
Identifiable, | ||
Queryable, | ||
serde::Serialize, | ||
)] | ||
#[diesel(table_name = gateway_status_map, primary_key(connector, flow, sub_flow, code, message))] | ||
pub struct GatewayStatusMap { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: String, | ||
pub router_error: Option<String>, | ||
pub decision: String, | ||
#[serde(with = "custom_serde::iso8601")] | ||
pub created_at: PrimitiveDateTime, | ||
#[serde(with = "custom_serde::iso8601")] | ||
pub last_modified: PrimitiveDateTime, | ||
pub step_up_possible: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Insertable)] | ||
#[diesel(table_name = gateway_status_map)] | ||
pub struct GatewayStatusMappingNew { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: String, | ||
pub router_error: Option<String>, | ||
pub decision: String, | ||
pub step_up_possible: bool, | ||
} | ||
|
||
#[derive( | ||
Clone, | ||
Debug, | ||
PartialEq, | ||
Eq, | ||
AsChangeset, | ||
router_derive::DebugAsDisplay, | ||
Default, | ||
serde::Deserialize, | ||
)] | ||
#[diesel(table_name = gateway_status_map)] | ||
pub struct GatewayStatusMapperUpdateInternal { | ||
pub connector: Option<String>, | ||
pub flow: Option<String>, | ||
pub sub_flow: Option<String>, | ||
pub code: Option<String>, | ||
pub message: Option<String>, | ||
pub status: Option<String>, | ||
pub router_error: Option<Option<String>>, | ||
pub decision: Option<String>, | ||
pub step_up_possible: Option<bool>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct GatewayStatusMappingUpdate { | ||
pub status: Option<String>, | ||
pub router_error: Option<Option<String>>, | ||
pub decision: Option<String>, | ||
pub step_up_possible: Option<bool>, | ||
} | ||
|
||
impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal { | ||
fn from(value: GatewayStatusMappingUpdate) -> Self { | ||
let GatewayStatusMappingUpdate { | ||
decision, | ||
status, | ||
router_error, | ||
step_up_possible, | ||
} = value; | ||
Self { | ||
status, | ||
router_error, | ||
decision, | ||
step_up_possible, | ||
..Default::default() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods}; | ||
use error_stack::report; | ||
|
||
use crate::{ | ||
errors, gsm::*, query::generics, schema::gateway_status_map::dsl, PgPooledConn, StorageResult, | ||
}; | ||
|
||
impl GatewayStatusMappingNew { | ||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<GatewayStatusMap> { | ||
generics::generic_insert(conn, self).await | ||
} | ||
} | ||
|
||
impl GatewayStatusMap { | ||
pub async fn find( | ||
conn: &PgPooledConn, | ||
connector: String, | ||
flow: String, | ||
sub_flow: String, | ||
code: String, | ||
message: String, | ||
) -> StorageResult<Self> { | ||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>( | ||
conn, | ||
dsl::connector | ||
.eq(connector) | ||
.and(dsl::flow.eq(flow)) | ||
.and(dsl::sub_flow.eq(sub_flow)) | ||
.and(dsl::code.eq(code)) | ||
.and(dsl::message.eq(message)), | ||
) | ||
.await | ||
} | ||
|
||
pub async fn retrieve_decision( | ||
conn: &PgPooledConn, | ||
connector: String, | ||
flow: String, | ||
sub_flow: String, | ||
code: String, | ||
message: String, | ||
) -> StorageResult<String> { | ||
Self::find(conn, connector, flow, sub_flow, code, message) | ||
.await | ||
.map(|item| item.decision) | ||
} | ||
|
||
pub async fn update( | ||
conn: &PgPooledConn, | ||
connector: String, | ||
flow: String, | ||
sub_flow: String, | ||
code: String, | ||
message: String, | ||
gsm: GatewayStatusMappingUpdate, | ||
) -> StorageResult<Self> { | ||
generics::generic_update_with_results::< | ||
<Self as HasTable>::Table, | ||
GatewayStatusMapperUpdateInternal, | ||
_, | ||
_, | ||
>( | ||
conn, | ||
dsl::connector | ||
.eq(connector) | ||
.and(dsl::flow.eq(flow)) | ||
.and(dsl::sub_flow.eq(sub_flow)) | ||
.and(dsl::code.eq(code)) | ||
.and(dsl::message.eq(message)), | ||
gsm.into(), | ||
) | ||
.await? | ||
.first() | ||
.cloned() | ||
.ok_or_else(|| { | ||
report!(errors::DatabaseError::NotFound) | ||
.attach_printable("Error while updating gsm entry") | ||
}) | ||
} | ||
|
||
pub async fn delete( | ||
conn: &PgPooledConn, | ||
connector: String, | ||
flow: String, | ||
sub_flow: String, | ||
code: String, | ||
message: String, | ||
) -> StorageResult<bool> { | ||
generics::generic_delete::<<Self as HasTable>::Table, _>( | ||
conn, | ||
dsl::connector | ||
.eq(connector) | ||
.and(dsl::flow.eq(flow)) | ||
.and(dsl::sub_flow.eq(sub_flow)) | ||
.and(dsl::code.eq(code)) | ||
.and(dsl::message.eq(message)), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.