Repository navigation
[Customer Portal][BE] Add case create endpoint and update case response #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,6 +634,57 @@ service http:InterceptableService / on new http:Listener(9090) { | |
| return caseResponse; | ||
| } | ||
|
|
||
| # Add a new case. | ||
|
Rashmika998 marked this conversation as resolved.
Resolved
|
||
| # | ||
| # + payload - Case creation payload | ||
| # + return - Success message or error response | ||
| resource function post cases(http:RequestContext ctx, entity:CaseCreatePayload payload) | ||
| returns http:Created|http:BadRequest|http:Unauthorized|http:Forbidden|http:InternalServerError { | ||
|
|
||
| authorization:UserInfoPayload|error userInfo = ctx.getWithType(authorization:HEADER_USER_INFO); | ||
| if userInfo is error { | ||
| return <http:InternalServerError>{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We (@shayanmalinda, @sacheeramesh, and I) already had a discussion in the past about whether this should return Should we revisit this? I also personally believe this should be a Adding @yuk7hi and @kasunsiyambalapitiya as well
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, If this attribute is missing, or if there is an issue deriving it in Authorization is handled at the gateway level, not by the backend service.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @shayanmalinda. Agree that One clarification here is that this behavior is specific to our setup. In Choreo, the gateway validates the This conversion is platform-specific and not something all API gateways do by default. Because of this, the backend currently depends on this contract with the gateway. If We can add a comment in the interceptor to document this dependency on the gateway behavior, so it’s clear why this is treated as an internal error and mapped accordingly. However I believe I need to fix the error returned when the custom header(
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have a seperate revisit on this later. Will approve the PR due to the urgency. |
||
| body: { | ||
| message: ERR_MSG_USER_INFO_HEADER_NOT_FOUND | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think returning
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we have an offline discussion regarding this? Anyway the fix will be in a separate PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, +1 |
||
| } | ||
| }; | ||
| } | ||
|
|
||
| entity:CaseCreateResponse|error createdCaseResponse = entity:addCase(userInfo.idToken, payload); | ||
| if createdCaseResponse is error { | ||
| if getStatusCode(createdCaseResponse) == http:STATUS_UNAUTHORIZED { | ||
| log:printWarn(string `User: ${userInfo.userId} is not authorized to access the customer portal!`); | ||
| return <http:Unauthorized>{ | ||
|
shayanmalinda marked this conversation as resolved.
Resolved
|
||
| body: { | ||
| message: ERR_MSG_UNAUTHORIZED_ACCESS | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| if getStatusCode(createdCaseResponse) == http:STATUS_FORBIDDEN { | ||
| log:printWarn(string `User: ${userInfo.userId} is forbidden to create a case for project: ${ | ||
| payload.projectId}!`); | ||
| return <http:Forbidden>{ | ||
| body: { | ||
| message: "You're not authorized to create a case for the selected project. " + | ||
| "Please check your access permissions or contact support." | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| string customError = "Failed to create a new case."; | ||
| log:printError(customError, createdCaseResponse); | ||
| return <http:InternalServerError>{ | ||
| body: { | ||
| message: customError | ||
| } | ||
| }; | ||
| } | ||
| return <http:Created>{ | ||
| body: createdCaseResponse.case | ||
| }; | ||
| } | ||
|
|
||
| # Search cases for a specific project with filters and pagination. | ||
| # | ||
| # + id - ID of the project | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.