Skip to content

[Customer portal][BE] Add PATCH endpoint to update change request - #298

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

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

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a PATCH endpoint to update existing change requests.

Changes

  • Added PATCH endpoint to update change request details
  • Implemented partial update support for change request fields
  • Added request validation and error handling
  • Updated service-layer logic and mappings
  • Ensured consistent response structure

Endpoint

PATCH /change-requests/{changeRequestId}

Reason

Previously, change requests could not be updated via API once created.
This endpoint enables:

  • Updating change request attributes (e.g., status, impact, description, etc.)
  • Supporting lifecycle management of change requests
  • Allowing UI workflows to modify change request details

Testing

  • Tested PATCH endpoint with valid update payloads
  • Verified validation for invalid or unsupported fields
  • Confirmed correct handling of non-existent change request IDs
  • Performed regression testing on related change request endpoints

Impact

  • New endpoint added (non-breaking enhancement)
  • No changes to existing APIs
  • Improves change request lifecycle management

Related PRs

Summary by CodeRabbit

  • New Features
    • Added an endpoint to update change requests by ID, including modifying the planned start date.
    • Introduced a timezone-less date format for planned start dates and a structured update payload/response that returns updated change-request metadata.
  • Improvements
    • Validates authorization and provides detailed handling for unauthorized, forbidden, validation, and server errors.

@coderabbitai

coderabbitai Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 67036d8b-f8c7-40c5-beb2-dba19596225a

📥 Commits

Reviewing files that changed from the base of the PR and between 2366dab and 06f6b4b.

📒 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 new PATCH endpoint to update change requests, new payload/response types for change-request updates, and an entity-layer function that forwards the update to the entity client. Duplicate insertion of the entity update function is present in the entity file.

Changes

Cohort / File(s) Summary
Type Definitions
apps/customer-portal/backend/modules/entity/types.bal
Adds DateTimeWithoutTimezone string type, ChangeRequestUpdatePayload (plannedStartOn), ChangeRequestUpdateResponse (message, changeRequest), and UpdatedChangeRequest (id, updatedOn, updatedBy, json...).
Entity Module
apps/customer-portal/backend/modules/entity/entity.bal
Adds `public isolated function updateChangeRequest(string idToken, string changeRequestId, ChangeRequestUpdatePayload payload) returns ChangeRequestUpdateResponse
Service Endpoint
apps/customer-portal/backend/service.bal
Adds patch change-requests/[entity:IdString id] resource that validates auth, calls entity:updateChangeRequest, maps 401/403/400 errors to HTTP responses, logs unexpected errors, and returns UpdatedChangeRequest on success.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Service as Service (resource)
    participant Entity as Entity Module
    participant EntityClient as Entity Client / External API

    Client->>Service: PATCH /change-requests/{id} + payload + Authorization
    Service->>Service: extract & validate Authorization header
    Service->>Entity: updateChangeRequest(token, id, payload)
    Entity->>EntityClient: PATCH /change-requests/{id} (auth header, payload)
    EntityClient->>EntityClient: external update processing
    EntityClient-->>Entity: 200 OK / 400 / 401 / 403 / error
    Entity-->>Service: ChangeRequestUpdateResponse | error
    Service-->>Client: 200 UpdatedChangeRequest / 400 / 401 / 403 / 500
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • cloby99
  • shayanmalinda
  • sacheeramesh

Poem

🐇 I hopped in with a patch and a cheer,
I nudged plannedStartOn and made things clear,
Tokens checked, updates sent with care,
Change requests dance through the midnight air,
Hooray — swift fixes, carrots to share! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers key sections (Summary, Changes, Endpoint, Reason, Testing, Impact, Related PRs) but lacks several required template sections including Purpose/Goals, Approach, User stories, Release notes, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Migrations, Test environment, and Learning. Complete the PR description by adding missing sections from the template: Purpose with issue links, Goals, Approach, User stories, Release notes, Documentation, Training, Certification, Marketing, Automation tests with coverage details, Security checks, Samples, Migrations, Test environment specifications, and Learning documentation.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a PATCH endpoint for updating change requests in 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.

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

🤖 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/types.bal`:
- Around line 1562-1563: The field comment for plannedStartOn is misleading:
update the comment for the DateTime field plannedStartOn in types.bal to state
that it uses ISO 8601 format (includes the 'T' separator and timezone/offset),
e.g. "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS±HH:MM", so API consumers
know the DateTime format enforced by the DateTime type.
- Around line 1561-1564: The PATCH payload type ChangeRequestUpdatePayload is
currently forcing plannedStartOn as mandatory; change the type to represent a
partial update by making updatable properties optional (e.g., plannedStartOn?:
DateTime) and include any other updatable change-request fields as optional
properties on ChangeRequestUpdatePayload so callers can send only the fields
they want to update; if you want open-ended updates, consider defining
ChangeRequestUpdatePayload as a record with optional properties or a map-like
shape to allow unknown keys.

In `@apps/customer-portal/backend/service.bal`:
- Around line 3168-3215: The handler currently doesn't map a 404 from
entity:updateChangeRequest and will return 500; update the function's return
union to include http:NotFound, add a branch after the BAD_REQUEST check that
checks if getStatusCode(response) == http:STATUS_NOT_FOUND and return
<http:NotFound>{ body: { message: "Change request not found." } }, and ensure
the new branch uses the same response and logging pattern (optionally a
log:printWarn referencing userInfo.userId) so unknown IDs are handled correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e161c0b1-81d0-4816-94d3-c189f1afae3f

📥 Commits

Reviewing files that changed from the base of the PR and between 57a020e and 2366dab.

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

Comment thread apps/customer-portal/backend/modules/entity/types.bal
Comment thread apps/customer-portal/backend/modules/entity/types.bal Outdated
Comment thread apps/customer-portal/backend/service.bal
@Rashmika998
Rashmika998 requested a review from cloby99 March 5, 2026 07:39
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