refactor(router): Refactored Authentication (#327)

This commit is contained in:
Rachit Naithani
2023-01-10 15:06:34 +05:30
committed by GitHub
parent 98816c05bd
commit 59573efe91
17 changed files with 363 additions and 384 deletions

View File

@ -8,28 +8,25 @@ use serde::Serialize;
use crate::{
core::errors::{self, RouterResult},
routes,
services::{api, logger},
types::storage,
services::{api, authentication as auth, logger},
};
#[instrument(skip(request, payload, state, func))]
pub async fn compatibility_api_wrap<'a, 'b, A, T, Q, F, Fut, S, E>(
#[instrument(skip(request, payload, state, func, api_authentication))]
pub async fn compatibility_api_wrap<'a, 'b, U, T, Q, F, Fut, S, E>(
state: &'b routes::AppState,
request: &'a HttpRequest,
payload: T,
func: F,
api_authentication: A,
api_authentication: &dyn auth::AuthenticateAndFetch<U>,
) -> HttpResponse
where
A: Into<api::ApiAuthentication<'a>> + std::fmt::Debug,
F: Fn(&'b routes::AppState, storage::MerchantAccount, T) -> Fut,
F: Fn(&'b routes::AppState, U, T) -> Fut,
Fut: Future<Output = RouterResult<api::BachResponse<Q>>>,
Q: Serialize + std::fmt::Debug + 'a,
S: From<Q> + Serialize,
E: From<errors::ApiErrorResponse> + Serialize + error_stack::Context + actix_web::ResponseError,
T: std::fmt::Debug,
{
let api_authentication = api_authentication.into();
let resp = api::server_wrap_util(state, request, payload, func, api_authentication).await;
match resp {
Ok(api::BachResponse::Json(router_resp)) => {