mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(analytics): FRM Analytics (#4880)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Abhitator216 <abhishek.kanojia@juspay.in> Co-authored-by: Abhishek Kanojia <89402434+Abhitator216@users.noreply.github.com> Co-authored-by: ivor-juspay <138492857+ivor-juspay@users.noreply.github.com> Co-authored-by: Sampras Lopes <sampras.lopes@juspay.in>
This commit is contained in:
@ -14,9 +14,10 @@ pub mod routes {
|
||||
},
|
||||
GenerateReportRequest, GetActivePaymentsMetricRequest, GetApiEventFiltersRequest,
|
||||
GetApiEventMetricRequest, GetAuthEventMetricRequest, GetDisputeMetricRequest,
|
||||
GetPaymentFiltersRequest, GetPaymentIntentFiltersRequest, GetPaymentIntentMetricRequest,
|
||||
GetPaymentMetricRequest, GetRefundFilterRequest, GetRefundMetricRequest,
|
||||
GetSdkEventFiltersRequest, GetSdkEventMetricRequest, ReportRequest,
|
||||
GetFrmFilterRequest, GetFrmMetricRequest, GetPaymentFiltersRequest,
|
||||
GetPaymentIntentFiltersRequest, GetPaymentIntentMetricRequest, GetPaymentMetricRequest,
|
||||
GetRefundFilterRequest, GetRefundMetricRequest, GetSdkEventFiltersRequest,
|
||||
GetSdkEventMetricRequest, ReportRequest,
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
|
||||
@ -54,6 +55,9 @@ pub mod routes {
|
||||
web::resource("filters/payments")
|
||||
.route(web::post().to(get_payment_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("filters/frm").route(web::post().to(get_frm_filters)),
|
||||
)
|
||||
.service(
|
||||
web::resource("filters/refunds")
|
||||
.route(web::post().to(get_refund_filters)),
|
||||
@ -87,6 +91,9 @@ pub mod routes {
|
||||
web::resource("metrics/auth_events")
|
||||
.route(web::post().to(get_auth_event_metrics)),
|
||||
)
|
||||
.service(
|
||||
web::resource("metrics/frm").route(web::post().to(get_frm_metrics)),
|
||||
)
|
||||
.service(
|
||||
web::resource("api_event_logs").route(web::get().to(get_api_events)),
|
||||
)
|
||||
@ -270,6 +277,38 @@ pub mod routes {
|
||||
.await
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `json_payload` array does not contain one `GetFrmMetricRequest` element.
|
||||
pub async fn get_frm_metrics(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<[GetFrmMetricRequest; 1]>,
|
||||
) -> impl Responder {
|
||||
#[allow(clippy::expect_used)]
|
||||
// safety: This shouldn't panic owing to the data type
|
||||
let payload = json_payload
|
||||
.into_inner()
|
||||
.to_vec()
|
||||
.pop()
|
||||
.expect("Couldn't get GetFrmMetricRequest");
|
||||
let flow = AnalyticsFlow::GetFrmMetrics;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
payload,
|
||||
|state, auth: AuthenticationData, req, _| async move {
|
||||
analytics::frm::get_metrics(&state.pool, &auth.merchant_account.merchant_id, req)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth(Permission::Analytics),
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if `json_payload` array does not contain one `GetSdkEventMetricRequest` element.
|
||||
@ -458,6 +497,28 @@ pub mod routes {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_frm_filters(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<GetFrmFilterRequest>,
|
||||
) -> impl Responder {
|
||||
let flow = AnalyticsFlow::GetFrmFilters;
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, auth: AuthenticationData, req: GetFrmFilterRequest, _| async move {
|
||||
analytics::frm::get_filters(&state.pool, req, &auth.merchant_account.merchant_id)
|
||||
.await
|
||||
.map(ApplicationResponse::Json)
|
||||
},
|
||||
&auth::JWTAuth(Permission::Analytics),
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_sdk_event_filters(
|
||||
state: web::Data<AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
|
||||
Reference in New Issue
Block a user