Skip to content

[Customer Portal][BE] Enhance case search validation and add active chats count to conversation stats - #257

Merged
Rashmika998 merged 3 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:customer-portal-milestone-1-cases
Feb 26, 2026
Merged

Rashmika998 merged 3 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:customer-portal-milestone-1-cases

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Description

This PR includes the following enhancements:

  1. Enhanced case search to validate case creation payload, including supporting service requests
  2. Added active chats count to the conversation stats endpoint

Changes

1️⃣ Case Search & Payload Validation Enhancement

  • Improved validation logic for case creation payload
  • Included validation for supporting service requests
  • Ensured required fields and structure are properly validated
  • Updated related DTOs and service-layer validation logic

Reason:
Supporting service requests are now part of the case creation workflow. Proper validation ensures:

  • Data integrity
  • Reduced downstream errors
  • Consistent case creation behavior

2️⃣ Add Active Chats Count to Conversation Stats

  • Updated conversation stats endpoint to include activeChatsCount
  • Implemented aggregation logic to calculate active chat sessions
  • Updated response model to include the new field

Reason:
The dashboard requires visibility into the number of active chats.

Testing

  • Verified case payload validation for valid and invalid supporting service requests
  • Tested conversation stats endpoint with active and inactive chat scenarios
  • Confirmed accurate active chat counts
  • Performed regression testing on case and conversation-related endpoints

Impact

  • Validation logic enhanced (no contract break unless validation constraints changed)
  • Conversation stats response extended (non-breaking addition)

Related PRs

Summary by CodeRabbit

  • New Features

    • Added case type classification (Default Case, Service Request, Security Report Analysis, Announcement) with type-specific validation.
    • Case creation/search now support caseType and optional product/catalog references and variable entries.
    • Deployed products include category; conversation stats now surface activeCount.
  • Chores

    • Updated and simplified backend dependency declarations, removing an unused UUID package.

@coderabbitai

coderabbitai Bot commented Feb 26, 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 9f2bf0f and bff5022.

📒 Files selected for processing (1)
  • apps/customer-portal/backend/modules/entity/types.bal
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/customer-portal/backend/modules/entity/types.bal

📝 Walkthrough

Walkthrough

Adds a CaseType enum, updates case-related types (new/optional fields and Variable type), introduces case-type-specific payload validation, replaces string case type filters with enum arrays, adds product category and activeCount, and adjusts Dependencies.toml (downgrades and removes uuid).

Changes

Cohort / File(s) Summary
Dependencies Management
apps/customer-portal/backend/Dependencies.toml
Downgraded crypto, observe, and task package versions; removed the standalone uuid dependency and simplified dependency lists.
Case Type Enum
apps/customer-portal/backend/modules/entity/enums.bal
Added public CaseType enum with values DEFAULT_CASE, SERVICE_REQUEST, SECURITY_REPORT_ANALYSIS, and ANNOUNCEMENT.
Entity Types
apps/customer-portal/backend/modules/entity/types.bal, apps/customer-portal/backend/modules/types/types.bal
Updated CaseCreatePayload (added caseType?, deployedProductId?, catalogId?, catalogItemId?, variables?; made title/description/issueTypeKey/severityKey optional; removed productId); replaced caseTypeIds?: string[] with caseTypes?: CaseType[]; added category? to DeployedProduct; added activeCount? to conversation stats. Also added new Variable type.
Payload Validation
apps/customer-portal/backend/modules/entity/utils.bal
Added public isolated function validateCaseCreatePayload(CaseCreatePayload) returns string? implementing case-type-specific validation (rules for DEFAULT_CASE and SERVICE_REQUEST; others return not-supported error).
Service & Utilities Integration
apps/customer-portal/backend/service.bal, apps/customer-portal/backend/utils.bal
Integrated validation into case creation flow (returns 400 on validation error); updated search/mapping to use caseTypes; included category in deployed product mapping; added activeCount to conversation stats mapping.

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Service as Service
    participant Validator as Validator
    participant CaseCreator as CaseCreation
    participant DB as Database

    Client->>Service: createCase(CaseCreatePayload)
    Service->>Validator: validateCaseCreatePayload(payload)
    alt validation fails
        Validator-->>Service: "error message"
        Service-->>Client: 400 Bad Request
    else validation OK
        Validator-->>Service: nil
        Service->>CaseCreator: processCase(payload)
        CaseCreator->>DB: insert case (type-specific fields)
        DB-->>CaseCreator: created case
        CaseCreator-->>Service: case response
        Service-->>Client: 201 Created
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • cloby99
  • shayanmalinda

Poem

🐇 I hop through records, checking each case,
Enums and payloads now fall into place,
I validate, nudge catalogs in line,
Categories and counts all neatly align,
A joyful backend burrow—code refined!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main changes: case search validation enhancement and active chats count addition to conversation stats.
Description check ✅ Passed The description covers purpose, goals, approach, testing, and impact sections; however, it lacks several required template sections like documentation, certification, and security checks.
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.

@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

🧹 Nitpick comments (1)
apps/customer-portal/backend/modules/entity/utils.bal (1)

200-203: Add a defensive fallback for unsupported future case types.

Right now unsupported handling is hardcoded to two enum members. A final else branch is safer if new enum values are added later.

♻️ Suggested refactor
-    } else if caseType == ANNOUNCEMENT || caseType == SECURITY_REPORT_ANALYSIS {
+    } else {
         return string `Case type ${caseType} is not supported.`;
     }
+    return ();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/backend/modules/entity/utils.bal` around lines 200 -
203, The current branch only handles ANNOUNCEMENT and SECURITY_REPORT_ANALYSIS
specifically, which will miss any future enum values; update the conditional in
the function using the caseType variable (the block that currently checks "else
if caseType == ANNOUNCEMENT || caseType == SECURITY_REPORT_ANALYSIS") to add a
final else fallback that returns a generic "Case type ${caseType} is not
supported." message for any other enum members so unsupported/new case types are
defensively handled.
🤖 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/modules/entity/utils.bal`:
- Around line 180-182: The validation error string returned when description is
empty contains typos; update the return value in the block that checks "if
description is () || description.trim().length() == 0" to a correct, user-facing
message (e.g., "Description cannot be empty for default case.") by replacing the
existing incorrect text ("Description cannnot be epty for default case.") in the
function in utils.bal that performs description validation.

---

Nitpick comments:
In `@apps/customer-portal/backend/modules/entity/utils.bal`:
- Around line 200-203: The current branch only handles ANNOUNCEMENT and
SECURITY_REPORT_ANALYSIS specifically, which will miss any future enum values;
update the conditional in the function using the caseType variable (the block
that currently checks "else if caseType == ANNOUNCEMENT || caseType ==
SECURITY_REPORT_ANALYSIS") to add a final else fallback that returns a generic
"Case type ${caseType} is not supported." message for any other enum members so
unsupported/new case types are defensively handled.

ℹ️ 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 5931763 and 935656a.

📒 Files selected for processing (7)
  • apps/customer-portal/backend/Dependencies.toml
  • apps/customer-portal/backend/modules/entity/enums.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/modules/entity/utils.bal

@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

♻️ Duplicate comments (1)
apps/customer-portal/backend/modules/entity/utils.bal (1)

180-182: ⚠️ Potential issue | 🟡 Minor

Fix typo in user-facing validation message.

Line 181 still contains typos (cannnot, epty) in an API-facing error string.

✏️ Suggested fix
-            return "Description cannnot be epty for default case.";
+            return "Description cannot be empty for default case.";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/customer-portal/backend/modules/entity/utils.bal` around lines 180 -
182, The user-facing validation message contains typos; update the returned
string in the block checking description (the conditional that uses
description.trim().length() and returns the error) to a correct, clear message
such as "Description cannot be empty for default case."—replace the misspelled
"cannnot" (and any other variants like "epty") with the correct spelling while
leaving the conditional logic (the description is () ||
description.trim().length() == 0 check) unchanged.
🤖 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/modules/entity/utils.bal`:
- Around line 183-195: The current nil-only checks allow empty or
whitespace-only strings; update the validation in the same block that checks
caseType (including SERVICE_REQUEST branch) to reject values that are nil or
blank by testing both nil and trimmed length 0 for payload.issueTypeKey,
payload.severityKey, payload.catalogId and payload.catalogItemId (e.g., replace
the nil-only checks with a compound check that treats "" and "   " as invalid by
verifying the field is not nil and payload.<field>.trim().length() > 0 or
equivalent in Ballerina using a type test for string and trim/length).

---

Duplicate comments:
In `@apps/customer-portal/backend/modules/entity/utils.bal`:
- Around line 180-182: The user-facing validation message contains typos; update
the returned string in the block checking description (the conditional that uses
description.trim().length() and returns the error) to a correct, clear message
such as "Description cannot be empty for default case."—replace the misspelled
"cannnot" (and any other variants like "epty") with the correct spelling while
leaving the conditional logic (the description is () ||
description.trim().length() == 0 check) unchanged.

ℹ️ 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 935656a and 9f2bf0f.

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

Comment thread apps/customer-portal/backend/modules/entity/utils.bal
Comment thread apps/customer-portal/backend/modules/entity/utils.bal
Comment thread apps/customer-portal/backend/service.bal
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.

3 participants