Skip to content

Commit

Permalink
Revamp devportal-api yaml with new scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
chashikajw committed Oct 9, 2023
1 parent 08956e8 commit 61bc681
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 940 deletions.
21 changes: 0 additions & 21 deletions backoffice/backoffice-domain-service/ballerina/BusinessPlan.bal

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ service http:InterceptableService /api/backoffice on ep0 {
http:Interceptor[] interceptors = [jwtValidationInterceptor, requestErrorInterceptor, responseErrorInterceptor];
return interceptors;
}
isolated resource function get apis(http:RequestContext requestContext, string? query, @http:Header string? 'if\-none\-match, int 'limit = 25, int offset = 0, string sortBy = "createdTime", string sortOrder = "desc", @http:Header string? accept = "application/json") returns APIList|http:NotModified|commons:APKError {
isolated resource function get apis(http:RequestContext requestContext, string? query, @http:Header string? 'if\-none\-match, int 'limit = 25, int offset = 0, "apiName"|"version"|"createdTime"|"status" sortBy = "createdTime", string sortOrder = "desc", @http:Header string? accept = "application/json") returns APIList|http:NotModified|commons:APKError {
commons:UserContext authenticatedUserContext = check commons:getAuthenticatedUserContext(requestContext);
commons:Organization organization = authenticatedUserContext.organization;
return getAPIList('limit, offset, query, organization.uuid);
Expand All @@ -66,8 +66,6 @@ service http:InterceptableService /api/backoffice on ep0 {
}
return apiDefinition;
}
// resource function get apis/[string apiId]/'resource\-paths(@http:Header string? 'if\-none\-match, int 'limit = 25, int offset = 0) returns ResourcePathList|http:NotModified|NotFoundError|NotAcceptableError {
// }
isolated resource function get apis/[string apiId]/thumbnail(@http:Header string? 'if\-none\-match, @http:Header string? accept = "application/json") returns http:Response|http:NotModified|NotFoundError|NotAcceptableError|commons:APKError {
return getThumbnail(apiId);
}
Expand All @@ -77,18 +75,11 @@ service http:InterceptableService /api/backoffice on ep0 {
resource function get apis/[string apiId]/documents(@http:Header string? 'if\-none\-match, int 'limit = 25, int offset = 0, @http:Header string? accept = "application/json") returns DocumentList|http:NotModified|NotFoundError|NotAcceptableError|commons:APKError {
return getDocumentList(apiId, 'limit, offset);
}
isolated resource function post apis/[string apiId]/documents(@http:Payload Document payload) returns CreatedDocument|BadRequestError|UnsupportedMediaTypeError|commons:APKError|error {
isolated resource function post apis/[string apiId]/documents(@http:Payload Document payload) returns Document|BadRequestError|UnsupportedMediaTypeError|commons:APKError|error {
Document documentBody = check payload.cloneWithType(Document);

Document|commons:APKError createdDocument = createDocument(apiId, documentBody);
if createdDocument is Document {
CreatedDocument createdDoc = {
body: createdDocument
};
return createdDoc;
} else {
return createdDocument;
}
return createdDocument;
}
resource function get apis/[string apiId]/documents/[string documentId](@http:Header string? 'if\-none\-match, @http:Header string? accept = "application/json") returns Document|http:NotModified|NotFoundError|NotAcceptableError|commons:APKError {
return getDocumentMetaData(apiId, documentId);
Expand Down Expand Up @@ -174,13 +165,4 @@ service http:InterceptableService /api/backoffice on ep0 {
return error("Error while getting LC state of API" + currentState.message());
}
}
resource function get 'business\-plans(http:RequestContext requestContext, @http:Header string? accept = "application/json") returns BusinessPlanList|commons:APKError {
commons:UserContext authenticatedUserContext = check commons:getAuthenticatedUserContext(requestContext);
commons:Organization organization = authenticatedUserContext.organization;
BusinessPlanList|commons:APKError subPolicyList = getBusinessPlans(organization.uuid);
if subPolicyList is BusinessPlanList {
log:printDebug(subPolicyList.toString());
}
return subPolicyList;
}
}
91 changes: 8 additions & 83 deletions backoffice/backoffice-domain-service/ballerina/backoffice_dao.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ballerina/io;
import wso2/apk_common_lib as commons;
import ballerina/log;

isolated function db_getAPIsDAO(string organization) returns API[]|commons:APKError {
isolated function db_getAPIsDAO(string organization) returns APIInfo[]|commons:APKError {
postgresql:Client|error db_Client = getConnection();
if db_Client is error {
return e909601(db_Client);
Expand All @@ -32,8 +32,8 @@ isolated function db_getAPIsDAO(string organization) returns API[]|commons:APKEr
sql:ParameterizedQuery GET_API = `SELECT UUID AS ID,
API_NAME as NAME, API_VERSION as VERSION,CONTEXT, ORGANIZATION, STATUS as STATE, string_to_array(SDK::text,',')::text[] AS SDK,string_to_array(API_TIER::text,',') AS POLICIES, ARTIFACT as ARTIFACT
FROM API where ORGANIZATION = ${organization}`;
stream<API, sql:Error?> apisStream = db_Client->query(GET_API);
API[] apis = check from API api in apisStream
stream<APIInfo, sql:Error?> apisStream = db_Client->query(GET_API);
APIInfo[] apis = check from APIInfo api in apisStream
select api;
check apisStream.close();
return apis;
Expand Down Expand Up @@ -159,9 +159,9 @@ isolated function db_getSubscriptionsForAPI(string apiId) returns Subscription[]
Subscription[] subsList = [];
check from Subscriptions subitem in result1
do {
Subscription sub = {applicationInfo: {}, subscriptionId: "", subscriptionStatus: "", usagePlan: ""};
Subscription sub = {applicationInfo: {}, subscriptionId: "", subscriptionStatus: <"BLOCKED"|"PROD_ONLY_BLOCKED"|"UNBLOCKED"|"ON_HOLD"|"REJECTED"|"TIER_UPDATE_PENDING"|"DELETE_PENDING">"", usagePlan: ""};
sub.subscriptionId = subitem.subscriptionId;
sub.subscriptionStatus = subitem.subscriptionStatus;
sub.subscriptionStatus = <"BLOCKED"|"PROD_ONLY_BLOCKED"|"UNBLOCKED"|"ON_HOLD"|"REJECTED"|"TIER_UPDATE_PENDING"|"DELETE_PENDING">subitem.subscriptionStatus;
sub.applicationInfo.applicationId = subitem.applicationId;
sub.usagePlan = subitem.usagePlan;
sub.applicationInfo.name = subitem.name;
Expand Down Expand Up @@ -332,7 +332,7 @@ isolated function getAPICategoriesDAO(string org) returns APICategory[]|commons:
}
}

isolated function getAPIsByQueryDAO(string payload, string org) returns API[]|commons:APKError {
isolated function getAPIsByQueryDAO(string payload, string org) returns APIInfo[]|commons:APKError {
postgresql:Client|error dbClient = getConnection();
if dbClient is error {
return e909601(dbClient);
Expand All @@ -342,8 +342,8 @@ isolated function getAPIsByQueryDAO(string payload, string org) returns API[]|co
API_NAME as NAME, API_VERSION as VERSION,CONTEXT, ORGANIZATION,STATUS,
ARTIFACT as ARTIFACT FROM API JOIN JSONB_EACH_TEXT(ARTIFACT) e ON true
WHERE e.value LIKE ${payload} AND ORGANIZATION = ${org}`;
stream<API, sql:Error?> apisStream = dbClient->query(query);
API[] apis = check from API api in apisStream
stream<APIInfo, sql:Error?> apisStream = dbClient->query(query);
APIInfo[] apis = check from APIInfo api in apisStream
select api;
check apisStream.close();
return apis;
Expand All @@ -354,81 +354,6 @@ isolated function getAPIsByQueryDAO(string payload, string org) returns API[]|co
}
}

public isolated function getBusinessPlansDAO(string org) returns BusinessPlan[]|commons:APKError {
postgresql:Client|error dbClient = getConnection();
if dbClient is error {
return e909601(dbClient);
} else {
do {
sql:ParameterizedQuery query = `SELECT NAME as PLANNAME, DISPLAY_NAME as DISPLAYNAME, DESCRIPTION,
UUID as PLANID, IS_DEPLOYED as ISDEPLOYED,
QUOTA_TYPE as DefaulLimitType, QUOTA , TIME_UNIT as TIMEUNIT, UNIT_TIME as
UNITTIME, RATE_LIMIT_COUNT as RATELIMITCOUNT, RATE_LIMIT_TIME_UNIT as RATELIMITTIMEUNIT FROM BUSINESS_PLAN WHERE ORGANIZATION =${org}`;
stream<BusinessPlanDAO, sql:Error?> businessPlanStream = dbClient->query(query);
BusinessPlanDAO[] businessPlansDAO = check from BusinessPlanDAO businessPlan in businessPlanStream
select businessPlan;
check businessPlanStream.close();
BusinessPlan[] businessPlans = [];
if businessPlansDAO is BusinessPlanDAO[] {
foreach BusinessPlanDAO result in businessPlansDAO {
if result.defaulLimitType == "requestCount" {
BusinessPlan bp = {
planName: result.planName,
displayName: result.displayName,
description: result.description,
planId: result.planId,
isDeployed: result.isDeployed,
rateLimitCount: result.rateLimitCount,
rateLimitTimeUnit: result.rateLimitTimeUnit,
defaultLimit: {
'type: result.defaulLimitType,
requestCount:
{requestCount: result.quota, timeUnit: result.timeUnit, unitTime: result.unitTime}
}
};
businessPlans.push(bp);
} else if result.defaulLimitType == "bandwidth" {
BusinessPlan bp = {
planName: result.planName,
displayName: result.displayName,
description: result.description,
planId: result.planId,
isDeployed: result.isDeployed,
rateLimitCount: result.rateLimitCount,
rateLimitTimeUnit: result.rateLimitTimeUnit,
defaultLimit: {
'type: result.defaulLimitType,
bandwidth:
{dataAmount: result.quota, dataUnit: <string>result.dataUnit, timeUnit: result.timeUnit, unitTime: result.unitTime}
}
};
businessPlans.push(bp);
} else {
BusinessPlan bp = {
planName: result.planName,
displayName: result.displayName,
description: result.description,
planId: result.planId,
isDeployed: result.isDeployed,
rateLimitCount: result.rateLimitCount,
rateLimitTimeUnit: result.rateLimitTimeUnit,
defaultLimit: {
'type: result.defaulLimitType,
eventCount:
{eventCount: result.quota, timeUnit: result.timeUnit, unitTime: result.unitTime}
}
};
businessPlans.push(bp);
}
}
}
return businessPlans;
} on fail var e {
return e909620(e);
}
}
}

isolated function db_getResourceByResourceCategory(string apiId, int resourceCategoryId) returns Resource|NotFoundError|commons:APKError {
postgresql:Client|error db_Client = getConnection();
if db_Client is error {
Expand Down
Loading

0 comments on commit 61bc681

Please sign in to comment.