From 2b89a8ddff724b7d6377003a90a9fa7e43cb3b97 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Wed, 8 Feb 2023 17:09:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E6=94=B9=E4=B8=BA=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app.go | 12 +++++----- backend/app/api/v1/helper/helper.go | 8 +++++++ backend/app/service/app.go | 4 ++-- backend/router/ro_app.go | 2 +- frontend/src/api/modules/app.ts | 4 ++-- frontend/src/routers/modules/app-store.ts | 10 +++++++++ frontend/src/views/app-store/apps/index.vue | 8 +++---- frontend/src/views/app-store/detail/index.vue | 22 ++++++++++--------- .../views/app-store/detail/params/index.vue | 14 ++++-------- .../views/website/website/create/index.vue | 18 +++------------ 10 files changed, 52 insertions(+), 50 deletions(-) diff --git a/backend/app/api/v1/app.go b/backend/app/api/v1/app.go index 90f065b2b..4fa7fe3dd 100644 --- a/backend/app/api/v1/app.go +++ b/backend/app/api/v1/app.go @@ -45,20 +45,20 @@ func (b *BaseApi) SyncApp(c *gin.Context) { } // @Tags App -// @Summary Search app by id -// @Description 通过 id 获取应用信息 +// @Summary Search app by key +// @Description 通过 key 获取应用信息 // @Accept json -// @Param id path integer true "app id" +// @Param key path string true "app key" // @Success 200 {object} response.AppDTO // @Security ApiKeyAuth -// @Router /apps/:id [get] +// @Router /apps/:key [get] func (b *BaseApi) GetApp(c *gin.Context) { - id, err := helper.GetParamID(c) + appKey, err := helper.GetStrParamByKey(c, "key") if err != nil { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) return } - appDTO, err := appService.GetApp(id) + appDTO, err := appService.GetApp(appKey) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return diff --git a/backend/app/api/v1/helper/helper.go b/backend/app/api/v1/helper/helper.go index 630b6ca73..f576268dc 100644 --- a/backend/app/api/v1/helper/helper.go +++ b/backend/app/api/v1/helper/helper.go @@ -111,6 +111,14 @@ func GetIntParamByKey(c *gin.Context, key string) (uint, error) { return uint(intNum), nil } +func GetStrParamByKey(c *gin.Context, key string) (string, error) { + idParam, ok := c.Params.Get(key) + if !ok { + return "", fmt.Errorf("error %s in path", key) + } + return idParam, nil +} + func GetTxAndContext() (tx *gorm.DB, ctx context.Context) { tx = global.DB.Begin() ctx = context.WithValue(context.Background(), constant.DB, tx) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 4ed534643..84b9552e4 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -106,9 +106,9 @@ func (a AppService) GetAppTags() ([]response.TagDTO, error) { return res, nil } -func (a AppService) GetApp(id uint) (*response.AppDTO, error) { +func (a AppService) GetApp(key string) (*response.AppDTO, error) { var appDTO response.AppDTO - app, err := appRepo.GetFirst(commonRepo.WithByID(id)) + app, err := appRepo.GetFirst(appRepo.WithKey(key)) if err != nil { return nil, err } diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index b60588f66..71bc749eb 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -17,7 +17,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { { appRouter.POST("/sync", baseApi.SyncApp) appRouter.POST("/search", baseApi.SearchApp) - appRouter.GET("/:id", baseApi.GetApp) + appRouter.GET("/:key", baseApi.GetApp) appRouter.GET("/detail/:appId/:version", baseApi.GetAppDetail) appRouter.POST("/install", baseApi.InstallApp) appRouter.GET("/tags", baseApi.GetAppTags) diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index 6bce18c20..d173c8f75 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -10,8 +10,8 @@ export const SearchApp = (req: App.AppReq) => { return http.post('apps/search', req); }; -export const GetApp = (id: number) => { - return http.get('apps/' + id); +export const GetApp = (key: string) => { + return http.get('apps/' + key); }; export const GetAppTags = () => { diff --git a/frontend/src/routers/modules/app-store.ts b/frontend/src/routers/modules/app-store.ts index 5e1389242..9a99e1d43 100644 --- a/frontend/src/routers/modules/app-store.ts +++ b/frontend/src/routers/modules/app-store.ts @@ -27,6 +27,16 @@ const appStoreRouter = { activeMenu: '/apps', }, }, + { + path: 'detail/:appKey', + name: 'AppDetail', + component: () => import('@/views/app-store/detail/index.vue'), + props: true, + hidden: true, + meta: { + activeMenu: '/apps', + }, + }, { path: 'installed', name: 'AppInstalled', diff --git a/frontend/src/views/app-store/apps/index.vue b/frontend/src/views/app-store/apps/index.vue index 4d8881b68..a7c983609 100644 --- a/frontend/src/views/app-store/apps/index.vue +++ b/frontend/src/views/app-store/apps/index.vue @@ -62,7 +62,7 @@ plain round size="small" - @click="getAppDetail(app.id)" + @click="getAppDetail(app.key)" > {{ $t('app.install') }} @@ -97,6 +97,7 @@ import { GetAppTags, SearchApp, SyncApp } from '@/api/modules/app'; import { ElMessage } from 'element-plus'; import i18n from '@/lang'; import Detail from '../detail/index.vue'; +import router from '@/routers'; let req = reactive({ name: '', @@ -131,9 +132,8 @@ const search = async (req: App.AppReq) => { }); }; -const getAppDetail = (id: number) => { - showDetail.value = true; - appId.value = id; +const getAppDetail = (key: string) => { + router.push({ name: 'AppDetail', params: { appKey: key } }); }; const sync = () => { diff --git a/frontend/src/views/app-store/detail/index.vue b/frontend/src/views/app-store/detail/index.vue index b1a2453ed..95a2df5a2 100644 --- a/frontend/src/views/app-store/detail/index.vue +++ b/frontend/src/views/app-store/detail/index.vue @@ -1,5 +1,5 @@