Skip to content
2 changes: 2 additions & 0 deletions apps/customer-portal/backend/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ public const int DEFAULT_LIMIT = 10;

public const ERR_STATUS_CODE = "statusCode";
public const ERR_BODY = "body";

public const STATE_OPEN = "Open";
8 changes: 7 additions & 1 deletion apps/customer-portal/backend/modules/entity/entity.bal
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ public isolated function getProjectActivityStats(string idToken, string id) retu
#
# + idToken - ID token for authorization
# + id - Unique ID of the project
# + caseTypes - Optional array of case types to filter statistics
# + return - Project cases statistics or error
public isolated function getCaseStatsForProject(string idToken, string id) returns ProjectCaseStatsResponse|error {
public isolated function getCaseStatsForProject(string idToken, string id, string[]? caseTypes)
returns ProjectCaseStatsResponse|error {

if caseTypes is string[] {
return csEntityClient->/projects/[id]/cases/stats.get(generateHeaders(idToken), caseTypes = caseTypes);
}
return csEntityClient->/projects/[id]/cases/stats.get(generateHeaders(idToken));
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved

Expand Down
27 changes: 20 additions & 7 deletions apps/customer-portal/backend/modules/entity/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ public type ReferenceTableItem record {|
public type CaseSearchFilters record {|
# List of project IDs to filter
string[] projectIds?;
# List of case type IDs to filter
string[] caseTypeIds?;
# Search query for case number, title and description
string searchQuery?;
# List of issue types to filter
int[] issueTypeKeys?;
# State key
int stateKey?;
int[] stateKeys?;
# Severity key
int severityKey?;
# Deployment ID
Expand Down Expand Up @@ -362,20 +364,31 @@ public type ResolvedCaseCount record {|
json...;
|};

# Count of a specific item with its ID (State, severity, etc.)
public type CountItem record {|
# ID of the item
int id;
# Count value
int count;
json...;
|};

# Project cases statistics response.
public type ProjectCaseStatsResponse record {|
# Total case count
int totalCount;
# Open case count
int openCount;
# Average response time
decimal averageResponseTime;
# Active case count breakdown
ActiveCaseCount activeCount;
# Outstanding cases count breakdown
OutstandingCasesCount outstandingCasesCount;
# Resolved case count breakdown
ResolvedCaseCount resolvedCount;
# Count of cases by state
map<CountItem> stateCount;
# Count of cases by severity
map<CountItem> severityCount;
# Outstanding cases count by severity
map<CountItem> outstandingSeverityCount;
# Cases trend by quarter and week
map<map<CountItem>> casesTrend;
json...;
|};

Expand Down
18 changes: 12 additions & 6 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public type CaseSearchFilters record {|
string searchQuery?;
# Issue ID
int issueId?;
# Status ID
int statusId?;
# Status IDs
int[] statusIds?;
# List of case type IDs
string[] caseTypeIds?;
# Severity ID
int severityId?;
# Deployment ID
Expand Down Expand Up @@ -161,12 +163,16 @@ public type ProjectCaseStats record {|
int openCases;
# Average response time
decimal averageResponseTime;
# Active case count breakdown
entity:ActiveCaseCount activeCases;
# Outstanding cases count breakdown
entity:OutstandingCasesCount outstandingCases;
# Resolved case count breakdown
entity:ResolvedCaseCount resolvedCases;
# Count of cases by state
map<entity:CountItem> stateCount;
# Count of cases by severity
map<entity:CountItem> severityCount;
# Outstanding cases count by severity
map<entity:CountItem> outstandingSeverityCount;
# Cases trend by quarter and week
map<map<entity:CountItem>> casesTrend;
|};

# Project support statistics.
Expand Down
25 changes: 15 additions & 10 deletions apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ service http:InterceptableService / on new http:Listener(9090) {
#
# + id - ID of the project
# + return - Project statistics response or error
resource function get projects/[string id]/stats(http:RequestContext ctx)
resource function get projects/[string id]/stats(http:RequestContext ctx, string[]? caseTypes)
returns types:ProjectStatsResponse|http:BadRequest|http:Unauthorized|http:Forbidden|http:InternalServerError {

authorization:UserInfoPayload|error userInfo = ctx.getWithType(authorization:HEADER_USER_INFO);
Expand Down Expand Up @@ -438,7 +438,8 @@ service http:InterceptableService / on new http:Listener(9090) {
}

// Fetch case stats
entity:ProjectCaseStatsResponse|error caseStats = entity:getCaseStatsForProject(userInfo.idToken, id);
entity:ProjectCaseStatsResponse|error caseStats =
entity:getCaseStatsForProject(userInfo.idToken, id, caseTypes);
if caseStats is error {
string customError = "Failed to retrieve project case statistics.";
log:printError(customError, caseStats);
Expand Down Expand Up @@ -488,7 +489,7 @@ service http:InterceptableService / on new http:Listener(9090) {

return {
projectStats: {
openCases: caseStats.openCount,
openCases: caseStats.stateCount.get(STATE_OPEN).count,
activeChats: chatStats.activeCount,
deployments: deploymentStats.totalCount,
slaStatus: projectActivityStats.slaStatus
Expand All @@ -506,7 +507,7 @@ service http:InterceptableService / on new http:Listener(9090) {
#
# + id - ID of the project
# + return - Project statistics overview or error response
resource function get projects/[string id]/stats/cases(http:RequestContext ctx)
resource function get projects/[string id]/stats/cases(http:RequestContext ctx, string[]? caseTypes)
returns types:ProjectCaseStats|http:BadRequest|http:Unauthorized|http:Forbidden|http:InternalServerError {

authorization:UserInfoPayload|error userInfo = ctx.getWithType(authorization:HEADER_USER_INFO);
Expand Down Expand Up @@ -547,7 +548,8 @@ service http:InterceptableService / on new http:Listener(9090) {
};
}

entity:ProjectCaseStatsResponse|error caseStats = entity:getCaseStatsForProject(userInfo.idToken, id);
entity:ProjectCaseStatsResponse|error caseStats =
entity:getCaseStatsForProject(userInfo.idToken, id, caseTypes);
if caseStats is error {
string customError = "Failed to retrieve project case statistics.";
log:printError(customError, caseStats);
Expand All @@ -560,19 +562,21 @@ service http:InterceptableService / on new http:Listener(9090) {

return {
totalCases: caseStats.totalCount,
openCases: caseStats.openCount,
openCases: caseStats.stateCount.get(STATE_OPEN).count,
averageResponseTime: caseStats.averageResponseTime,
activeCases: caseStats.activeCount,
resolvedCases: caseStats.resolvedCount,
outstandingCases: caseStats.outstandingCasesCount
stateCount: caseStats.stateCount,
severityCount: caseStats.severityCount,
outstandingSeverityCount: caseStats.outstandingSeverityCount,
casesTrend: caseStats.casesTrend
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

# Get project support statistics by ID.
#
# + id - ID of the project
# + return - Project support statistics or error response
resource function get projects/[string id]/stats/support(http:RequestContext ctx)
resource function get projects/[string id]/stats/support(http:RequestContext ctx, string[]? caseTypes)
returns types:ProjectSupportStats|http:BadRequest|http:Unauthorized|http:Forbidden|http:InternalServerError {

authorization:UserInfoPayload|error userInfo = ctx.getWithType(authorization:HEADER_USER_INFO);
Expand Down Expand Up @@ -614,7 +618,8 @@ service http:InterceptableService / on new http:Listener(9090) {
}

// Fetch case stats
entity:ProjectCaseStatsResponse|error caseStats = entity:getCaseStatsForProject(userInfo.idToken, id);
entity:ProjectCaseStatsResponse|error caseStats =
entity:getCaseStatsForProject(userInfo.idToken, id, caseTypes);
if caseStats is error {
string customError = "Failed to retrieve project case statistics.";
log:printError(customError, caseStats);
Expand Down
3 changes: 2 additions & 1 deletion apps/customer-portal/backend/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public isolated function searchCases(string idToken, string projectId, types:Cas
searchQuery: payload.filters?.searchQuery,
issueTypeKeys: issueId != () ? [issueId] : (),
severityKey: payload.filters?.severityId,
stateKey: payload.filters?.statusId,
caseTypeIds: payload.filters?.caseTypeIds,
stateKeys: payload.filters?.statusIds,
deploymentId: payload.filters?.deploymentId
},
pagination: payload.pagination,
Expand Down