Skip to content

Commit

Permalink
refactor(core): Add additional parameters in AppState and refactor Ap…
Browse files Browse the repository at this point in the history
…pState references (#2123)

Co-authored-by: Kritik Modi <[email protected]>
Co-authored-by: Kritik Modi <[email protected]>
Co-authored-by: Nitesh Balla <[email protected]>
  • Loading branch information
4 people authored Sep 18, 2023
1 parent b39369c commit a0a8ef2
Show file tree
Hide file tree
Showing 46 changed files with 531 additions and 395 deletions.
16 changes: 8 additions & 8 deletions crates/router/src/compatibility/stripe/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub async fn customer_create(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
create_cust_req,
|state, auth, req| {
customers::create_customer(&*state.store, auth.merchant_account, auth.key_store, req)
customers::create_customer(state, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
))
Expand Down Expand Up @@ -77,11 +77,11 @@ pub async fn customer_retrieve(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
customers::retrieve_customer(&*state.store, auth.merchant_account, auth.key_store, req)
customers::retrieve_customer(state, auth.merchant_account, auth.key_store, req)
},
&auth::ApiKeyAuth,
))
Expand Down Expand Up @@ -121,11 +121,11 @@ pub async fn customer_update(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
cust_update_req,
|state, auth, req| {
customers::update_customer(&*state.store, auth.merchant_account, req, auth.key_store)
customers::update_customer(state, auth.merchant_account, req, auth.key_store)
},
&auth::ApiKeyAuth,
))
Expand Down Expand Up @@ -156,7 +156,7 @@ pub async fn customer_delete(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -190,7 +190,7 @@ pub async fn list_customer_payment_method_api(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down
18 changes: 9 additions & 9 deletions crates/router/src/compatibility/stripe/payment_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn payment_intents_create(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
create_payment_req,
|state, auth, req| {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub async fn payment_intents_retrieve(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, payload| {
Expand Down Expand Up @@ -169,7 +169,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -233,7 +233,7 @@ pub async fn payment_intents_update(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -299,7 +299,7 @@ pub async fn payment_intents_confirm(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -355,7 +355,7 @@ pub async fn payment_intents_capture(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
capture_payload,
|state, auth, payload| {
Expand Down Expand Up @@ -415,7 +415,7 @@ pub async fn payment_intents_cancel(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -461,10 +461,10 @@ pub async fn payment_intent_list(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| payments::list_payments(&*state.store, auth.merchant_account, req),
|state, auth, req| payments::list_payments(state, auth.merchant_account, req),
&auth::ApiKeyAuth,
))
.await
Expand Down
10 changes: 5 additions & 5 deletions crates/router/src/compatibility/stripe/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn refund_create(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
create_refund_req,
|state, auth, req| {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub async fn refund_retrieve_with_gateway_creds(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
refund_request,
|state, auth, refund_request| {
Expand Down Expand Up @@ -126,7 +126,7 @@ pub async fn refund_retrieve(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
refund_request,
|state, auth, refund_request| {
Expand Down Expand Up @@ -167,11 +167,11 @@ pub async fn refund_update(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
create_refund_update_req,
|state, auth, req| {
refunds::refund_update_core(&*state.store, auth.merchant_account, &refund_id, req)
refunds::refund_update_core(state, auth.merchant_account, &refund_id, req)
},
&auth::ApiKeyAuth,
))
Expand Down
8 changes: 4 additions & 4 deletions crates/router/src/compatibility/stripe/setup_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn setup_intents_create(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
create_payment_req,
|state, auth, req| {
Expand Down Expand Up @@ -110,7 +110,7 @@ pub async fn setup_intents_retrieve(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, payload| {
Expand Down Expand Up @@ -175,7 +175,7 @@ pub async fn setup_intents_update(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down Expand Up @@ -241,7 +241,7 @@ pub async fn setup_intents_confirm(
_,
>(
flow,
state.get_ref(),
state.into_inner(),
&req,
payload,
|state, auth, req| {
Expand Down
17 changes: 12 additions & 5 deletions crates/router/src/compatibility/wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{future::Future, time::Instant};
use std::{future::Future, sync::Arc, time::Instant};

use actix_web::{HttpRequest, HttpResponse, Responder};
use common_utils::errors::{CustomResult, ErrorSwitch};
Expand All @@ -14,14 +14,14 @@ use crate::{
#[instrument(skip(request, payload, state, func, api_authentication))]
pub async fn compatibility_api_wrap<'a, 'b, A, U, T, Q, F, Fut, S, E, E2>(
flow: impl router_env::types::FlowMetric,
state: &'b A,
state: Arc<A>,
request: &'a HttpRequest,
payload: T,
func: F,
api_authentication: &dyn auth::AuthenticateAndFetch<U, A>,
) -> HttpResponse
where
F: Fn(&'b A, U, T) -> Fut,
F: Fn(A, U, T) -> Fut,
Fut: Future<Output = CustomResult<api::ApplicationResponse<Q>, E2>>,
E2: ErrorSwitch<E> + std::error::Error + Send + Sync + 'static,
Q: Serialize + std::fmt::Debug + 'a,
Expand All @@ -31,7 +31,7 @@ where
error_stack::Report<E>: services::EmbedError,
errors::ApiErrorResponse: ErrorSwitch<E>,
T: std::fmt::Debug,
A: AppStateInfo,
A: AppStateInfo + Clone,
{
let request_method = request.method().as_str();
let url_path = request.path();
Expand All @@ -42,7 +42,14 @@ where
logger::info!(tag = ?Tag::BeginRequest, payload = ?payload);

let res = match metrics::request::record_request_time_metric(
api::server_wrap_util(&flow, state, request, payload, func, api_authentication),
api::server_wrap_util(
&flow,
state.clone().into(),
request,
payload,
func,
api_authentication,
),
&flow,
)
.await
Expand Down
Loading

0 comments on commit a0a8ef2

Please sign in to comment.