[Customer portal][BE] Add PATCH endpoint to update change request - #298
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
apps/customer-portal/backend/modules/entity/entity.balapps/customer-portal/backend/modules/entity/types.balapps/customer-portal/backend/service.bal
1d01652
into
wso2-open-operations:customer-portal-milestone-1
Summary
This PR introduces a PATCH endpoint to update existing change requests.
Changes
Endpoint
PATCH
/change-requests/{changeRequestId}Reason
Previously, change requests could not be updated via API once created.
This endpoint enables:
Testing
Impact
Related PRs
Summary by CodeRabbit