Bug: feat(payouts): Add profile level get filters API for payouts



Currently payout get filter API gives filters whole merchant. Since dashboard is being moved to profile level, filter API at profile level should be needed.
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 515a7be959a..65490e2d270 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -947,10 +947,11 @@ pub async fn payouts_filtered_list_core(
 pub async fn payouts_list_available_filters_core(
     state: SessionState,
     merchant_account: domain::MerchantAccount,
+    profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
     time_range: api::TimeRange,
 ) -> RouterResponse<api::PayoutListFilters> {
     let db = state.store.as_ref();
-    let payout = db
+    let payouts = db
         .filter_payouts_by_time_range_constraints(
             merchant_account.get_id(),
             &time_range,
@@ -959,9 +960,11 @@ pub async fn payouts_list_available_filters_core(
         .await
         .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
 
+    let payouts = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, payouts);
+
     let filters = db
         .get_filters_for_payouts(
-            payout.as_slice(),
+            payouts.as_slice(),
             merchant_account.get_id(),
             storage_enums::MerchantStorageScheme::PostgresOnly,
         )
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 8201380cc29..d3b9801cedf 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -1021,7 +1021,12 @@ impl Payouts {
                         .route(web::post().to(payouts_list_by_filter_profile)),
                 )
                 .service(
-                    web::resource("/filter").route(web::post().to(payouts_list_available_filters)),
+                    web::resource("/filter")
+                        .route(web::post().to(payouts_list_available_filters_for_merchant)),
+                )
+                .service(
+                    web::resource("/profile/filter")
+                        .route(web::post().to(payouts_list_available_filters_for_profile)),
                 );
         }
         route = route
diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rs
index bc14a619745..8c45f9fdfd9 100644
--- a/crates/router/src/routes/payouts.rs
+++ b/crates/router/src/routes/payouts.rs
@@ -320,10 +320,10 @@ pub async fn payouts_list_by_filter_profile(
     .await
 }
 
-/// Payouts - Available filters
+/// Payouts - Available filters for Merchant
 #[cfg(feature = "olap")]
 #[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))]
-pub async fn payouts_list_available_filters(
+pub async fn payouts_list_available_filters_for_merchant(
     state: web::Data<AppState>,
     req: HttpRequest,
     json_payload: web::Json<payment_types::TimeRange>,
@@ -337,7 +337,41 @@ pub async fn payouts_list_available_filters(
         &req,
         payload,
         |state, auth, req, _| {
-            payouts_list_available_filters_core(state, auth.merchant_account, req)
+            payouts_list_available_filters_core(state, auth.merchant_account, None, req)
+        },
+        auth::auth_type(
+            &auth::HeaderAuth(auth::ApiKeyAuth),
+            &auth::JWTAuth(Permission::PayoutRead),
+            req.headers(),
+        ),
+        api_locking::LockAction::NotApplicable,
+    ))
+    .await
+}
+
+/// Payouts - Available filters for Profile
+#[cfg(feature = "olap")]
+#[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))]
+pub async fn payouts_list_available_filters_for_profile(
+    state: web::Data<AppState>,
+    req: HttpRequest,
+    json_payload: web::Json<payment_types::TimeRange>,
+) -> HttpResponse {
+    let flow = Flow::PayoutsFilter;
+    let payload = json_payload.into_inner();
+
+    Box::pin(api::server_wrap(
+        flow,
+        state,
+        &req,
+        payload,
+        |state, auth, req, _| {
+            payouts_list_available_filters_core(
+                state,
+                auth.merchant_account,
+                auth.profile_id.map(|profile_id| vec![profile_id]),
+                req,
+            )
         },
         auth::auth_type(
             &auth::HeaderAuth(auth::ApiKeyAuth),

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
- This PR adds a profile level get filters api for payouts.

### Additional Changes

- [x] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
Closes #5805.

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
```
curl --location 'http://localhost:8080/payouts/profile/filter' \
--header 'Content-Type: application/json' \
--header 'authorization: Bearer JWT with profile_id' \
--data '{"start_time":"2024-08-05T18:30:00Z","end_time":"2024-09-05T08:19:00Z"}'
```
Response will look like this
```json
{
    "connector": [],
    "currency": [],
    "status": [],
    "payout_method": []
}
```

This API should only give filters for payouts which have profile_id as the one in JWT.
This cannot be tested in integ/sandbox as the JWT currently doesn't have profile_id.

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
