Skip to content
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

fix(web): update app state api & rules add api #1184

Merged
merged 3 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/.swagger.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = [
{
swaggerPath: "http://api.dev.laf.run/-json",
swaggerPath: "http://api.maslow-dev.lafyun.com/-json",
typingFileName: "api-auto.d.ts",

outDir: "src/apis/v1",
Expand Down
2 changes: 1 addition & 1 deletion web/src/apis/v1/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function AccountControllerCharge(
params: Definitions.CreateChargeOrderDto | any,
): Promise<{
error: string;
data: Paths.AccountControllerCharge.Responses;
data: Definitions.CreateChargeOrderOutDto;
}> {
// /v1/accounts/charge-order
let _params: { [key: string]: any } = {
Expand Down
128 changes: 119 additions & 9 deletions web/src/apis/v1/api-auto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,40 @@ declare namespace Definitions {
state?: string;
regionId?: string;
runtimeId?: string;
isTrialTier?: boolean;
};

export type UpdateApplicationDto = {
export type ApplicationWithRelations = {
_id?: string;
name?: string;
appid?: string;
regionId?: string;
runtimeId?: string;
tags?: string[];
state?: string;
phase?: string;
createdAt?: string;
updatedAt?: string;
createdBy?: string;
region?: Definitions.Region;
bundle?: Definitions.ApplicationBundle;
runtime?: Definitions.Runtime;
configuration?: Definitions.ApplicationConfiguration;
domain?: Definitions.RuntimeDomain;
};

export type Application = {
_id?: string;
name?: string;
appid?: string;
regionId?: string;
runtimeId?: string;
tags?: string[];
state?: string;
phase?: string;
createdAt?: string;
updatedAt?: string;
createdBy?: string;
};

export type UpdateApplicationNameDto = {
Expand All @@ -50,6 +79,15 @@ declare namespace Definitions {
storageCapacity?: number;
};

export type ApplicationBundle = {
_id?: string;
appid?: string;
resource?: Definitions.ApplicationBundleResource;
isTrialTier?: boolean;
createdAt?: string;
updatedAt?: string;
};

export type CreateEnvironmentDto = {
name?: string;
value?: string;
Expand Down Expand Up @@ -127,6 +165,11 @@ declare namespace Definitions {
currency?: string;
};

export type CreateChargeOrderOutDto = {
order?: Definitions.AccountChargeOrder;
result?: Definitions.WeChatPaymentCreateOrderResult;
};

export type CreateWebsiteDto = {
bucketName?: string;
state?: string;
Expand Down Expand Up @@ -232,6 +275,81 @@ declare namespace Definitions {
storageCapacity?: number;
};

export type CalculatePriceResultDto = {
cpu?: number;
memory?: number;
storageCapacity?: number;
databaseCapacity?: number;
total?: number;
};

export type Region = {
_id?: string;
name?: string;
displayName?: string;
tls?: boolean;
state?: string;
createdAt?: string;
updatedAt?: string;
};

export type ApplicationBundleResource = {
limitCPU?: number;
limitMemory?: number;
databaseCapacity?: number;
storageCapacity?: number;
limitCountOfCloudFunction?: number;
limitCountOfBucket?: number;
limitCountOfDatabasePolicy?: number;
limitCountOfTrigger?: number;
limitCountOfWebsiteHosting?: number;
reservedTimeAfterExpired?: number;
};

export type Runtime = {
_id?: string;
name?: string;
type?: string;
image?: Definitions.RuntimeImageGroup;
state?: string;
version?: string;
latest?: boolean;
};

export type RuntimeImageGroup = {
main?: string;
init?: string;
sidecar?: string;
};

export type ApplicationConfiguration = {
_id?: string;
appid?: string;
environments?: Definitions.EnvironmentVariable[];
dependencies?: string[];
createdAt?: string;
updatedAt?: string;
};

export type EnvironmentVariable = {
name?: string;
value?: string;
};

export type RuntimeDomain = {
_id?: string;
appid?: string;
domain?: string;
state?: string;
phase?: string;
createdAt?: string;
updatedAt?: string;
};

export type WeChatPaymentCreateOrderResult = {
code_url?: string;
};

export type UserProfile = {
_id?: string;
uid?: string;
Expand Down Expand Up @@ -345,14 +463,6 @@ declare namespace Paths {
export type Responses = any;
}

namespace ApplicationControllerUpdate {
export type QueryParameters = any;

export type BodyParameters = Definitions.UpdateApplicationDto;

export type Responses = any;
}

namespace ApplicationControllerUpdateName {
export type QueryParameters = any;

Expand Down
30 changes: 5 additions & 25 deletions web/src/apis/v1/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function ApplicationControllerCreate(
params: Definitions.CreateApplicationDto | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerCreate.Responses;
data: Definitions.ApplicationWithRelations;
}> {
// /v1/applications
let _params: { [key: string]: any } = {
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function ApplicationControllerDelete(
params: Paths.ApplicationControllerDelete.BodyParameters | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerDelete.Responses;
data: Definitions.Application;
}> {
// /v1/applications/{appid}
let _params: { [key: string]: any } = {
Expand All @@ -90,34 +90,14 @@ export async function ApplicationControllerDelete(
});
}

/**
* Update an application
*/
export async function ApplicationControllerUpdate(
params: Definitions.UpdateApplicationDto | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerUpdate.Responses;
}> {
// /v1/applications/{appid}
let _params: { [key: string]: any } = {
appid: useGlobalStore.getState().currentApp?.appid || "",
...params,
};
return request(`/v1/applications/${_params.appid}`, {
method: "PATCH",
data: params,
});
}

/**
* Update application name
*/
export async function ApplicationControllerUpdateName(
params: Definitions.UpdateApplicationNameDto | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerUpdateName.Responses;
data: Definitions.Application;
}> {
// /v1/applications/{appid}/name
let _params: { [key: string]: any } = {
Expand All @@ -137,7 +117,7 @@ export async function ApplicationControllerUpdateState(
params: Definitions.UpdateApplicationStateDto | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerUpdateState.Responses;
data: Definitions.Application;
}> {
// /v1/applications/{appid}/state
let _params: { [key: string]: any } = {
Expand All @@ -157,7 +137,7 @@ export async function ApplicationControllerUpdateBundle(
params: Definitions.UpdateApplicationBundleDto | any,
): Promise<{
error: string;
data: Paths.ApplicationControllerUpdateBundle.Responses;
data: Definitions.ApplicationBundle;
}> {
// /v1/applications/{appid}/bundle
let _params: { [key: string]: any } = {
Expand Down
2 changes: 1 addition & 1 deletion web/src/apis/v1/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function ResourceControllerCalculatePrice(
params: Definitions.CalculatePriceDto | any,
): Promise<{
error: string;
data: Paths.ResourceControllerCalculatePrice.Responses;
data: Definitions.CalculatePriceResultDto;
}> {
// /v1/resources/price
let _params: { [key: string]: any } = {
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/ChargeButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default function ChargeButton(props: { amount?: number; children: React.R
["AccountControllerGetChargeOrder"],
() =>
AccountControllerGetChargeOrder({
id: createOrderRes?.data?.order?.id,
id: createOrderRes?.data?.order?._id,
}),
{
enabled: !!createOrderRes?.data?.order?.id && isOpen,
enabled: !!createOrderRes?.data?.order?._id && isOpen,
refetchInterval: phaseStatus === "Pending" && isOpen ? 1000 : false,
onSuccess: (res) => {
setPhaseStatus(res?.data?.phase);
Expand Down
Loading