Skip to content

[CSM Portal][BE] align with entity service PR #929: drop Key/Keys suffix, add change-requests search - #933

Merged
shayanmalinda merged 2 commits into
wso2-open-operations:v2from
Rashmika998:csm-portal-be-pr929-alignment
Jun 24, 2026
Merged

shayanmalinda merged 2 commits into
wso2-open-operations:v2from
Rashmika998:csm-portal-be-pr929-alignment

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Remove Key/Keys suffix from all enum request fields to match the entity service PR [Customer Entity] Add search endpoint and standardise enum field naming #929 contract: stateKey→state, severityKey→severity, workStateKey→workState (PATCH case); typeKey→type, issueTypeKey→issueType (create case/comment); typeKeys→types, stateKeys→states, severityKeys→severities, engagementTypeKeys→engagementTypes, issueTypeKeys→issueTypes (case search); deploymentTypeKeys→deploymentTypes (deployment search)
  • Fix BFF Go handler code to read the renamed fields from JSON (state/workState in PatchCase, type in CreateCaseComment)
  • Add POST /change-requests/search endpoint: entity client method, ChangeRequestHandler, interface, mock, tests, route registration, and full OpenAPI spec entry

Test plan

  • All existing handler tests pass (go test ./...)
  • New TestSearchChangeRequests tests cover auth, body size, invalid JSON, happy path, and upstream error mapping
  • PATCH case state/workState validation still works with new field names
  • CreateCaseComment work_note bypass still works with new field name

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new change request search endpoint to the portal API.
    • Updated request formats for case creation, case updates, comments, and search filters to use simpler field names.
  • Bug Fixes

    • Improved validation handling for case updates and comments so requests are checked against the updated API contract.
    • Added consistent error responses for unauthenticated, invalid, and oversized requests on change request search.

… drop Key/Keys suffix, add change-requests search

- Remove Key/Keys suffix from all enum request fields to match entity service:
  stateKey→state, severityKey→severity, workStateKey→workState (PATCH case),
  typeKey→type, issueTypeKey→issueType (create case/comment),
  typeKeys→types, stateKeys→states, severityKeys→severities,
  engagementTypeKeys→engagementTypes, issueTypeKeys→issueTypes (case search),
  deploymentTypeKeys→deploymentTypes (deployment search)
- Update PatchCase handler to read state/workState from new JSON field names
- Update CreateCaseComment handler to read type from new JSON field name
- Add POST /change-requests/search endpoint: entity client method, handler,
  interface, mock, tests, route registration, and openapi spec
- Update openapi.yaml, README.md, and CLAUDE.md throughout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Rashmika998 Rashmika998 self-assigned this Jun 24, 2026
@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Rashmika998, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 14 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04dfd010-248c-4fbd-b1e7-e664793120df

📥 Commits

Reviewing files that changed from the base of the PR and between 646873b and e287068.

📒 Files selected for processing (7)
  • apps/csm-portal/backend/README.md
  • apps/csm-portal/backend/cmd/server/main.go
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/change_requests.go
  • apps/csm-portal/backend/internal/handler/change_requests_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • apps/csm-portal/backend/openapi.yaml
📝 Walkthrough

Walkthrough

The PR renames all *Key/*Keys suffixed JSON request fields to plain names across the CSM portal backend (cases create, patch, comment, and search filters), updating the OpenAPI spec, handler logic, and tests. It also adds a new POST /change-requests/search endpoint with entity client method, HTTP handler, server wiring, tests, and OpenAPI schemas.

Changes

Field Naming Refactor (*Key → plain names)

Layer / File(s) Summary
OpenAPI contract field renames
apps/csm-portal/backend/openapi.yaml, apps/csm-portal/backend/CLAUDE.md, apps/csm-portal/backend/README.md
UpdateCaseRequest, CaseCreatePayload, CaseSearchFilters, DeploymentSearchPayload, and CaseCommentCreatePayload schemas drop the *Key/*Keys suffix from all field names. PATCH /cases/{id} description and developer docs updated to match.
Cases handler JSON tag updates
apps/csm-portal/backend/internal/handler/cases.go
CreateCaseComment reads type (was typeKey) for the work_note exemption gate; PatchCase reads state/workState (was stateKey/workStateKey) for transition and work-state guards.
Cases test payload field renames
apps/csm-portal/backend/internal/handler/cases_test.go
All affected request payloads in create-case, create-comment, search-cases, and patch-case tests updated to the new field names.

New Change Requests Search Endpoint

Layer / File(s) Summary
OpenAPI schemas and entity client method
apps/csm-portal/backend/openapi.yaml, apps/csm-portal/backend/internal/entity/entity.go
Adds POST /change-requests/search path and ChangeRequestSearchPayload/ChangeRequestSearchView/ChangeRequestSearchResponse schemas to the spec. Adds SearchChangeRequests on the entity Client to POST raw bytes to the upstream service.
ChangeRequestHandler implementation and server wiring
apps/csm-portal/backend/internal/handler/change_requests.go, apps/csm-portal/backend/cmd/server/main.go
Defines entityChangeRequestClient interface, ChangeRequestHandler struct, constructor, and SearchChangeRequests HTTP handler with auth check, body size limit, JSON validation, upstream call, error mapping, and JSON response. Handler is initialized and the route registered in main.go.
ChangeRequestHandler tests and documentation
apps/csm-portal/backend/internal/handler/change_requests_test.go, ...helpers_test.go, apps/csm-portal/backend/README.md
TestSearchChangeRequests covers unauthenticated, oversized, invalid JSON, success, and upstream error cases. mockEntityChangeRequestClient added to test helpers. README updated with new handler file and endpoint docs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • wso2-open-operations/cs-tools#929: Adds the corresponding entity-service change-request search handler and standardizes the same request/response field names that this PR adopts on the portal side.
  • wso2-open-operations/cs-tools#892: Modifies the same CreateCaseComment work_note bypass logic and typeKey handling in cases.go that this PR renames to type.
  • wso2-open-operations/cs-tools#896: Adds workState support to the entity-service UpdateCaseRequest, directly related to this PR dropping workStateKey in the portal's PatchCase handler.

Suggested labels

Type/Improvement, Area/Backend, App/CSM Portal

Suggested reviewers

  • cloby99
  • v15a1

🐇 No more typeKey, no more stateKey in sight,
The fields shed their suffixes, plain and light.
Change requests now search with a brand-new route,
The rabbit hops happy — refactor devout!
/change-requests/search, all wired and tested right. 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description has Summary and Test plan, but omits most required template sections such as Purpose, Goals, Approach, Release note, and Security checks. Add the missing template sections or mark them N/A where appropriate, including Purpose, Goals, Approach, Release note, Documentation, Automation tests, and Security checks.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: aligning request field names and adding change-request search.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features Area/Backend App/CSM Portal labels Jun 24, 2026

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/csm-portal/backend/internal/handler/cases.go`:
- Around line 183-186: The request guard in cases handling is now only reading
the renamed JSON keys, so legacy portal payloads can silently bypass the
work-note exemption and local transition checks. Update the parsing logic in the
cases handler to accept both the new and legacy aliases in the relevant request
metadata structs (including the work-state guard path), or explicitly detect
legacy-only payloads and return a clear 400; keep the behavior
backward-compatible during the rename rather than defaulting to empty values.

In `@apps/csm-portal/backend/openapi.yaml`:
- Around line 131-132: The OpenAPI request schema change in the case
update/create endpoints is removing live field names too abruptly, while the
frontend consumer still sends the older keys. Update the relevant request body
definitions in openapi.yaml so the case mutation endpoints accept both the new
names and the existing client fields used by cases.ts, or otherwise keep the old
spellings during a deprecation window; make sure the specs for the affected
operations stay backward-compatible across all referenced request-body blocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 362cf78a-912b-44e0-af14-66fc654f8be4

📥 Commits

Reviewing files that changed from the base of the PR and between d6c9c40 and 646873b.

📒 Files selected for processing (10)
  • apps/csm-portal/backend/CLAUDE.md
  • apps/csm-portal/backend/README.md
  • apps/csm-portal/backend/cmd/server/main.go
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/cases.go
  • apps/csm-portal/backend/internal/handler/cases_test.go
  • apps/csm-portal/backend/internal/handler/change_requests.go
  • apps/csm-portal/backend/internal/handler/change_requests_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • apps/csm-portal/backend/openapi.yaml

Comment thread apps/csm-portal/backend/internal/handler/cases.go
Comment thread apps/csm-portal/backend/openapi.yaml
…ate/type (PR wso2-open-operations#932)

- Add GetChangeRequest entity client method, interface method, handler,
  mock, tests, and route registration for GET /change-requests/{id}
- UUID validation on the path param (fail fast before calling upstream)
- Update ChangeRequestSearchView in openapi.yaml: mark impact, state, type
  as nullable: true to match entity service PR wso2-open-operations#932 fix
- Add ChangeRequestDetail schema extending ChangeRequestSearchView with
  approval and planning fields
- Update README.md with the new endpoint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants