-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(router): add gateway_status_map
CRUD APIs
#2809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d7ed4c5
add gsm interface
sai-harsha-vardhan 8093656
add gsm in storage
sai-harsha-vardhan 04764ba
add gsm crud apis
sai-harsha-vardhan 58fd445
fix cargo hack
sai-harsha-vardhan f702d89
Merge branch 'main' into add-gsm-core-apis
sai-harsha-vardhan 91e0944
Merge branch 'main' into add-gsm-core-apis
sai-harsha-vardhan 315bd1b
add apieventmetrics for gsm
sai-harsha-vardhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod customer; | ||
pub mod gsm; | ||
pub mod payment; | ||
#[cfg(feature = "payouts")] | ||
pub mod payouts; | ||
|
This file contains hidden or 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,33 @@ | ||
use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||
|
||
use crate::gsm; | ||
|
||
impl ApiEventMetric for gsm::GsmCreateRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmUpdateRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmRetrieveRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmDeleteRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmDeleteResponse { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} |
This file contains hidden or 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,75 @@ | ||
use crate::enums; | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmCreateRequest { | ||
pub connector: enums::Connector, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: String, | ||
pub router_error: Option<String>, | ||
pub decision: GsmDecision, | ||
pub step_up_possible: bool, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmRetrieveRequest { | ||
pub connector: enums::Connector, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
} | ||
|
||
#[derive( | ||
Default, | ||
Clone, | ||
Copy, | ||
Debug, | ||
strum::Display, | ||
PartialEq, | ||
Eq, | ||
serde::Serialize, | ||
serde::Deserialize, | ||
strum::EnumString, | ||
)] | ||
#[serde(rename_all = "snake_case")] | ||
#[strum(serialize_all = "snake_case")] | ||
pub enum GsmDecision { | ||
Retry, | ||
Requeue, | ||
#[default] | ||
DoDefault, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmUpdateRequest { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: Option<String>, | ||
pub router_error: Option<String>, | ||
pub decision: Option<GsmDecision>, | ||
pub step_up_possible: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmDeleteRequest { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
} | ||
|
||
#[derive(Debug, serde::Serialize)] | ||
pub struct GsmDeleteResponse { | ||
pub gsm_rule_delete: bool, | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,137 @@ | ||
use api_models::gsm as gsm_api_types; | ||
use diesel_models::gsm as storage; | ||
use error_stack::{IntoReport, ResultExt}; | ||
use router_env::{instrument, tracing}; | ||
|
||
use crate::{ | ||
core::{ | ||
errors, | ||
errors::{RouterResponse, StorageErrorExt}, | ||
}, | ||
db::gsm::GsmInterface, | ||
services, | ||
types::{self, transformers::ForeignInto}, | ||
AppState, | ||
}; | ||
|
||
#[instrument(skip_all)] | ||
pub async fn create_gsm_rule( | ||
state: AppState, | ||
gsm_rule: gsm_api_types::GsmCreateRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
GsmInterface::add_gsm_rule(db, gsm_rule.foreign_into()) | ||
.await | ||
.to_duplicate_response(errors::ApiErrorResponse::GenericDuplicateError { | ||
message: "GSM with given key already exists in our records".to_string(), | ||
}) | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn retrieve_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmRetrieveRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmRetrieveRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
} = gsm_request; | ||
GsmInterface::find_gsm_rule(db, connector.to_string(), flow, sub_flow, code, message) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn update_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmUpdateRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmUpdateRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
decision, | ||
status, | ||
router_error, | ||
step_up_possible, | ||
} = gsm_request; | ||
GsmInterface::update_gsm_rule( | ||
db, | ||
connector.to_string(), | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
storage::GatewayStatusMappingUpdate { | ||
decision: decision.map(|d| d.to_string()), | ||
status, | ||
router_error: Some(router_error), | ||
step_up_possible, | ||
}, | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.attach_printable("Failed while updating Gsm rule") | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn delete_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmDeleteRequest, | ||
) -> RouterResponse<gsm_api_types::GsmDeleteResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmDeleteRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
} = gsm_request; | ||
match GsmInterface::delete_gsm_rule( | ||
db, | ||
connector.to_string(), | ||
flow.to_owned(), | ||
sub_flow.to_owned(), | ||
code.to_owned(), | ||
message.to_owned(), | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.attach_printable("Failed while Deleting Gsm rule") | ||
{ | ||
Ok(is_deleted) => { | ||
if is_deleted { | ||
Ok(services::ApplicationResponse::Json( | ||
gsm_api_types::GsmDeleteResponse { | ||
gsm_rule_delete: true, | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
}, | ||
)) | ||
} else { | ||
Err(errors::ApiErrorResponse::InternalServerError) | ||
.into_report() | ||
.attach_printable("Failed while Deleting Gsm rule, got response as false") | ||
} | ||
} | ||
Err(err) => Err(err), | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the endpoints and http methods do not match, ideally get should go with the GET http method, same for the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all CRUD APIs we need payload with connector, flow, sub_flow, code and message fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GET endpoint can use query parameters if the values are all single values (and not a list of values).