From f506ea3d5a0f2046698c480cd9c398589c7eca43 Mon Sep 17 00:00:00 2001 From: lan-yonghui Date: Thu, 23 Jan 2025 11:36:40 +0800 Subject: [PATCH] feat: Unify the response body of the API interface --- backend/app/api/v1/app_install.go | 5 +- backend/app/api/v1/php_extensions.go | 7 +- cmd/server/docs/docs.go | 160 ++++++++++++++---- cmd/server/docs/swagger.json | 160 ++++++++++++++---- cmd/server/docs/swagger.yaml | 105 +++++++++--- frontend/src/api/modules/app.ts | 2 +- frontend/src/api/modules/runtime.ts | 2 +- .../website/runtime/php/create/index.vue | 2 +- .../views/website/website/create/index.vue | 4 +- 9 files changed, 356 insertions(+), 91 deletions(-) diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index 8acffb7e0b7b..2bef9e307062 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -28,7 +28,10 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, list) + helper.SuccessWithData(c, dto.PageResult{ + Items: list, + Total: int64(len(list)), + }) } else { total, list, err := appInstallService.Page(req) if err != nil { diff --git a/backend/app/api/v1/php_extensions.go b/backend/app/api/v1/php_extensions.go index 25f928ccbfc5..460c1612f0d8 100644 --- a/backend/app/api/v1/php_extensions.go +++ b/backend/app/api/v1/php_extensions.go @@ -12,7 +12,7 @@ import ( // @Summary Page Extensions // @Accept json // @Param request body request.PHPExtensionsSearch true "request" -// @Success 200 {array} response.PHPExtensionsDTO +// @Success 200 {object} dto.PageResult // @Security ApiKeyAuth // @Security Timestamp // @Router /runtimes/php/extensions/search [post] @@ -27,7 +27,10 @@ func (b *BaseApi) PagePHPExtensions(c *gin.Context) { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, list) + helper.SuccessWithData(c, dto.PageResult{ + Total: int64(len(list)), + Items: list, + }) } else { total, list, err := phpExtensionsService.Page(req) if err != nil { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index eec0c548537d..3ad351f8eedf 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -10013,10 +10013,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/response.PHPExtensionsDTO" - } + "$ref": "#/definitions/dto.PageResult" } } } @@ -15485,6 +15482,59 @@ const docTemplate = `{ } } }, + "/websites/proxies/del": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "consumes": [ + "application/json" + ], + "tags": [ + "Website" + ], + "summary": "Delete proxy conf", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyDel" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id" + ], + "formatEN": "Delete domain [domain] proxy config", + "formatZH": "删除网站 [domain] 反向代理配置", + "paramKeys": [] + } + } + }, "/websites/proxies/update": { "post": { "security": [ @@ -16700,6 +16750,9 @@ const docTemplate = `{ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "$ref": "#/definitions/dto.Locale" + }, "document": { "type": "string" }, @@ -19502,6 +19555,32 @@ const docTemplate = `{ } } }, + "dto.Locale": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ja": { + "type": "string" + }, + "ms": { + "type": "string" + }, + "pt-br": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "zh": { + "type": "string" + }, + "zh-hant": { + "type": "string" + } + } + }, "dto.LogOption": { "type": "object", "properties": { @@ -19545,6 +19624,7 @@ const docTemplate = `{ "en", "tw", "ja", + "ko", "ru", "ms", "pt-BR" @@ -21629,6 +21709,9 @@ const docTemplate = `{ "key": { "type": "string" }, + "locales": { + "$ref": "#/definitions/dto.Locale" + }, "name": { "type": "string" }, @@ -21918,6 +22001,9 @@ const docTemplate = `{ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "type": "string" + }, "document": { "type": "string" }, @@ -22142,6 +22228,9 @@ const docTemplate = `{ "sort": { "type": "integer" }, + "translations": { + "type": "string" + }, "updatedAt": { "type": "string" } @@ -24432,6 +24521,21 @@ const docTemplate = `{ } } }, + "request.WebsiteProxyDel": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "request.WebsiteProxyReq": { "type": "object", "required": [ @@ -24808,6 +24912,9 @@ const docTemplate = `{ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "type": "string" + }, "document": { "type": "string" }, @@ -24977,6 +25084,9 @@ const docTemplate = `{ "response.AppItem": { "type": "object", "properties": { + "description": { + "type": "string" + }, "icon": { "type": "string" }, @@ -24998,19 +25108,13 @@ const docTemplate = `{ "resource": { "type": "string" }, - "shortDescEn": { - "type": "string" - }, - "shortDescZh": { - "type": "string" - }, "status": { "type": "string" }, "tags": { "type": "array", "items": { - "$ref": "#/definitions/model.Tag" + "$ref": "#/definitions/response.TagDTO" } }, "type": { @@ -25492,26 +25596,6 @@ const docTemplate = `{ } } }, - "response.PHPExtensionsDTO": { - "type": "object", - "properties": { - "createdAt": { - "type": "string" - }, - "extensions": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - }, - "updatedAt": { - "type": "string" - } - } - }, "response.PackageScripts": { "type": "object", "properties": { @@ -25638,6 +25722,20 @@ const docTemplate = `{ } } }, + "response.TagDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "response.WebsiteAcmeAccountDTO": { "type": "object", "properties": { diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 6ef34082c2bd..050fffdcebf2 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -10010,10 +10010,7 @@ "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/response.PHPExtensionsDTO" - } + "$ref": "#/definitions/dto.PageResult" } } } @@ -15482,6 +15479,59 @@ } } }, + "/websites/proxies/del": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + }, + { + "Timestamp": [] + } + ], + "consumes": [ + "application/json" + ], + "tags": [ + "Website" + ], + "summary": "Delete proxy conf", + "parameters": [ + { + "description": "request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.WebsiteProxyDel" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "x-panel-log": { + "BeforeFunctions": [ + { + "db": "websites", + "input_column": "id", + "input_value": "id", + "isList": false, + "output_column": "primary_domain", + "output_value": "domain" + } + ], + "bodyKeys": [ + "id" + ], + "formatEN": "Delete domain [domain] proxy config", + "formatZH": "删除网站 [domain] 反向代理配置", + "paramKeys": [] + } + } + }, "/websites/proxies/update": { "post": { "security": [ @@ -16697,6 +16747,9 @@ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "$ref": "#/definitions/dto.Locale" + }, "document": { "type": "string" }, @@ -19499,6 +19552,32 @@ } } }, + "dto.Locale": { + "type": "object", + "properties": { + "en": { + "type": "string" + }, + "ja": { + "type": "string" + }, + "ms": { + "type": "string" + }, + "pt-br": { + "type": "string" + }, + "ru": { + "type": "string" + }, + "zh": { + "type": "string" + }, + "zh-hant": { + "type": "string" + } + } + }, "dto.LogOption": { "type": "object", "properties": { @@ -19542,6 +19621,7 @@ "en", "tw", "ja", + "ko", "ru", "ms", "pt-BR" @@ -21626,6 +21706,9 @@ "key": { "type": "string" }, + "locales": { + "$ref": "#/definitions/dto.Locale" + }, "name": { "type": "string" }, @@ -21915,6 +21998,9 @@ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "type": "string" + }, "document": { "type": "string" }, @@ -22139,6 +22225,9 @@ "sort": { "type": "integer" }, + "translations": { + "type": "string" + }, "updatedAt": { "type": "string" } @@ -24429,6 +24518,21 @@ } } }, + "request.WebsiteProxyDel": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "request.WebsiteProxyReq": { "type": "object", "required": [ @@ -24805,6 +24909,9 @@ "crossVersionUpdate": { "type": "boolean" }, + "description": { + "type": "string" + }, "document": { "type": "string" }, @@ -24974,6 +25081,9 @@ "response.AppItem": { "type": "object", "properties": { + "description": { + "type": "string" + }, "icon": { "type": "string" }, @@ -24995,19 +25105,13 @@ "resource": { "type": "string" }, - "shortDescEn": { - "type": "string" - }, - "shortDescZh": { - "type": "string" - }, "status": { "type": "string" }, "tags": { "type": "array", "items": { - "$ref": "#/definitions/model.Tag" + "$ref": "#/definitions/response.TagDTO" } }, "type": { @@ -25489,26 +25593,6 @@ } } }, - "response.PHPExtensionsDTO": { - "type": "object", - "properties": { - "createdAt": { - "type": "string" - }, - "extensions": { - "type": "string" - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - }, - "updatedAt": { - "type": "string" - } - } - }, "response.PackageScripts": { "type": "object", "properties": { @@ -25635,6 +25719,20 @@ } } }, + "response.TagDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "key": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "response.WebsiteAcmeAccountDTO": { "type": "object", "properties": { diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index cf37274cd279..ab2cc1c2c147 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -102,6 +102,8 @@ definitions: type: array crossVersionUpdate: type: boolean + description: + $ref: '#/definitions/dto.Locale' document: type: string github: @@ -1983,6 +1985,23 @@ definitions: - id - type type: object + dto.Locale: + properties: + en: + type: string + ja: + type: string + ms: + type: string + pt-br: + type: string + ru: + type: string + zh: + type: string + zh-hant: + type: string + type: object dto.LogOption: properties: logMaxFile: @@ -2009,6 +2028,7 @@ definitions: - en - tw - ja + - ko - ru - ms - pt-BR @@ -3429,6 +3449,8 @@ definitions: properties: key: type: string + locales: + $ref: '#/definitions/dto.Locale' name: type: string sort: @@ -3618,6 +3640,8 @@ definitions: type: string crossVersionUpdate: type: boolean + description: + type: string document: type: string github: @@ -3766,6 +3790,8 @@ definitions: type: string sort: type: integer + translations: + type: string updatedAt: type: string type: object @@ -5303,6 +5329,16 @@ definitions: - proxyHost - proxyPass type: object + request.WebsiteProxyDel: + properties: + id: + type: integer + name: + type: string + required: + - id + - name + type: object request.WebsiteProxyReq: properties: id: @@ -5556,6 +5592,8 @@ definitions: type: string crossVersionUpdate: type: boolean + description: + type: string document: type: string github: @@ -5668,6 +5706,8 @@ definitions: type: object response.AppItem: properties: + description: + type: string icon: type: string id: @@ -5682,15 +5722,11 @@ definitions: type: string resource: type: string - shortDescEn: - type: string - shortDescZh: - type: string status: type: string tags: items: - $ref: '#/definitions/model.Tag' + $ref: '#/definitions/response.TagDTO' type: array type: type: string @@ -6005,19 +6041,6 @@ definitions: uploadMaxSize: type: string type: object - response.PHPExtensionsDTO: - properties: - createdAt: - type: string - extensions: - type: string - id: - type: integer - name: - type: string - updatedAt: - type: string - type: object response.PackageScripts: properties: name: @@ -6101,6 +6124,15 @@ definitions: user: type: string type: object + response.TagDTO: + properties: + id: + type: integer + key: + type: string + name: + type: string + type: object response.WebsiteAcmeAccountDTO: properties: createdAt: @@ -12427,9 +12459,7 @@ paths: "200": description: OK schema: - items: - $ref: '#/definitions/response.PHPExtensionsDTO' - type: array + $ref: '#/definitions/dto.PageResult' security: - ApiKeyAuth: [] - Timestamp: [] @@ -15816,6 +15846,39 @@ paths: summary: Get proxy conf tags: - Website + /websites/proxies/del: + post: + consumes: + - application/json + parameters: + - description: request + in: body + name: request + required: true + schema: + $ref: '#/definitions/request.WebsiteProxyDel' + responses: + "200": + description: OK + security: + - ApiKeyAuth: [] + - Timestamp: [] + summary: Delete proxy conf + tags: + - Website + x-panel-log: + BeforeFunctions: + - db: websites + input_column: id + input_value: id + isList: false + output_column: primary_domain + output_value: domain + bodyKeys: + - id + formatEN: Delete domain [domain] proxy config + formatZH: 删除网站 [domain] 反向代理配置 + paramKeys: [] /websites/proxies/update: post: consumes: diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index f337b992089a..22689d07cffc 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -64,7 +64,7 @@ export const AppInstalledDeleteCheck = (appInstallId: number) => { }; export const GetAppInstalled = (search: App.AppInstalledSearch) => { - return http.post('apps/installed/search', search); + return http.post>('apps/installed/search', search); }; export const InstalledOp = (op: App.AppInstalledOp) => { diff --git a/frontend/src/api/modules/runtime.ts b/frontend/src/api/modules/runtime.ts index 2f6dd775f7a3..48d59f5b599d 100644 --- a/frontend/src/api/modules/runtime.ts +++ b/frontend/src/api/modules/runtime.ts @@ -49,7 +49,7 @@ export const SearchPHPExtensions = (req: ReqPage) => { }; export const ListPHPExtensions = (req: Runtime.PHPExtensionsList) => { - return http.post(`/runtimes/php/extensions/search`, req); + return http.post>(`/runtimes/php/extensions/search`, req); }; export const CreatePHPExtensions = (req: Runtime.PHPExtensionsCreate) => { diff --git a/frontend/src/views/website/runtime/php/create/index.vue b/frontend/src/views/website/runtime/php/create/index.vue index 00a78cdaf570..b185a20f037c 100644 --- a/frontend/src/views/website/runtime/php/create/index.vue +++ b/frontend/src/views/website/runtime/php/create/index.vue @@ -396,7 +396,7 @@ const listPHPExtensions = async () => { page: 1, pageSize: 100, }); - phpExtensions.value = res.data; + phpExtensions.value = res.data.items; } catch (error) {} }; diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue index b9ce7f6cf95c..ce187ae114bd 100644 --- a/frontend/src/views/website/website/create/index.vue +++ b/frontend/src/views/website/website/create/index.vue @@ -505,8 +505,8 @@ const changeType = (type: string) => { const searchAppInstalled = () => { GetAppInstalled({ type: 'website', unused: true, all: true, page: 1, pageSize: 100 }).then((res) => { - appInstalls.value = res.data; - if (res.data && res.data.length > 0) { + appInstalls.value = res.data.items; + if (res.data.items && res.data.items.length > 0) { website.value.appInstallId = res.data[0].id; } });