From 33ee7ed7a4b0e3d7f27af213ac6df723ce262ae7 Mon Sep 17 00:00:00 2001 From: Devadathan M B <84301852+devadathanmb@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:25:16 +0530 Subject: [PATCH] feat: Add group_by_state support to advance request stats API (#582) --- reference/admin.yaml | 94 ++++++++++++++++---- reference/spender.yaml | 94 ++++++++++++++++---- src/components/schemas/advance_request.yaml | 96 +++++++++++++++++---- 3 files changed, 233 insertions(+), 51 deletions(-) diff --git a/reference/admin.yaml b/reference/admin.yaml index ba195e669..9c3745814 100644 --- a/reference/admin.yaml +++ b/reference/admin.yaml @@ -4927,26 +4927,86 @@ components: advance_requests_stats_in: properties: query_params: - type: string description: | - This field contains the query param string similar to the query params passed in advance_requests GET call for displaying advance_requests in the list view. + Query param string similar to advance_requests GET call. Use group_by_state=eq.true to get state-wise grouping of stats. nullable: false - example: id=in.('adr1263', 'adr1569') + example: id=in.('adr1263','adr1569')&group_by_state=eq.true advance_requests_stats_out: - type: object - properties: - count: - type: integer - description: | - This field represents the total number of advance_requests that match the criteria specified in the query_params within the body of the request. - nullable: false - example: 1 - total_amount: - allOf: - - $ref: '#/components/schemas/amount' - description: | - This field indicates the sum of amount of advance_requests that match the criteria specified in the query_params within the body of the request. - example: 100 + oneOf: + - type: array + title: State-wise grouped stats + description: Stats grouped by advance request state + items: + type: object + required: + - count + - total_amount + - state + properties: + count: + type: integer + nullable: false + description: Number of matching advance requests in this state. + example: 10 + total_amount: + type: number + nullable: false + description: Sum of amounts for matching advance requests in this state. + example: 44545.4 + state: + type: string + enum: + - DRAFT + - APPROVAL_PENDING + - APPROVED + - CANCELLED + - REJECTED + - PAID + - PULLED_BACK + - SENT_BACK + description: Advance request state. + - type: object + title: Overall stats + description: Overall stats without state grouping. + required: + - count + - total_amount + properties: + count: + type: integer + nullable: false + description: Total number of matching advance requests. + example: 353 + total_amount: + type: number + nullable: false + description: Sum of amounts for all matching advance requests. + example: 45882.4 + example: + - state: DRAFT + count: 10 + total_amount: 44545.4 + - state: APPROVAL_PENDING + count: 0 + total_amount: 0 + - state: APPROVED + count: 343 + total_amount: 1337 + - state: CANCELLED + count: 0 + total_amount: 0 + - state: SENT_BACK + count: 0 + total_amount: 0 + - state: PULLED_BACK + count: 0 + total_amount: 0 + - state: REJECTED + count: 0 + total_amount: 0 + - state: PAID + count: 0 + total_amount: 0 advance_request_out_embed: type: object nullable: true diff --git a/reference/spender.yaml b/reference/spender.yaml index c7b0da61b..a3dbc6473 100644 --- a/reference/spender.yaml +++ b/reference/spender.yaml @@ -3888,26 +3888,86 @@ components: advance_requests_stats_in: properties: query_params: - type: string description: | - This field contains the query param string similar to the query params passed in advance_requests GET call for displaying advance_requests in the list view. + Query param string similar to advance_requests GET call. Use group_by_state=eq.true to get state-wise grouping of stats. nullable: false - example: id=in.('adr1263', 'adr1569') + example: id=in.('adr1263','adr1569')&group_by_state=eq.true advance_requests_stats_out: - type: object - properties: - count: - type: integer - description: | - This field represents the total number of advance_requests that match the criteria specified in the query_params within the body of the request. - nullable: false - example: 1 - total_amount: - allOf: - - $ref: '#/components/schemas/amount' - description: | - This field indicates the sum of amount of advance_requests that match the criteria specified in the query_params within the body of the request. - example: 100 + oneOf: + - type: array + title: State-wise grouped stats + description: Stats grouped by advance request state + items: + type: object + required: + - count + - total_amount + - state + properties: + count: + type: integer + nullable: false + description: Number of matching advance requests in this state. + example: 10 + total_amount: + type: number + nullable: false + description: Sum of amounts for matching advance requests in this state. + example: 44545.4 + state: + type: string + enum: + - DRAFT + - APPROVAL_PENDING + - APPROVED + - CANCELLED + - REJECTED + - PAID + - PULLED_BACK + - SENT_BACK + description: Advance request state. + - type: object + title: Overall stats + description: Overall stats without state grouping. + required: + - count + - total_amount + properties: + count: + type: integer + nullable: false + description: Total number of matching advance requests. + example: 353 + total_amount: + type: number + nullable: false + description: Sum of amounts for all matching advance requests. + example: 45882.4 + example: + - state: DRAFT + count: 10 + total_amount: 44545.4 + - state: APPROVAL_PENDING + count: 0 + total_amount: 0 + - state: APPROVED + count: 343 + total_amount: 1337 + - state: CANCELLED + count: 0 + total_amount: 0 + - state: SENT_BACK + count: 0 + total_amount: 0 + - state: PULLED_BACK + count: 0 + total_amount: 0 + - state: REJECTED + count: 0 + total_amount: 0 + - state: PAID + count: 0 + total_amount: 0 advance_request_out_embed: type: object nullable: true diff --git a/src/components/schemas/advance_request.yaml b/src/components/schemas/advance_request.yaml index 017a0eaf5..32b210963 100644 --- a/src/components/schemas/advance_request.yaml +++ b/src/components/schemas/advance_request.yaml @@ -151,27 +151,89 @@ advance_request_action_in: advance_requests_stats_in: properties: query_params: - type: string description: | - This field contains the query param string similar to the query params passed in advance_requests GET call for displaying advance_requests in the list view. + Query param string similar to advance_requests GET call. Use group_by_state=eq.true to get state-wise grouping of stats. nullable: false - example: id=in.('adr1263', 'adr1569') + example: id=in.('adr1263','adr1569')&group_by_state=eq.true advance_requests_stats_out: - type: object - properties: - count: - type: integer - description: | - This field represents the total number of advance_requests that match the criteria specified in the query_params within the body of the request. - nullable: false - example: 1 - total_amount: - allOf: - - $ref: './fields.yaml#/amount' - description: | - This field indicates the sum of amount of advance_requests that match the criteria specified in the query_params within the body of the request. - example: 100 + oneOf: + - type: array + title: "State-wise grouped stats" + description: "Stats grouped by advance request state" + items: + type: object + required: + - count + - total_amount + - state + properties: + count: + type: integer + nullable: false + description: "Number of matching advance requests in this state." + example: 10 + total_amount: + type: number + nullable: false + description: "Sum of amounts for matching advance requests in this state." + example: 44545.4 + state: + type: string + enum: + - DRAFT + - APPROVAL_PENDING + - APPROVED + - CANCELLED + - REJECTED + - PAID + - PULLED_BACK + - SENT_BACK + description: "Advance request state." + # NOTE: This is a hack to maintain backward compatibility with the existing response structure + # TODO: @Dev to update the response once the hack is removed from platform-api + - type: object + title: "Overall stats" + description: "Overall stats without state grouping." + required: + - count + - total_amount + properties: + count: + type: integer + nullable: false + description: "Total number of matching advance requests." + example: 353 + total_amount: + type: number + nullable: false + description: "Sum of amounts for all matching advance requests." + example: 45882.4 + example: + - state: "DRAFT" + count: 10 + total_amount: 44545.4 + - state: "APPROVAL_PENDING" + count: 0 + total_amount: 0 + - state: "APPROVED" + count: 343 + total_amount: 1337.0 + - state: "CANCELLED" + count: 0 + total_amount: 0 + - state: "SENT_BACK" + count: 0 + total_amount: 0 + - state: "PULLED_BACK" + count: 0 + total_amount: 0 + - state: "REJECTED" + count: 0 + total_amount: 0 + - state: "PAID" + count: 0 + total_amount: 0 advance_request_out_embed: type: object