Skip to content

[Customer Portal[BE] Add change request stats endpoint - #278

Merged
sacheeramesh merged 2 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:customer-portal-milestone-1-projects
Mar 2, 2026
Merged

sacheeramesh merged 2 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:customer-portal-milestone-1-projects

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces a new endpoint to provide statistical data for change requests.

Changes

  • Added change request stats endpoint
  • Implemented aggregation logic for change request metrics
  • Added validation and proper error handling
  • Updated response models/DTOs
  • Integrated service-layer computation logic

Functionality

The new endpoint provides aggregated statistics such as:

  • Total change requests
  • Status-based counts
  • Trend data (if applicable)
  • Other summary metrics required for dashboards

Reason

Change request reporting required a dedicated endpoint to:

  • Support dashboard visualizations
  • Provide aggregated insights
  • Avoid frontend-side computation
  • Improve performance and consistency

Centralizing this logic in the backend ensures scalable and reliable reporting.

Testing

  • Verified stats calculations with multiple datasets
  • Tested edge cases (no records, partial data, large dataset)
  • Confirmed correct response structure

Impact

  • New endpoint added (non-breaking enhancement)
  • No changes to existing change request APIs
  • Improves reporting and analytics capabilities

Related PRs

Summary by CodeRabbit

  • New Features

    • Added a new API to fetch project change-request statistics, returning total counts and a breakdown by request state for each project.
  • Bug Fixes

    • Fixed a naming inconsistency in change-request state identifiers for improved consistency and reliability.
    • Added response mapping to ensure statistics are returned in the expected public format.

@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0a1850 and a16b3ec.

📒 Files selected for processing (1)
  • apps/customer-portal/backend/service.bal

📝 Walkthrough

Walkthrough

Adds a project-level change-request statistics endpoint, supporting entity function, response mapping, and new response types; also corrects a typo in the conversation state configurable type name. (47 words)

Changes

Cohort / File(s) Summary
Change Request Stats — API & Service
apps/customer-portal/backend/service.bal
New resource GET projects/[id]/stats/change-requests: authenticates, checks authorization, calls entity function, handles Unauthorized/Forbidden, logs other errors, and returns mapped response.
Change Request Stats — Entity
apps/customer-portal/backend/modules/entity/entity.bal
Adds `public isolated function getProjectChangeRequestStats(string idToken, string projectId) returns ProjectChangeRequestStatsResponse
Response Mapping Utilities
apps/customer-portal/backend/utils.bal
Adds mapProjectChangeRequestStatsResponse to convert internal ProjectChangeRequestStatsResponse (ChoiceListItem[]) into public types:ProjectChangeRequestStatsResponse (ReferenceItem[]).
Internal Types & Config
apps/customer-portal/backend/modules/entity/types.bal, apps/customer-portal/backend/modules/entity/utils.bal
Renames configurable type ConverstaionStateIdsConversationStateIds. Adds internal ProjectChangeRequestStatsResponse type with totalCount and stateCount.
Public Types
apps/customer-portal/backend/modules/types/types.bal
Adds public ProjectChangeRequestStatsResponse type with totalCount:int and stateCount:ReferenceItem[] for API exposure.

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Service as Service (HTTP Resource)
    participant Entity as Entity Module
    participant Mapper as Utils (Mapper)

    Client->>Service: GET /projects/[id]/stats/change-requests
    Service->>Service: Authenticate & authorize request
    Service->>Entity: getProjectChangeRequestStats(idToken, projectId)
    Entity->>Entity: HTTP GET /projects/[projectId]/change-requests/stats
    Entity-->>Service: ProjectChangeRequestStatsResponse
    Service->>Mapper: mapProjectChangeRequestStatsResponse(response)
    Mapper-->>Service: types:ProjectChangeRequestStatsResponse
    Service-->>Client: JSON response (totalCount, stateCount)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • cloby99
  • shayanmalinda
  • sacheeramesh

Poem

🐰 I hopped through code to count and cheer,
Change-requests tallied, their states appear,
Types aligned and mappers neat,
A typo fixed — now names repeat,
Hooray — stats delivered, clear and near!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description deviates significantly from the required template, missing critical sections like Purpose, Goals, Approach, User stories, Release notes, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Migrations, and Test environment. Follow the repository's required PR description template and complete all mandatory sections, including Purpose with issue links, Goals, Approach, test coverage details, Documentation, and Security checks.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a new change request stats endpoint to the Customer Portal backend.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rashmika998
Rashmika998 requested a review from cloby99 March 2, 2026 07:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/customer-portal/backend/service.bal`:
- Around line 3145-3146: The resource function signature using the unconstrained
path param `[string id]` (resource function get projects/[string
id]/stats/change-requests) allows malformed IDs to reach downstream entity calls
and be collapsed into 500s; change the path parameter type to the constrained
entity:IdString (or another project ID-specific constrained type) so invalid IDs
are rejected before entity lookup, and add explicit handling to return 400 for
malformed IDs (or map non-401/403 validation failures to http:BadRequest) around
the same block that currently returns 500 (the error handling logic referenced
near lines 3177 and the similar code in the 3157–3184 region). Ensure you update
the function signature and the corresponding validation/error branch so client
errors become 400 responses instead of 500.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d787fd and d0a1850.

📒 Files selected for processing (6)
  • apps/customer-portal/backend/modules/entity/entity.bal
  • apps/customer-portal/backend/modules/entity/types.bal
  • apps/customer-portal/backend/modules/entity/utils.bal
  • apps/customer-portal/backend/modules/types/types.bal
  • apps/customer-portal/backend/service.bal
  • apps/customer-portal/backend/utils.bal

Comment thread apps/customer-portal/backend/service.bal Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/Customer Portal Area/Backend Type/Improvement Marks enhancements or improvements to existing features

Projects

Status: Staging Deployed

Development

Successfully merging this pull request may close these issues.

2 participants