From 07dfe62daf278178a5e3733b2570ae5fbe5d0330 Mon Sep 17 00:00:00 2001 From: Ryan SU <1137661202@qq.com> Date: Sat, 12 Nov 2022 16:56:23 +0800 Subject: [PATCH 1/5] wip: error code optimize --- api/desc/apis.api | 6 +- api/desc/authority.api | 14 +- api/desc/base.api | 34 +++- api/desc/captcha.api | 12 +- api/desc/dictionary.api | 8 +- api/desc/menu.api | 11 +- api/desc/oauth.api | 4 +- api/desc/role.api | 4 +- api/desc/token.api | 4 +- api/desc/user.api | 20 ++- .../api/create_or_update_api_handler.go | 5 +- .../handler/api/delete_api_handler.go | 5 +- .../logic/api/create_or_update_api_logic.go | 9 +- api/internal/logic/api/delete_api_logic.go | 9 +- api/internal/logic/api/get_api_list_logic.go | 11 +- .../middleware/authority_middleware.go | 2 +- api/internal/types/types.go | 47 +++--- core.yml | 153 ++++++++++++------ docs/simple-admin/en/docs/ent.md | 2 +- docs/simple-admin/en/docs/global_vars.md | 4 +- docs/simple-admin/zh-cn/docs/ent.md | 2 +- docs/simple-admin/zh-cn/docs/global_vars.md | 4 +- pkg/i18n/locale/en.json | 4 +- pkg/i18n/locale/zh.json | 4 +- pkg/i18n/var.go | 17 ++ pkg/msg/errormsg/msg.go | 5 + pkg/msg/logmsg/msg.go | 18 +-- .../logic/block_user_all_token_logic.go | 6 +- rpc/internal/logic/change_password_logic.go | 4 +- .../logic/create_or_update_api_logic.go | 4 +- ...reate_or_update_dictionary_detail_logic.go | 6 +- .../create_or_update_dictionary_logic.go | 12 +- .../logic/create_or_update_menu_logic.go | 8 +- .../create_or_update_menu_param_logic.go | 6 +- .../logic/create_or_update_provider_logic.go | 4 +- .../logic/create_or_update_role_logic.go | 6 +- .../logic/create_or_update_token_logic.go | 4 +- .../logic/create_or_update_user_logic.go | 4 +- rpc/internal/logic/delete_api_logic.go | 2 +- .../logic/delete_dictionary_detail_logic.go | 2 +- rpc/internal/logic/delete_menu_logic.go | 6 +- rpc/internal/logic/delete_menu_param_logic.go | 2 +- rpc/internal/logic/delete_provider_logic.go | 2 +- rpc/internal/logic/delete_role_logic.go | 4 +- rpc/internal/logic/delete_token_logic.go | 2 +- rpc/internal/logic/delete_user_logic.go | 2 +- .../get_detail_by_dictionary_name_logic.go | 2 +- .../logic/get_menu_authority_logic.go | 2 +- .../logic/get_menu_list_by_role_logic.go | 2 +- .../get_menu_param_list_by_menu_id_logic.go | 2 +- rpc/internal/logic/get_role_by_id_logic.go | 2 +- rpc/internal/logic/get_token_list_logic.go | 2 +- rpc/internal/logic/get_user_by_id_logic.go | 2 +- rpc/internal/logic/init_database_logic.go | 22 +-- rpc/internal/logic/login_logic.go | 6 +- rpc/internal/logic/oauth_callback_logic.go | 4 +- rpc/internal/logic/oauth_login_logic.go | 2 +- rpc/internal/logic/update_profile_logic.go | 2 +- .../logic/update_role_status_logic.go | 2 +- .../logic/update_token_status_logic.go | 2 +- .../logic/update_user_status_logic.go | 2 +- 61 files changed, 343 insertions(+), 217 deletions(-) create mode 100644 pkg/i18n/var.go create mode 100644 pkg/msg/errormsg/msg.go diff --git a/api/desc/apis.api b/api/desc/apis.api index 2f410a82..eb738e0b 100644 --- a/api/desc/apis.api +++ b/api/desc/apis.api @@ -62,18 +62,18 @@ type ( } // The response data of API list | API列表数据 + // swagger:model ApiListResp ApiListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The API list data | API列表数据 - // in: body Data []ApiInfo `json:"data"` } // Get API list request params | API列表请求参数 ApiListReq { PageInfo + // API path | API路径 // Max length: 100 Path string `json:"path,optional" validate:"omitempty,max=100"` diff --git a/api/desc/authority.api b/api/desc/authority.api index ebbc3237..4ca5cb56 100644 --- a/api/desc/authority.api +++ b/api/desc/authority.api @@ -34,12 +34,11 @@ type ( } // The response data of api authorization list | API授权列表数据 + // swagger:model ApiAuthorityListResp ApiAuthorityListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The api authorization list data | API授权列表数据 - // in: body Data []ApiAuthorityInfo `json:"data"` } @@ -55,13 +54,12 @@ type ( MenuIds []uint64 `json:"menuIds"` } - // Create or update menu authorization information request params | 创建或更新菜单授权信息参数 + // Menu authorization response data | 菜单授权信息数据 MenuAuthorityInfoResp { - // role ID | 角色ID - RoleId uint64 `json:"roleId"` + BaseDataInfo - // menu ID array | 菜单ID数组 - MenuIds []uint64 `json:"menuIds"` + // The menu authorization data | 菜单授权信息数据 + Data []MenuAuthorityInfoReq `json:"data"` } ) diff --git a/api/desc/base.api b/api/desc/base.api index 663df548..6d4f361a 100644 --- a/api/desc/base.api +++ b/api/desc/base.api @@ -9,16 +9,38 @@ info( ) // The basic response with data | 基础带数据信息 -// swagger:response BaseMsg -type BaseMsg { - Code int32 `json:"code"` +type BaseDataInfo { + // Error code | 错误代码 + Code int `json:"code"` + + // Message | 提示信息 + Msg string `json:"msg"` + + // Data | 数据 + Data string `json:"data,omitempty"` +} + +// The basic response with data | 基础带数据信息 +type BaseListInfo { + // Error code | 错误代码 + Code int `json:"code"` + + // Message | 提示信息 Msg string `json:"msg"` - Data string `json:"data"` + + // The total number of data | 数据总数 + Total uint64 `json:"total"` + + // Data | 数据 + Data string `json:"data,omitempty"` } // The basic response without data | 基础不带数据信息 -type BaseResp { - Code int32 `json:"code"` +type BaseMsgInfo { + // Error code | 错误代码 + Code int `json:"code"` + + // Message | 提示信息 Msg string `json:"msg"` } diff --git a/api/desc/captcha.api b/api/desc/captcha.api index 88adb086..f6265b9f 100644 --- a/api/desc/captcha.api +++ b/api/desc/captcha.api @@ -10,12 +10,20 @@ info( import "base.api" -// The response data of captcha | 验证码返回数据 +// The information of captcha | 验证码数据 type CaptchaInfo { CaptchaId string `json:"captchaId"` ImgPath string `json:"imgPath"` } +// The response data of captcha | 验证码返回数据 +type CaptchaResp { + BaseDataInfo + + // The menu authorization data | 菜单授权信息数据 + Data []CaptchaInfo `json:"data"` +} + @server( group: captcha ) @@ -23,5 +31,5 @@ type CaptchaInfo { service core { // Get captcha | 获取验证码 @handler getCaptcha - get /captcha returns (CaptchaInfo) + get /captcha returns (CaptchaResp) } \ No newline at end of file diff --git a/api/desc/dictionary.api b/api/desc/dictionary.api index 935a81d3..728d4fb8 100644 --- a/api/desc/dictionary.api +++ b/api/desc/dictionary.api @@ -58,11 +58,9 @@ type ( // The response data of dictionary list | 字典列表数据 DictionaryListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryInfo `json:"data"` } @@ -98,11 +96,9 @@ type ( // The response data of dictionary KV list | 字典值的列表数据 DictionaryDetailListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryDetailInfo `json:"data"` } diff --git a/api/desc/menu.api b/api/desc/menu.api index 6f225cf0..222c520b 100644 --- a/api/desc/menu.api +++ b/api/desc/menu.api @@ -55,7 +55,7 @@ type ( } // The meta data of menu | 菜单的meta数据 - // swagger:response Meta + // swagger:model Meta Meta { // Menu title show in page | 菜单显示名 // Max length: 50 @@ -102,11 +102,9 @@ type ( // The response data of menu list | 菜单列表数据 MenuListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The menu list data | 菜单列表数据 - // in: body Data []*MenuInfo `json:"data"` } @@ -114,6 +112,7 @@ type ( GetMenuListBase { // Menu type: directory or menu | 菜单类型: 目录或菜单 menuType uint32 `json:"type"` + // Parent menu ID | 父级菜单ID ParentId uint64 `json:"parentId"` @@ -242,11 +241,9 @@ type ( // The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 MenuParamListByMenuIdResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The menu list data | 菜单列表数据 - // in: body Data []MenuParamResp `json:"data"` } ) diff --git a/api/desc/oauth.api b/api/desc/oauth.api index 0dd436df..60cad6ea 100644 --- a/api/desc/oauth.api +++ b/api/desc/oauth.api @@ -101,11 +101,9 @@ type ( // The response data of provider list | 提供商列表数据 ProviderListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The provider list data | 提供商列表数据 - // in: body Data []ProviderInfo `json:"data"` } diff --git a/api/desc/role.api b/api/desc/role.api index 8b11a2b0..0f01f725 100644 --- a/api/desc/role.api +++ b/api/desc/role.api @@ -51,11 +51,9 @@ type ( // The response data of role list | 角色列表数据 RoleListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The role list data | 角色列表数据 - // in: body Data []RoleInfo `json:"data"` } ) diff --git a/api/desc/token.api b/api/desc/token.api index 429f344c..3ad80a4c 100644 --- a/api/desc/token.api +++ b/api/desc/token.api @@ -62,11 +62,9 @@ type ( // The response data of Token list | Token列表数据 TokenListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The token list data | Token列表数据 - // in: body Data []TokenInfo `json:"data"` } diff --git a/api/desc/user.api b/api/desc/user.api index ee77192e..a5709427 100644 --- a/api/desc/user.api +++ b/api/desc/user.api @@ -51,8 +51,8 @@ type ( Expire uint64 `json:"expire"` } - // The profile response data | 个人信息返回数据 - ProfileResp { + // The profile information | 个人信息 + ProfileInfo { // user's nickname | 用户的昵称 Nickname string `json:"nickname"` @@ -66,6 +66,14 @@ type ( Email string `json:"email"` } + // The profile response data | 个人信息返回数据 + ProfileResp { + BaseDataInfo + + // The profile information | 个人信息 + Data ProfileInfo `json:"data"` + } + // The profile request data | 个人信息请求参数 ProfileReq { // user's nickname | 用户的昵称 @@ -85,7 +93,7 @@ type ( } // The simple role data | 简单的角色数据 - // swagger:response RoleInfoSimple + // swagger:model RoleInfoSimple RoleInfoSimple { // Role name | 角色名 RoleName string `json:"roleName"` @@ -200,16 +208,16 @@ type ( // The response data of user list | 用户列表数据 UserListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The user list data | 用户列表数据 - // in: body Data []UserInfoResp `json:"data"` } // The permission code for front end permission control | 权限码: 用于前端权限控制 PermCodeResp { + BaseDataInfo + // Permission code data | 权限码数据 Data []string `json:"data"` } diff --git a/api/internal/handler/api/create_or_update_api_handler.go b/api/internal/handler/api/create_or_update_api_handler.go index 2de2bfca..044605ca 100644 --- a/api/internal/handler/api/create_or_update_api_handler.go +++ b/api/internal/handler/api/create_or_update_api_handler.go @@ -3,10 +3,11 @@ package api import ( "net/http" + "github.com/zeromicro/go-zero/rest/httpx" + "github.com/suyuan32/simple-admin-core/api/internal/logic/api" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" - "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route post /api api CreateOrUpdateApi @@ -34,7 +35,7 @@ func CreateOrUpdateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := api.NewCreateOrUpdateApiLogic(r.Context(), svcCtx) + l := api.NewCreateOrUpdateApiLogic(r, svcCtx) resp, err := l.CreateOrUpdateApi(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/api/delete_api_handler.go b/api/internal/handler/api/delete_api_handler.go index e40fae87..530cb05a 100644 --- a/api/internal/handler/api/delete_api_handler.go +++ b/api/internal/handler/api/delete_api_handler.go @@ -3,10 +3,11 @@ package api import ( "net/http" + "github.com/zeromicro/go-zero/rest/httpx" + "github.com/suyuan32/simple-admin-core/api/internal/logic/api" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" - "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route delete /api api DeleteApi @@ -34,7 +35,7 @@ func DeleteApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := api.NewDeleteApiLogic(r.Context(), svcCtx) + l := api.NewDeleteApiLogic(r, svcCtx) resp, err := l.DeleteApi(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/logic/api/create_or_update_api_logic.go b/api/internal/logic/api/create_or_update_api_logic.go index 9ec81aa2..ee9f0eed 100644 --- a/api/internal/logic/api/create_or_update_api_logic.go +++ b/api/internal/logic/api/create_or_update_api_logic.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,13 +15,15 @@ type CreateOrUpdateApiLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateApiLogic { +func NewCreateOrUpdateApiLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateApiLogic { return &CreateOrUpdateApiLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } diff --git a/api/internal/logic/api/delete_api_logic.go b/api/internal/logic/api/delete_api_logic.go index bd16afa7..641862bf 100644 --- a/api/internal/logic/api/delete_api_logic.go +++ b/api/internal/logic/api/delete_api_logic.go @@ -2,6 +2,7 @@ package api import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,13 +15,15 @@ type DeleteApiLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteApiLogic { +func NewDeleteApiLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteApiLogic { return &DeleteApiLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } diff --git a/api/internal/logic/api/get_api_list_logic.go b/api/internal/logic/api/get_api_list_logic.go index 38850be8..263c1f01 100644 --- a/api/internal/logic/api/get_api_list_logic.go +++ b/api/internal/logic/api/get_api_list_logic.go @@ -6,6 +6,7 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -15,7 +16,7 @@ type GetApiListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext - r *http.Request + lang string } func NewGetApiListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetApiListLogic { @@ -23,7 +24,7 @@ func NewGetApiListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetApiList Logger: logx.WithContext(r.Context()), ctx: r.Context(), svcCtx: svcCtx, - r: r, + lang: r.Header.Get("Accept-Language"), } } @@ -41,10 +42,10 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList return nil, err } resp = &types.ApiListResp{} + resp.Code = 0 + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.SUCCESS) resp.Total = data.GetTotal() - lang := l.r.Header.Get("Accept-Language") - for _, v := range data.Data { resp.Data = append(resp.Data, types.ApiInfo{ @@ -54,7 +55,7 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList UpdatedAt: v.UpdatedAt, }, Path: v.Path, - Title: l.svcCtx.Trans.Trans(lang, v.Description), + Title: l.svcCtx.Trans.Trans(l.lang, v.Description), Description: v.Description, Group: v.Group, Method: v.Method, diff --git a/api/internal/middleware/authority_middleware.go b/api/internal/middleware/authority_middleware.go index 91c469ed..ab6912de 100644 --- a/api/internal/middleware/authority_middleware.go +++ b/api/internal/middleware/authority_middleware.go @@ -37,7 +37,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { // check the role status roleStatus, err := m.Rds.Hget("roleData", fmt.Sprintf("%s_status", roleId)) if err != nil { - logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) httpx.Error(w, errorx.NewApiErrorWithoutMsg(http.StatusUnauthorized)) return } else if roleStatus == "0" { diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 205bed7b..959269ca 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -44,17 +44,33 @@ type RoleListResp struct { } // The basic response with data | 基础带数据信息 -// swagger:response BaseMsg -type BaseMsg struct { - Code int32 `json:"code"` - Msg string `json:"msg"` - Data string `json:"data"` +// swagger:model BaseDataResp +type BaseDataResp struct { + // Error code | 错误代码 + Code int `json:"code"` + // Message | 提示信息 + Msg string `json:"msg"` + // Data | 数据 + Data string `json:"data,omitempty"` +} + +// The basic response with data | 基础带数据信息 +// swagger:model BaseListResp +type BaseListResp struct { + // Error code | 错误代码 + Code int `json:"code"` + // Message | 提示信息 + Msg string `json:"msg"` + // The total number of data | 数据总数 + Total uint64 `json:"total"` + // Data | 数据 + Data string `json:"data,omitempty"` } // The basic response without data | 基础不带数据信息 // swagger:response BaseResp type BaseResp struct { - Code int32 `json:"code"` + Code int `json:"code"` Msg string `json:"msg"` } @@ -624,12 +640,10 @@ type CreateOrUpdateApiReq struct { } // The response data of API list | API列表数据 -// swagger:response ApiListResp +// swagger:model ApiListResp type ApiListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListResp // The API list data | API列表数据 - // in: body Data []ApiInfo `json:"data"` } @@ -673,12 +687,10 @@ type CreateOrUpdateApiAuthorityReq struct { } // The response data of api authorization list | API授权列表数据 -// swagger:response ApiAuthorityListResp +// swagger:model ApiAuthorityListResp type ApiAuthorityListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListResp // The api authorization list data | API授权列表数据 - // in: body Data []ApiAuthorityInfo `json:"data"` } @@ -694,13 +706,10 @@ type MenuAuthorityInfoReq struct { MenuIds []uint64 `json:"menuIds"` } -// Create or update menu authorization information request params | 创建或更新菜单授权信息参数 +// Menu authorization response data | 菜单授权信息数据 // swagger:response MenuAuthorityInfoResp type MenuAuthorityInfoResp struct { - // role ID | 角色ID - RoleId uint64 `json:"roleId"` - // menu ID array | 菜单ID数组 - MenuIds []uint64 `json:"menuIds"` + BaseDataResp } // The response data of dictionary information | 字典信息 diff --git a/core.yml b/core.yml index e351fee0..3e55a676 100644 --- a/core.yml +++ b/core.yml @@ -15,6 +15,31 @@ definitions: x-go-name: Path type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ApiAuthorityListResp: + description: The response data of api authorization list | API授权列表数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + description: The api authorization list data | API授权列表数据 + items: + $ref: '#/definitions/ApiAuthorityInfo' + type: array + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ApiInfo: description: The response data of API information | API信息 properties: @@ -94,6 +119,49 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ApiListResp: + description: The response data of API list | API列表数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + description: The API list data | API列表数据 + items: + $ref: '#/definitions/ApiInfo' + type: array + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + BaseDataResp: + description: The basic response with data | 基础带数据信息 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types BaseInfo: description: The base response data | 基础信息 properties: @@ -114,6 +182,29 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + BaseListResp: + description: The basic response with data | 基础带数据信息 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types CaptchaInfo: description: The response data of captcha | 验证码返回数据 properties: @@ -1545,7 +1636,9 @@ paths: type: object responses: "200": - $ref: '#/responses/ApiListResp' + description: ApiListResp + schema: + $ref: '#/definitions/ApiListResp' "401": $ref: '#/responses/SimpleMsg' "500": @@ -1585,7 +1678,9 @@ paths: type: object responses: "200": - $ref: '#/responses/ApiAuthorityListResp' + description: ApiAuthorityListResp + schema: + $ref: '#/definitions/ApiAuthorityListResp' "401": $ref: '#/responses/SimpleMsg' "500": @@ -2402,43 +2497,11 @@ paths: produces: - application/json responses: - ApiAuthorityListResp: - description: The response data of api authorization list | API授权列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/ApiAuthorityInfo' - type: array - ApiListResp: - description: The response data of API list | API列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/ApiInfo' - type: array - BaseMsg: - description: The basic response with data | 基础带数据信息 - headers: - code: - format: int32 - type: integer - data: - type: string - msg: - type: string BaseResp: description: The basic response without data | 基础不带数据信息 headers: code: - format: int32 + format: int64 type: integer msg: type: string @@ -2512,18 +2575,18 @@ responses: schema: $ref: '#/definitions/RoleInfoSimple' MenuAuthorityInfoResp: - description: Create or update menu authorization information request params | 创建或更新菜单授权信息参数 + description: Menu authorization response data | 菜单授权信息数据 headers: - menuIds: - description: menu ID array | 菜单ID数组 - items: - format: uint64 - type: integer - type: array - roleId: - description: role ID | 角色ID - format: uint64 + code: + description: Error code | 错误代码 + format: int64 type: integer + data: + description: Data | 数据 + type: string + msg: + description: Message | 提示信息 + type: string MenuListResp: description: The response data of menu list | 菜单列表数据 headers: diff --git a/docs/simple-admin/en/docs/ent.md b/docs/simple-admin/en/docs/ent.md index 21f55b74..f7f9ad54 100644 --- a/docs/simple-admin/en/docs/ent.md +++ b/docs/simple-admin/en/docs/ent.md @@ -168,7 +168,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/en/docs/global_vars.md b/docs/simple-admin/en/docs/global_vars.md index 59e1435d..5f2e78d4 100644 --- a/docs/simple-admin/en/docs/global_vars.md +++ b/docs/simple-admin/en/docs/global_vars.md @@ -93,7 +93,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -116,7 +116,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/zh-cn/docs/ent.md b/docs/simple-admin/zh-cn/docs/ent.md index 5b1af604..55d10e6e 100644 --- a/docs/simple-admin/zh-cn/docs/ent.md +++ b/docs/simple-admin/zh-cn/docs/ent.md @@ -168,7 +168,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/zh-cn/docs/global_vars.md b/docs/simple-admin/zh-cn/docs/global_vars.md index 38c96f5d..a9d94e4b 100644 --- a/docs/simple-admin/zh-cn/docs/global_vars.md +++ b/docs/simple-admin/zh-cn/docs/global_vars.md @@ -92,7 +92,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -115,7 +115,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/pkg/i18n/locale/en.json b/pkg/i18n/locale/en.json index e0849f71..d7b266e6 100644 --- a/pkg/i18n/locale/en.json +++ b/pkg/i18n/locale/en.json @@ -1,13 +1,13 @@ { "common": { + "success": "successfully", + "failed": "failed", "updateSuccess": "Update successfully", "updateFailed": "Update failed", "createSuccess": "Create successfully", "createFailed": "Create failed", "deleteSuccess": "Delete successfully", "deleteFailed": "Delete failed", - "getInfoSuccess": "Get information Successfully", - "getInfoFailed": "Get information Failed", "changeStatusSuccess": "Change status successfully", "changeStatusFailed": "Change status failed", "targetNotExist": "Target does not exist", diff --git a/pkg/i18n/locale/zh.json b/pkg/i18n/locale/zh.json index d3219809..0d30c0fa 100644 --- a/pkg/i18n/locale/zh.json +++ b/pkg/i18n/locale/zh.json @@ -1,13 +1,13 @@ { "common": { + "success": "成功", + "failed": "失败", "updateSuccess": "更新成功", "updateFailed": "更新失败", "createSuccess": "新建成功", "createFailed": "新建失败", "deleteSuccess": "删除成功", "deleteFailed": "删除失败", - "getInfoSuccess": "获取信息成功", - "getInfoFailed": "获取信息失败", "changeStatusSuccess": "状态修改成功", "changeStatusFailed": "状态修改失败", "targetNotExist": "目标不存在", diff --git a/pkg/i18n/var.go b/pkg/i18n/var.go new file mode 100644 index 00000000..184f117f --- /dev/null +++ b/pkg/i18n/var.go @@ -0,0 +1,17 @@ +package i18n + +const ( + SUCCESS = "common.success" + FAILED = "common.failed" + UPDATE_SUCCESS = "common.updateSuccess" + UPDATE_FAILED = "common.updateFailed" + CREATE_SUCCESS = "common.createSuccess" + CREATE_FAILED = "common.createFailed" + DELETE_SUCCESS = "common.deleteSuccess" + DELETE_FAILED = "common.deleteFailed" + CHANGE_STATUS_SUCCESS = "common.changeStatusSuccess" + CHANGE_STATUS_FAILED = "common.changeStatusFailed" + TARGET_NOT_FOUND = "common.targetNotExist" + DATABASE_ERROR = "common.databaseError" + REDIS_ERROR = "common.redisError" +) diff --git a/pkg/msg/errormsg/msg.go b/pkg/msg/errormsg/msg.go new file mode 100644 index 00000000..8245b33e --- /dev/null +++ b/pkg/msg/errormsg/msg.go @@ -0,0 +1,5 @@ +package errormsg + +const ( + SUCCESS string = "successful" +) diff --git a/pkg/msg/logmsg/msg.go b/pkg/msg/logmsg/msg.go index 33d328ad..09ba216a 100644 --- a/pkg/msg/logmsg/msg.go +++ b/pkg/msg/logmsg/msg.go @@ -1,13 +1,13 @@ package logmsg const ( - CreateSuccess string = "create successfully" - CreateFailed string = "create failed" - DeleteSuccess string = "delete successful" - DeleteFailed string = "delete failed" - UpdateSuccess string = "update successful" - UpdateFailed string = "update failed" - TargetNotFound string = "target cannot be found" - DatabaseError string = "database error" - RedisError string = "redis error" + CREATE_SUCCESS = "create successfully" + CREATE_FAILED = "create failed" + DELETE_SUCCESS = "delete successful" + DELETE_FAILED = "delete failed" + UPDATE_SUCCESS = "update successful" + UPDATE_FAILED = "update failed" + TARGET_NOT_FOUND = "target not found" + DATABASE_ERROR = "database error" + REDIS_ERROR = "redis error" ) diff --git a/rpc/internal/logic/block_user_all_token_logic.go b/rpc/internal/logic/block_user_all_token_logic.go index 0a1536ad..a18a9e00 100644 --- a/rpc/internal/logic/block_user_all_token_logic.go +++ b/rpc/internal/logic/block_user_all_token_logic.go @@ -38,7 +38,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -55,7 +55,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -63,7 +63,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base for _, v := range tokenData { err := l.svcCtx.Redis.Set("token_"+v.Token, "1") if err != nil { - logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.RedisError) } } diff --git a/rpc/internal/logic/change_password_logic.go b/rpc/internal/logic/change_password_logic.go index 260b1039..f838b8ec 100644 --- a/rpc/internal/logic/change_password_logic.go +++ b/rpc/internal/logic/change_password_logic.go @@ -38,7 +38,7 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core. logx.Errorw(err.Error(), logx.Field("uuid", in.Uuid)) return nil, statuserr.NewInvalidArgumentError("login.userNotExist") default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -56,7 +56,7 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_api_logic.go b/rpc/internal/logic/create_or_update_api_logic.go index e2326a1f..6a54f191 100644 --- a/rpc/internal/logic/create_or_update_api_logic.go +++ b/rpc/internal/logic/create_or_update_api_logic.go @@ -43,7 +43,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("apis.apiExists") default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -66,7 +66,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_dictionary_detail_logic.go b/rpc/internal/logic/create_or_update_dictionary_detail_logic.go index 1218af7e..1989da7f 100644 --- a/rpc/internal/logic/create_or_update_dictionary_detail_logic.go +++ b/rpc/internal/logic/create_or_update_dictionary_detail_logic.go @@ -32,7 +32,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in exist, err := l.svcCtx.DB.Dictionary.Query().Where(dictionary.IDEQ(in.DictionaryId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -56,7 +56,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -79,7 +79,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_dictionary_logic.go b/rpc/internal/logic/create_or_update_dictionary_logic.go index e8ccb77a..06cc3d7d 100644 --- a/rpc/internal/logic/create_or_update_dictionary_logic.go +++ b/rpc/internal/logic/create_or_update_dictionary_logic.go @@ -42,10 +42,10 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio if err != nil { if ent.IsConstraintError(err) { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) } - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -57,12 +57,12 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio } if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, err.Error()) } if !exist { - logx.Errorw(logmsg.TargetNotFound, logx.Field("id", in.Id)) + logx.Errorw(logmsg.TARGET_NOT_FOUND, logx.Field("id", in.Id)) return nil, status.Error(codes.InvalidArgument, errorx.UpdateFailed) } @@ -74,8 +74,8 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio Exec(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) - return nil, statuserr.NewInvalidArgumentError(logmsg.UpdateFailed) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + return nil, statuserr.NewInvalidArgumentError(logmsg.UPDATE_FAILED) } return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil diff --git a/rpc/internal/logic/create_or_update_menu_logic.go b/rpc/internal/logic/create_or_update_menu_logic.go index e24eb902..0eebd6fc 100644 --- a/rpc/internal/logic/create_or_update_menu_logic.go +++ b/rpc/internal/logic/create_or_update_menu_logic.go @@ -42,7 +42,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -89,7 +89,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -98,7 +98,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu } else { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.IDEQ(in.ParentId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, err } @@ -142,7 +142,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_menu_param_logic.go b/rpc/internal/logic/create_or_update_menu_param_logic.go index 9e6e652d..5c0d0ceb 100644 --- a/rpc/internal/logic/create_or_update_menu_param_logic.go +++ b/rpc/internal/logic/create_or_update_menu_param_logic.go @@ -43,7 +43,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -52,7 +52,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr } else { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.IDEQ(in.MenuId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -77,7 +77,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_provider_logic.go b/rpc/internal/logic/create_or_update_provider_logic.go index e781f500..9ef9f546 100644 --- a/rpc/internal/logic/create_or_update_provider_logic.go +++ b/rpc/internal/logic/create_or_update_provider_logic.go @@ -48,7 +48,7 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(in *core.ProviderIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -76,7 +76,7 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(in *core.ProviderIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_role_logic.go b/rpc/internal/logic/create_or_update_role_logic.go index 96f4bcc1..f4dac645 100644 --- a/rpc/internal/logic/create_or_update_role_logic.go +++ b/rpc/internal/logic/create_or_update_role_logic.go @@ -47,7 +47,7 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(in *core.RoleInfo) (*core.B logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("role.duplicateRoleValue") default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -78,7 +78,7 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(in *core.RoleInfo) (*core.B logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("role.duplicateRoleValue") default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -105,7 +105,7 @@ func (l *CreateOrUpdateRoleLogic) UpdateRoleInfoInRedis() error { logx.Error(err.Error()) return statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_token_logic.go b/rpc/internal/logic/create_or_update_token_logic.go index 15cb7aa7..8987be76 100644 --- a/rpc/internal/logic/create_or_update_token_logic.go +++ b/rpc/internal/logic/create_or_update_token_logic.go @@ -45,7 +45,7 @@ func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(in *core.TokenInfo) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -69,7 +69,7 @@ func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(in *core.TokenInfo) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_user_logic.go b/rpc/internal/logic/create_or_update_user_logic.go index d4fa7548..d4e1d317 100644 --- a/rpc/internal/logic/create_or_update_user_logic.go +++ b/rpc/internal/logic/create_or_update_user_logic.go @@ -48,7 +48,7 @@ func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(in *core.CreateOrUpdateUser logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -86,7 +86,7 @@ func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(in *core.CreateOrUpdateUser logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_api_logic.go b/rpc/internal/logic/delete_api_logic.go index 223ff341..f6aba651 100644 --- a/rpc/internal/logic/delete_api_logic.go +++ b/rpc/internal/logic/delete_api_logic.go @@ -36,7 +36,7 @@ func (l *DeleteApiLogic) DeleteApi(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_dictionary_detail_logic.go b/rpc/internal/logic/delete_dictionary_detail_logic.go index df061c46..05593ec6 100644 --- a/rpc/internal/logic/delete_dictionary_detail_logic.go +++ b/rpc/internal/logic/delete_dictionary_detail_logic.go @@ -36,7 +36,7 @@ func (l *DeleteDictionaryDetailLogic) DeleteDictionaryDetail(in *core.IDReq) (*c logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_menu_logic.go b/rpc/internal/logic/delete_menu_logic.go index 710c2b08..aa57369a 100644 --- a/rpc/internal/logic/delete_menu_logic.go +++ b/rpc/internal/logic/delete_menu_logic.go @@ -32,7 +32,7 @@ func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.ParentID(in.Id)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -46,7 +46,7 @@ func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { err = l.svcCtx.DB.Menu.Update().ClearParams().Exec(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } @@ -58,7 +58,7 @@ func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_menu_param_logic.go b/rpc/internal/logic/delete_menu_param_logic.go index 3bc6ef0b..ad39b13b 100644 --- a/rpc/internal/logic/delete_menu_param_logic.go +++ b/rpc/internal/logic/delete_menu_param_logic.go @@ -36,7 +36,7 @@ func (l *DeleteMenuParamLogic) DeleteMenuParam(in *core.IDReq) (*core.BaseResp, logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_provider_logic.go b/rpc/internal/logic/delete_provider_logic.go index 02355569..292a348a 100644 --- a/rpc/internal/logic/delete_provider_logic.go +++ b/rpc/internal/logic/delete_provider_logic.go @@ -36,7 +36,7 @@ func (l *DeleteProviderLogic) DeleteProvider(in *core.IDReq) (*core.BaseResp, er logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_role_logic.go b/rpc/internal/logic/delete_role_logic.go index d8099361..6b7b1af2 100644 --- a/rpc/internal/logic/delete_role_logic.go +++ b/rpc/internal/logic/delete_role_logic.go @@ -31,7 +31,7 @@ func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete func (l *DeleteRoleLogic) DeleteRole(in *core.IDReq) (*core.BaseResp, error) { exist, err := l.svcCtx.DB.User.Query().Where(user.RoleIDEQ(in.Id)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -49,7 +49,7 @@ func (l *DeleteRoleLogic) DeleteRole(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_token_logic.go b/rpc/internal/logic/delete_token_logic.go index d89fca60..0dd8fa00 100644 --- a/rpc/internal/logic/delete_token_logic.go +++ b/rpc/internal/logic/delete_token_logic.go @@ -36,7 +36,7 @@ func (l *DeleteTokenLogic) DeleteToken(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_user_logic.go b/rpc/internal/logic/delete_user_logic.go index fddae88b..1b3442f4 100644 --- a/rpc/internal/logic/delete_user_logic.go +++ b/rpc/internal/logic/delete_user_logic.go @@ -36,7 +36,7 @@ func (l *DeleteUserLogic) DeleteUser(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_detail_by_dictionary_name_logic.go b/rpc/internal/logic/get_detail_by_dictionary_name_logic.go index e38e09f4..ccbce168 100644 --- a/rpc/internal/logic/get_detail_by_dictionary_name_logic.go +++ b/rpc/internal/logic/get_detail_by_dictionary_name_logic.go @@ -40,7 +40,7 @@ func (l *GetDetailByDictionaryNameLogic) GetDetailByDictionaryName(in *core.Dict logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_authority_logic.go b/rpc/internal/logic/get_menu_authority_logic.go index 1f69daf9..4b75fcf2 100644 --- a/rpc/internal/logic/get_menu_authority_logic.go +++ b/rpc/internal/logic/get_menu_authority_logic.go @@ -38,7 +38,7 @@ func (l *GetMenuAuthorityLogic) GetMenuAuthority(in *core.IDReq) (*core.RoleMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_list_by_role_logic.go b/rpc/internal/logic/get_menu_list_by_role_logic.go index 1af74e03..cd4efaa5 100644 --- a/rpc/internal/logic/get_menu_list_by_role_logic.go +++ b/rpc/internal/logic/get_menu_list_by_role_logic.go @@ -39,7 +39,7 @@ func (l *GetMenuListByRoleLogic) GetMenuListByRole(in *core.IDReq) (*core.MenuIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go b/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go index cdeaf17c..8825bc4f 100644 --- a/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go +++ b/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go @@ -37,7 +37,7 @@ func (l *GetMenuParamListByMenuIdLogic) GetMenuParamListByMenuId(in *core.IDReq) logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_role_by_id_logic.go b/rpc/internal/logic/get_role_by_id_logic.go index eafbd183..fc570465 100644 --- a/rpc/internal/logic/get_role_by_id_logic.go +++ b/rpc/internal/logic/get_role_by_id_logic.go @@ -36,7 +36,7 @@ func (l *GetRoleByIdLogic) GetRoleById(in *core.IDReq) (*core.RoleInfo, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_token_list_logic.go b/rpc/internal/logic/get_token_list_logic.go index e9b1c8b5..f7a13700 100644 --- a/rpc/internal/logic/get_token_list_logic.go +++ b/rpc/internal/logic/get_token_list_logic.go @@ -67,7 +67,7 @@ func (l *GetTokenListLogic) GetTokenList(in *core.TokenListReq) (*core.TokenList logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_user_by_id_logic.go b/rpc/internal/logic/get_user_by_id_logic.go index 6ac9fcfc..6552795a 100644 --- a/rpc/internal/logic/get_user_by_id_logic.go +++ b/rpc/internal/logic/get_user_by_id_logic.go @@ -38,7 +38,7 @@ func (l *GetUserByIdLogic) GetUserById(in *core.UUIDReq) (*core.UserInfoResp, er logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/init_database_logic.go b/rpc/internal/logic/init_database_logic.go index 7c6911a7..034b18cc 100644 --- a/rpc/internal/logic/init_database_logic.go +++ b/rpc/internal/logic/init_database_logic.go @@ -49,7 +49,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) logx.Error("last initialization is running") return nil, statuserr.NewInternalError(errorx.InitRunning) } else { - logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.RedisError) } } @@ -62,7 +62,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) check, err := l.svcCtx.DB.API.Query().Count(l.ctx) //if err != nil { - // logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + // logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) // l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) // return nil, status.Error(codes.Internal, err.Error()) //} @@ -70,7 +70,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) if check != 0 { err := l.svcCtx.Redis.Set("database_init_state", "1") if err != nil { - logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, errorx.RedisError) } return &core.BaseResp{Msg: errorx.AlreadyInit}, nil @@ -82,51 +82,51 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) // initialize table structure if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false)); err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertUserData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertRoleData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertMenuData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertApiData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertRoleMenuAuthorityData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertCasbinPoliciesData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertProviderData() if err != nil { - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } diff --git a/rpc/internal/logic/login_logic.go b/rpc/internal/logic/login_logic.go index 59d1c5ad..4e3cb01e 100644 --- a/rpc/internal/logic/login_logic.go +++ b/rpc/internal/logic/login_logic.go @@ -42,7 +42,7 @@ func (l *LoginLogic) Login(in *core.LoginReq) (*core.LoginResp, error) { logx.Errorw("user not found", logx.Field("username", in.Username)) return nil, status.Error(codes.InvalidArgument, "login.userNotExist") } - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, errorx.DatabaseError) } @@ -73,7 +73,7 @@ func getRoleInfo(roleId uint64, rds *redis.Redis, db *ent.Client, ctx context.Co logx.Error("fail to find any roles") return "", "", status.Error(codes.NotFound, errorx.TargetNotFound) } - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return "", "", status.Error(codes.NotFound, errorx.TargetNotFound) } @@ -82,7 +82,7 @@ func getRoleInfo(roleId uint64, rds *redis.Redis, db *ent.Client, ctx context.Co err = rds.Hset("roleData", fmt.Sprintf("%d_value", v.ID), v.Value) err = rds.Hset("roleData", fmt.Sprintf("%d_status", v.ID), strconv.Itoa(int(v.Status))) if err != nil { - logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) return "", "", statuserr.NewInternalError(errorx.RedisError) } if v.ID == roleId { diff --git a/rpc/internal/logic/oauth_callback_logic.go b/rpc/internal/logic/oauth_callback_logic.go index 4f0a8e9b..8b865d87 100644 --- a/rpc/internal/logic/oauth_callback_logic.go +++ b/rpc/internal/logic/oauth_callback_logic.go @@ -54,7 +54,7 @@ func (l *OauthCallbackLogic) OauthCallback(in *core.CallbackReq) (*core.LoginRes logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -97,7 +97,7 @@ func (l *OauthCallbackLogic) OauthCallback(in *core.CallbackReq) (*core.LoginRes logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("login.userNotExist") default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/oauth_login_logic.go b/rpc/internal/logic/oauth_login_logic.go index 10ca48e1..d28f18f3 100644 --- a/rpc/internal/logic/oauth_login_logic.go +++ b/rpc/internal/logic/oauth_login_logic.go @@ -44,7 +44,7 @@ func (l *OauthLoginLogic) OauthLogin(in *core.OauthLoginReq) (*core.OauthRedirec logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_profile_logic.go b/rpc/internal/logic/update_profile_logic.go index f25cc05f..a6fb834e 100644 --- a/rpc/internal/logic/update_profile_logic.go +++ b/rpc/internal/logic/update_profile_logic.go @@ -60,7 +60,7 @@ func (l *UpdateProfileLogic) UpdateProfile(in *core.UpdateProfileReq) (*core.Bas logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_role_status_logic.go b/rpc/internal/logic/update_role_status_logic.go index 8334a144..e9581f5d 100644 --- a/rpc/internal/logic/update_role_status_logic.go +++ b/rpc/internal/logic/update_role_status_logic.go @@ -38,7 +38,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_token_status_logic.go b/rpc/internal/logic/update_token_status_logic.go index 06d9a742..16acda10 100644 --- a/rpc/internal/logic/update_token_status_logic.go +++ b/rpc/internal/logic/update_token_status_logic.go @@ -38,7 +38,7 @@ func (l *UpdateTokenStatusLogic) UpdateTokenStatus(in *core.StatusCodeReq) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_user_status_logic.go b/rpc/internal/logic/update_user_status_logic.go index b9f74f55..06df310b 100644 --- a/rpc/internal/logic/update_user_status_logic.go +++ b/rpc/internal/logic/update_user_status_logic.go @@ -36,7 +36,7 @@ func (l *UpdateUserStatusLogic) UpdateUserStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } From 5de1d18cd8e2e23d10390d9728219d2812d92b03 Mon Sep 17 00:00:00 2001 From: Ryan SU <1137661202@qq.com> Date: Sun, 13 Nov 2022 00:17:50 +0800 Subject: [PATCH 2/5] wip: error code optimize --- api/desc/apis.api | 13 +- api/desc/authority.api | 17 +- api/desc/base.api | 8 +- api/desc/captcha.api | 2 +- api/desc/core.api | 2 +- api/desc/dictionary.api | 24 +- api/desc/menu.api | 56 +- api/desc/oauth.api | 15 +- api/desc/role.api | 16 +- api/desc/token.api | 18 +- api/desc/user.api | 42 +- .../api/create_or_update_api_handler.go | 4 +- .../handler/api/delete_api_handler.go | 7 +- .../handler/api/get_api_list_handler.go | 5 +- .../create_or_update_api_authority_handler.go | 6 +- ...create_or_update_menu_authority_handler.go | 6 +- .../authority/get_api_authority_handler.go | 4 +- .../authority/get_menu_authority_handler.go | 4 +- .../handler/captcha/get_captcha_handler.go | 6 +- .../handler/core/health_check_handler.go | 2 +- .../handler/core/init_database_handler.go | 6 +- ...ate_or_update_dictionary_detail_handler.go | 6 +- .../create_or_update_dictionary_handler.go | 6 +- .../delete_dictionary_detail_handler.go | 6 +- .../dictionary/delete_dictionary_handler.go | 6 +- .../get_detail_by_dictionary_name_handler.go | 4 +- .../dictionary/get_dictionary_list_handler.go | 4 +- .../menu/create_or_update_menu_handler.go | 6 +- .../create_or_update_menu_param_handler.go | 6 +- .../handler/menu/delete_menu_handler.go | 6 +- .../handler/menu/delete_menu_param_handler.go | 6 +- .../handler/menu/get_menu_by_role_handler.go | 5 +- .../handler/menu/get_menu_list_handler.go | 5 +- .../get_menu_param_list_by_menu_id_handler.go | 4 +- .../create_or_update_provider_handler.go | 6 +- .../handler/oauth/delete_provider_handler.go | 6 +- .../oauth/get_provider_list_handler.go | 4 +- .../handler/oauth/oauth_callback_handler.go | 5 +- .../handler/oauth/oauth_login_handler.go | 4 +- .../role/create_or_update_role_handler.go | 6 +- .../handler/role/delete_role_handler.go | 6 +- .../handler/role/get_role_list_handler.go | 5 +- .../role/update_role_status_handler.go | 6 +- .../token/create_or_update_token_handler.go | 6 +- .../handler/token/delete_token_handler.go | 6 +- .../handler/token/get_token_list_handler.go | 4 +- api/internal/handler/token/logout_handler.go | 6 +- .../token/update_token_status_handler.go | 6 +- .../handler/user/change_password_handler.go | 6 +- .../user/create_or_update_user_handler.go | 6 +- .../handler/user/delete_user_handler.go | 6 +- .../handler/user/get_user_info_handler.go | 4 +- .../handler/user/get_user_list_handler.go | 4 +- .../user/get_user_perm_code_handler.go | 4 +- .../handler/user/get_user_profile_handler.go | 4 +- api/internal/handler/user/login_handler.go | 4 +- api/internal/handler/user/logout_handler.go | 6 +- api/internal/handler/user/register_handler.go | 6 +- .../user/update_user_profile_handler.go | 6 +- .../user/update_user_status_handler.go | 6 +- .../logic/api/create_or_update_api_logic.go | 4 +- api/internal/logic/api/delete_api_logic.go | 4 +- api/internal/logic/api/get_api_list_logic.go | 7 +- .../create_or_update_api_authority_logic.go | 29 +- .../create_or_update_menu_authority_logic.go | 13 +- .../authority/get_api_authority_logic.go | 15 +- .../authority/get_menu_authority_logic.go | 23 +- .../logic/captcha/get_captcha_logic.go | 32 +- api/internal/logic/core/health_check_logic.go | 9 +- .../logic/core/init_database_logic.go | 34 +- ...reate_or_update_dictionary_detail_logic.go | 13 +- .../create_or_update_dictionary_logic.go | 13 +- .../delete_dictionary_detail_logic.go | 13 +- .../dictionary/delete_dictionary_logic.go | 13 +- .../get_detail_by_dictionary_name_logic.go | 15 +- .../dictionary/get_dictionary_list_logic.go | 15 +- .../logic/menu/create_or_update_menu_logic.go | 15 +- .../menu/create_or_update_menu_param_logic.go | 13 +- api/internal/logic/menu/delete_menu_logic.go | 13 +- .../logic/menu/delete_menu_param_logic.go | 15 +- .../logic/menu/get_menu_by_role_logic.go | 14 +- .../logic/menu/get_menu_list_logic.go | 10 +- .../get_menu_param_list_by_menu_id_logic.go | 15 +- .../oauth/create_or_update_provider_logic.go | 15 +- .../logic/oauth/delete_provider_logic.go | 15 +- .../logic/oauth/get_provider_list_logic.go | 9 +- .../logic/oauth/oauth_callback_logic.go | 4 +- api/internal/logic/oauth/oauth_login_logic.go | 19 +- .../logic/role/create_or_update_role_logic.go | 17 +- api/internal/logic/role/delete_role_logic.go | 17 +- .../logic/role/get_role_list_logic.go | 14 +- .../logic/role/update_role_status_logic.go | 15 +- .../token/create_or_update_token_logic.go | 25 +- .../logic/token/delete_token_logic.go | 13 +- .../logic/token/get_token_list_logic.go | 15 +- api/internal/logic/token/logout_logic.go | 13 +- .../logic/token/update_token_status_logic.go | 13 +- .../logic/user/change_password_logic.go | 13 +- .../logic/user/create_or_update_user_logic.go | 15 +- api/internal/logic/user/delete_user_logic.go | 17 +- .../logic/user/get_user_info_logic.go | 29 +- .../logic/user/get_user_list_logic.go | 15 +- .../logic/user/get_user_perm_code_logic.go | 15 +- .../logic/user/get_user_profile_logic.go | 14 +- api/internal/logic/user/login_logic.go | 32 +- api/internal/logic/user/logout_logic.go | 13 +- api/internal/logic/user/register_logic.go | 21 +- .../logic/user/update_user_profile_logic.go | 13 +- .../logic/user/update_user_status_logic.go | 13 +- .../middleware/authority_middleware.go | 2 +- api/internal/types/types.go | 264 ++- core.yml | 1484 ++++++++++------- docs/simple-admin/en/docs/ent.md | 2 +- docs/simple-admin/en/docs/global_vars.md | 4 +- docs/simple-admin/zh-cn/docs/ent.md | 2 +- docs/simple-admin/zh-cn/docs/global_vars.md | 4 +- go.mod | 6 +- go.sum | 4 +- pkg/enum/errorcode.go | 166 ++ pkg/enum/status.go | 2 + pkg/i18n/locale/en.json | 4 + pkg/i18n/locale/zh.json | 4 + pkg/i18n/translator.go | 6 + pkg/i18n/var.go | 26 +- pkg/msg/logmsg/msg.go | 18 +- .../logic/block_user_all_token_logic.go | 6 +- rpc/internal/logic/change_password_logic.go | 4 +- .../logic/create_or_update_api_logic.go | 4 +- ...reate_or_update_dictionary_detail_logic.go | 6 +- .../create_or_update_dictionary_logic.go | 12 +- .../logic/create_or_update_menu_logic.go | 8 +- .../create_or_update_menu_param_logic.go | 6 +- .../logic/create_or_update_provider_logic.go | 4 +- .../logic/create_or_update_role_logic.go | 6 +- .../logic/create_or_update_token_logic.go | 4 +- .../logic/create_or_update_user_logic.go | 4 +- rpc/internal/logic/delete_api_logic.go | 2 +- .../logic/delete_dictionary_detail_logic.go | 2 +- rpc/internal/logic/delete_menu_logic.go | 6 +- rpc/internal/logic/delete_menu_param_logic.go | 2 +- rpc/internal/logic/delete_provider_logic.go | 2 +- rpc/internal/logic/delete_role_logic.go | 4 +- rpc/internal/logic/delete_token_logic.go | 2 +- rpc/internal/logic/delete_user_logic.go | 2 +- .../get_detail_by_dictionary_name_logic.go | 2 +- .../logic/get_menu_authority_logic.go | 2 +- .../logic/get_menu_list_by_role_logic.go | 2 +- .../get_menu_param_list_by_menu_id_logic.go | 2 +- rpc/internal/logic/get_role_by_id_logic.go | 2 +- rpc/internal/logic/get_token_list_logic.go | 2 +- rpc/internal/logic/get_user_by_id_logic.go | 2 +- rpc/internal/logic/init_database_logic.go | 22 +- rpc/internal/logic/login_logic.go | 6 +- rpc/internal/logic/oauth_callback_logic.go | 4 +- rpc/internal/logic/oauth_login_logic.go | 2 +- rpc/internal/logic/update_profile_logic.go | 2 +- .../logic/update_role_status_logic.go | 2 +- .../logic/update_token_status_logic.go | 2 +- .../logic/update_user_status_logic.go | 2 +- 159 files changed, 2031 insertions(+), 1341 deletions(-) create mode 100644 pkg/enum/errorcode.go diff --git a/api/desc/apis.api b/api/desc/apis.api index eb738e0b..5fc1ad8d 100644 --- a/api/desc/apis.api +++ b/api/desc/apis.api @@ -62,8 +62,15 @@ type ( } // The response data of API list | API列表数据 - // swagger:model ApiListResp ApiListResp { + BaseDataInfo + + // API list data | API 列表数据 + Data ApiListInfo `json:"data"` + } + + // API list data | API 列表数据 + ApiListInfo { BaseListInfo // The API list data | API列表数据 @@ -101,11 +108,11 @@ type ( service core { // Create or update API information | 创建或更新API @handler createOrUpdateApi - post /api (CreateOrUpdateApiReq) returns (SimpleMsg) + post /api (CreateOrUpdateApiReq) returns (BaseMsgResp) // Delete API information | 删除API信息 @handler deleteApi - delete /api (IDReq) returns (SimpleMsg) + delete /api (IDReq) returns (BaseMsgResp) // Get API list | 获取API列表 @handler getApiList diff --git a/api/desc/authority.api b/api/desc/authority.api index 4ca5cb56..cc71e0fb 100644 --- a/api/desc/authority.api +++ b/api/desc/authority.api @@ -33,9 +33,16 @@ type ( Data []ApiAuthorityInfo `json:"data"` } - // The response data of api authorization list | API授权列表数据 - // swagger:model ApiAuthorityListResp + // The response data of api authorization list | API授权列表返回数据 ApiAuthorityListResp { + BaseDataInfo + + // The api authorization list data | API授权列表数据 + Data ApiAuthorityListInfo `json:"data"` + } + + // The data of api authorization list | API授权列表数据 + ApiAuthorityListInfo { BaseListInfo // The api authorization list data | API授权列表数据 @@ -59,7 +66,7 @@ type ( BaseDataInfo // The menu authorization data | 菜单授权信息数据 - Data []MenuAuthorityInfoReq `json:"data"` + Data MenuAuthorityInfoReq `json:"data"` } ) @@ -72,7 +79,7 @@ type ( service core { // Create or update API authorization information | 创建或更新API权限 @handler createOrUpdateApiAuthority - post /authority/api (CreateOrUpdateApiAuthorityReq) returns (SimpleMsg) + post /authority/api (CreateOrUpdateApiAuthorityReq) returns (BaseMsgResp) // Get role's API authorization list | 获取角色api权限列表 @handler getApiAuthority @@ -80,7 +87,7 @@ service core { // Create or update menu authorization information | 创建或更新菜单权限 @handler createOrUpdateMenuAuthority - post /authority/menu (MenuAuthorityInfoReq) returns (SimpleMsg) + post /authority/menu (MenuAuthorityInfoReq) returns (BaseMsgResp) // Get role's menu authorization list | 获取角色菜单权限列表 @handler getMenuAuthority diff --git a/api/desc/base.api b/api/desc/base.api index 6d4f361a..51c6d25e 100644 --- a/api/desc/base.api +++ b/api/desc/base.api @@ -22,12 +22,6 @@ type BaseDataInfo { // The basic response with data | 基础带数据信息 type BaseListInfo { - // Error code | 错误代码 - Code int `json:"code"` - - // Message | 提示信息 - Msg string `json:"msg"` - // The total number of data | 数据总数 Total uint64 `json:"total"` @@ -36,7 +30,7 @@ type BaseListInfo { } // The basic response without data | 基础不带数据信息 -type BaseMsgInfo { +type BaseMsgResp { // Error code | 错误代码 Code int `json:"code"` diff --git a/api/desc/captcha.api b/api/desc/captcha.api index f6265b9f..6eaa8147 100644 --- a/api/desc/captcha.api +++ b/api/desc/captcha.api @@ -21,7 +21,7 @@ type CaptchaResp { BaseDataInfo // The menu authorization data | 菜单授权信息数据 - Data []CaptchaInfo `json:"data"` + Data CaptchaInfo `json:"data"` } @server( diff --git a/api/desc/core.api b/api/desc/core.api index 48ddd65a..c96fac73 100644 --- a/api/desc/core.api +++ b/api/desc/core.api @@ -30,5 +30,5 @@ service core { // Initialize database | 初始化数据库 @handler initDatabase - get /core/init/database returns (SimpleMsg) + get /core/init/database returns (BaseMsgResp) } \ No newline at end of file diff --git a/api/desc/dictionary.api b/api/desc/dictionary.api index 728d4fb8..ac20df27 100644 --- a/api/desc/dictionary.api +++ b/api/desc/dictionary.api @@ -58,6 +58,14 @@ type ( // The response data of dictionary list | 字典列表数据 DictionaryListResp { + BaseDataInfo + + // The dictionary list data | 字典列表数据 + Data DictionaryListInfo `json:"data"` + } + + // The response data of dictionary list | 字典列表数据 + DictionaryListInfo { BaseListInfo // The dictionary list data | 字典列表数据 @@ -96,6 +104,14 @@ type ( // The response data of dictionary KV list | 字典值的列表数据 DictionaryDetailListResp { + BaseDataInfo + + // The dictionary list data | 字典列表数据 + Data DictionaryDetailListInfo `json:"data"` + } + + // The data of dictionary KV list | 字典值的列表数据 + DictionaryDetailListInfo { BaseListInfo // The dictionary list data | 字典列表数据 @@ -149,11 +165,11 @@ type ( service core { // Create or update dictionary information | 创建或更新字典信息 @handler createOrUpdateDictionary - post /dict (CreateOrUpdateDictionaryReq) returns (SimpleMsg) + post /dict (CreateOrUpdateDictionaryReq) returns (BaseMsgResp) // Delete dictionary information | 删除字典信息 @handler deleteDictionary - delete /dict (IDReq) returns (SimpleMsg) + delete /dict (IDReq) returns (BaseMsgResp) // Get dictionary list | 获取字典列表 @handler getDictionaryList @@ -161,11 +177,11 @@ service core { // Create or update dictionary KV information | 创建或更新字典键值信息 @handler createOrUpdateDictionaryDetail - post /dict/detail (CreateOrUpdateDictionaryDetailReq) returns (SimpleMsg) + post /dict/detail (CreateOrUpdateDictionaryDetailReq) returns (BaseMsgResp) // Delete dictionary KV information | 删除字典键值信息 @handler deleteDictionaryDetail - delete /dict/detail (IDReq) returns (SimpleMsg) + delete /dict/detail (IDReq) returns (BaseMsgResp) // Get dictionary detail list by dictionary name | 根据字典名获取字典键值列表 @handler getDetailByDictionaryName diff --git a/api/desc/menu.api b/api/desc/menu.api index 222c520b..b30636f0 100644 --- a/api/desc/menu.api +++ b/api/desc/menu.api @@ -100,15 +100,23 @@ type ( RealPath string `json:"realPath,omitempty" validate:"max=200"` } - // The response data of menu list | 菜单列表数据 + // The response data of menu list | 菜单列表返回数据 MenuListResp { + BaseDataInfo + + // The menu list data | 菜单列表数据 + Data MenuListInfo `json:"data"` + } + + // The data of menu list | 菜单列表数据 + MenuListInfo { BaseListInfo // The menu list data | 菜单列表数据 Data []*MenuInfo `json:"data"` } - // The response data of role menu list, show after user login | 角色菜单列表数据, 登录后自动获取 + // The response data of role menu list data | 角色菜单列表数据 GetMenuListBase { // Menu type: directory or menu | 菜单类型: 目录或菜单 menuType uint32 `json:"type"` @@ -145,6 +153,22 @@ type ( Children []*GetMenuListBase `json:"children"` } + // The response data of role menu list, show after user login | 角色菜单列表数据, 登录后自动获取 + GetMenuListBaseResp { + BaseDataInfo + + // The data of role menu list data | 角色菜单列表数据 + Data GetMenuListBaseInfo `json:"data"` + } + + // The data of role menu list, show after user login | 角色菜单列表数据 + GetMenuListBaseInfo { + BaseListInfo + + // The response data of role menu list data | 角色菜单列表数据 + Data []*GetMenuListBase `json:"data"` + } + // Create or update menu information request params | 创建或更新菜单信息参数 CreateOrUpdateMenuReq { // ID @@ -225,8 +249,16 @@ type ( Value string `json:"value" validate:"min=1,max=100"` } - // The response data of menu parameters | 菜单参数列表数据 + // The response data of menu parameters | 菜单参数返回数据 MenuParamResp { + BaseDataInfo + + // The information of menu parameter | 菜单参数数据 + Data MenuParamInfo `json:"data"` + } + + // The information of menu parameter | 菜单参数数据 + MenuParamInfo { BaseInfo // Data Type | 数据类型 @@ -241,10 +273,18 @@ type ( // The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 MenuParamListByMenuIdResp { + BaseDataInfo + + // The menu list data | 菜单列表数据 + Data MenuParamListByMenuIdInfo `json:"data"` + } + + // The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 + MenuParamListByMenuIdInfo { BaseListInfo // The menu list data | 菜单列表数据 - Data []MenuParamResp `json:"data"` + Data []MenuParamInfo `json:"data"` } ) @@ -257,11 +297,11 @@ type ( service core { // Create or update menu information | 创建或更新菜单 @handler createOrUpdateMenu - post /menu (CreateOrUpdateMenuReq) returns (SimpleMsg) + post /menu (CreateOrUpdateMenuReq) returns (BaseMsgResp) // Delete menu information | 删除菜单信息 @handler deleteMenu - delete /menu (IDReq) returns (SimpleMsg) + delete /menu (IDReq) returns (BaseMsgResp) // Get menu list | 获取菜单列表 @handler getMenuList @@ -273,7 +313,7 @@ service core { // Create or update menu parameters | 创建或更新菜单参数 @handler createOrUpdateMenuParam - post /menu/param (CreateOrUpdateMenuParamReq) returns (SimpleMsg) + post /menu/param (CreateOrUpdateMenuParamReq) returns (BaseMsgResp) // Get menu extra parameters by menu ID | 获取某个菜单的额外参数列表 @handler getMenuParamListByMenuId @@ -281,5 +321,5 @@ service core { // Delete menu extra parameters | 删除菜单额外参数 @handler deleteMenuParam - delete /menu/param (IDReq) returns (SimpleMsg) + delete /menu/param (IDReq) returns (BaseMsgResp) } diff --git a/api/desc/oauth.api b/api/desc/oauth.api index 60cad6ea..66df0e93 100644 --- a/api/desc/oauth.api +++ b/api/desc/oauth.api @@ -121,8 +121,17 @@ type ( Provider string `json:"provider" validate:"max=40"` } - // Redirect response | 跳转网址 + // Redirect response | 跳转网址返回信息 RedirectResp { + BaseDataInfo + + // Redirect information | 跳转网址 + Data RedirectInfo `json:"data"` + } + + // Redirect information | 跳转网址 + RedirectInfo { + // Redirect URL | 跳转网址 URL string `json:"URL"` } @@ -166,11 +175,11 @@ service core { service core { // Create or update Provider information | 创建或更新提供商 @handler createOrUpdateProvider - post /oauth/provider (CreateOrUpdateProviderReq) returns (SimpleMsg) + post /oauth/provider (CreateOrUpdateProviderReq) returns (BaseMsgResp) // Delete provider information | 删除提供商信息 @handler deleteProvider - delete /oauth/provider (IDReq) returns (SimpleMsg) + delete /oauth/provider (IDReq) returns (BaseMsgResp) // Get provider list | 获取提供商列表 @handler getProviderList diff --git a/api/desc/role.api b/api/desc/role.api index 0f01f725..a182a7c2 100644 --- a/api/desc/role.api +++ b/api/desc/role.api @@ -49,8 +49,16 @@ type ( OrderNo uint32 `json:"orderNo" validate:"number,max=1000"` } - // The response data of role list | 角色列表数据 + // The response data of role list | 角色列表返回数据 RoleListResp { + BaseDataInfo + + // The role list data | 角色列表数据 + Data RoleListInfo `json:"data"` + } + + // The data of role list | 角色列表数据 + RoleListInfo { BaseListInfo // The role list data | 角色列表数据 @@ -67,11 +75,11 @@ type ( service core { // Create or update role information | 创建或更新角色 @handler createOrUpdateRole - post /role (RoleInfo) returns (SimpleMsg) + post /role (RoleInfo) returns (BaseMsgResp) // Delete role information | 删除角色信息 @handler deleteRole - delete /role (IDReq) returns (SimpleMsg) + delete /role (IDReq) returns (BaseMsgResp) // Get role list | 获取角色列表 @handler getRoleList @@ -79,5 +87,5 @@ service core { // Set role status | 设置角色状态 @handler updateRoleStatus - post /role/status (StatusCodeReq) returns (SimpleMsg) + post /role/status (StatusCodeReq) returns (BaseMsgResp) } diff --git a/api/desc/token.api b/api/desc/token.api index 3ad80a4c..f99b8917 100644 --- a/api/desc/token.api +++ b/api/desc/token.api @@ -60,8 +60,16 @@ type ( ExpiredAt int64 `json:"expiredAt" validate:"number"` } - // The response data of Token list | Token列表数据 + // The response data of Token list | Token列表返回数据 TokenListResp { + BaseDataInfo + + // The token list data | Token列表数据 + Data TokenListInfo `json:"data"` + } + + // The data of Token list | Token列表数据 + TokenListInfo { BaseListInfo // The token list data | Token列表数据 @@ -98,11 +106,11 @@ type ( service core { // Create or update Token information | 创建或更新Token @handler createOrUpdateToken - post /token (CreateOrUpdateTokenReq) returns (SimpleMsg) + post /token (CreateOrUpdateTokenReq) returns (BaseMsgResp) // Delete token information | 删除token信息 @handler deleteToken - delete /token (IDReq) returns (SimpleMsg) + delete /token (IDReq) returns (BaseMsgResp) // Get Token list | 获取token列表 @handler getTokenList @@ -110,9 +118,9 @@ service core { // Set token status | 设置token状态 @handler updateTokenStatus - post /token/status (StatusCodeReq) returns (SimpleMsg) + post /token/status (StatusCodeReq) returns (BaseMsgResp) // Force logging out by user UUID | 根据UUID强制用户退出 @handler logout - post /token/logout (UUIDReq) returns (SimpleMsg) + post /token/logout (UUIDReq) returns (BaseMsgResp) } diff --git a/api/desc/user.api b/api/desc/user.api index a5709427..cdca8724 100644 --- a/api/desc/user.api +++ b/api/desc/user.api @@ -35,8 +35,16 @@ type ( Captcha string `json:"captcha" validate:"len=5"` } - // The login response data | 登录返回数据 + // The log in response data | 登录返回数据 LoginResp { + BaseDataInfo + + // The log in information | 登陆返回的数据信息 + Data LoginInfo `json:"data"` + } + + // The log in information | 登陆返回的数据信息 + LoginInfo { // User's UUID | 用户的UUID UserId string `json:"userId"` @@ -180,6 +188,14 @@ type ( // The response data of user's basic information | 用户基本信息返回数据 GetUserInfoResp { + BaseDataInfo + + // The data of user's basic information | 用户基本信息 + Data UserBaseInfo `json:"data"` + } + + // The data of user's basic information | 用户基本信息 + UserBaseInfo { // User's UUID | 用户的UUID UUID string `json:"userId"` @@ -206,8 +222,16 @@ type ( Value string `json:"value"` } - // The response data of user list | 用户列表数据 + // The response data of user list | 用户列表返回数据 UserListResp { + BaseDataInfo + + // The user list data | 用户列表数据 + Data UserListInfo `json:"data"` + } + + // The response data of user list | 用户列表数据 + UserListInfo { BaseListInfo // The user list data | 用户列表数据 @@ -315,7 +339,7 @@ service core { // Register | 注册 @handler register - post /user/register (RegisterReq) returns (SimpleMsg) + post /user/register (RegisterReq) returns (BaseMsgResp) } @server( @@ -327,7 +351,7 @@ service core { service core { // Change Password | 修改密码 @handler changePassword - post /user/change-password (ChangePasswordReq) returns (SimpleMsg) + post /user/change-password (ChangePasswordReq) returns (BaseMsgResp) // Get user basic information | 获取用户基本信息 @handler getUserInfo @@ -335,7 +359,7 @@ service core { // Create or update user's information | 新增或更新用户 @handler createOrUpdateUser - post /user (CreateOrUpdateUserReq) returns (SimpleMsg) + post /user (CreateOrUpdateUserReq) returns (BaseMsgResp) // Get user list | 获取用户列表 @handler getUserList @@ -343,7 +367,7 @@ service core { // Delete user information | 删除用户信息 @handler deleteUser - delete /user (IDReq) returns (SimpleMsg) + delete /user (IDReq) returns (BaseMsgResp) // Get user's permission code | 获取用户权限码 @handler getUserPermCode @@ -355,13 +379,13 @@ service core { // Update user's profile | 更新用户个人信息 @handler updateUserProfile - post /user/profile (ProfileReq) returns (SimpleMsg) + post /user/profile (ProfileReq) returns (BaseMsgResp) // Set user's status | 更新用户状态 @handler updateUserStatus - post /user/status (StatusCodeReq) returns (SimpleMsg) + post /user/status (StatusCodeReq) returns (BaseMsgResp) // Log out | 退出登陆 @handler logout - get /user/logout returns (SimpleMsg) + get /user/logout returns (BaseMsgResp) } diff --git a/api/internal/handler/api/create_or_update_api_handler.go b/api/internal/handler/api/create_or_update_api_handler.go index 044605ca..64ad19f7 100644 --- a/api/internal/handler/api/create_or_update_api_handler.go +++ b/api/internal/handler/api/create_or_update_api_handler.go @@ -23,9 +23,7 @@ import ( // type: CreateOrUpdateApiReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/api/delete_api_handler.go b/api/internal/handler/api/delete_api_handler.go index 530cb05a..5ee8351b 100644 --- a/api/internal/handler/api/delete_api_handler.go +++ b/api/internal/handler/api/delete_api_handler.go @@ -3,11 +3,10 @@ package api import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/api" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route delete /api api DeleteApi @@ -23,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/api/get_api_list_handler.go b/api/internal/handler/api/get_api_list_handler.go index c3863399..c45311d7 100644 --- a/api/internal/handler/api/get_api_list_handler.go +++ b/api/internal/handler/api/get_api_list_handler.go @@ -3,11 +3,10 @@ package api import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/api" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route post /api/list api GetApiList @@ -24,8 +23,6 @@ import ( // // Responses: // 200: ApiListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetApiListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/authority/create_or_update_api_authority_handler.go b/api/internal/handler/authority/create_or_update_api_authority_handler.go index d1f773da..6f123af0 100644 --- a/api/internal/handler/authority/create_or_update_api_authority_handler.go +++ b/api/internal/handler/authority/create_or_update_api_authority_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateApiAuthorityReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerF return } - l := authority.NewCreateOrUpdateApiAuthorityLogic(r.Context(), svcCtx) + l := authority.NewCreateOrUpdateApiAuthorityLogic(r, svcCtx) resp, err := l.CreateOrUpdateApiAuthority(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/authority/create_or_update_menu_authority_handler.go b/api/internal/handler/authority/create_or_update_menu_authority_handler.go index fc549498..85584f8d 100644 --- a/api/internal/handler/authority/create_or_update_menu_authority_handler.go +++ b/api/internal/handler/authority/create_or_update_menu_authority_handler.go @@ -22,9 +22,7 @@ import ( // type: MenuAuthorityInfoReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.Handler return } - l := authority.NewCreateOrUpdateMenuAuthorityLogic(r.Context(), svcCtx) + l := authority.NewCreateOrUpdateMenuAuthorityLogic(r, svcCtx) resp, err := l.CreateOrUpdateMenuAuthority(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/authority/get_api_authority_handler.go b/api/internal/handler/authority/get_api_authority_handler.go index f1f5cff1..e93b4a94 100644 --- a/api/internal/handler/authority/get_api_authority_handler.go +++ b/api/internal/handler/authority/get_api_authority_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: ApiAuthorityListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := authority.NewGetApiAuthorityLogic(r.Context(), svcCtx) + l := authority.NewGetApiAuthorityLogic(r, svcCtx) resp, err := l.GetApiAuthority(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/authority/get_menu_authority_handler.go b/api/internal/handler/authority/get_menu_authority_handler.go index 11eb8c79..fbf3856e 100644 --- a/api/internal/handler/authority/get_menu_authority_handler.go +++ b/api/internal/handler/authority/get_menu_authority_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: MenuAuthorityInfoResp -// 401: SimpleMsg -// 500: SimpleMsg func GetMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := authority.NewGetMenuAuthorityLogic(r.Context(), svcCtx) + l := authority.NewGetMenuAuthorityLogic(r, svcCtx) resp, err := l.GetMenuAuthority(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/captcha/get_captcha_handler.go b/api/internal/handler/captcha/get_captcha_handler.go index a703393b..d7859cca 100644 --- a/api/internal/handler/captcha/get_captcha_handler.go +++ b/api/internal/handler/captcha/get_captcha_handler.go @@ -15,13 +15,11 @@ import ( // Get captcha | 获取验证码 // // Responses: -// 200: CaptchaInfo -// 401: SimpleMsg -// 500: SimpleMsg +// 200: CaptchaResp func GetCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := captcha.NewGetCaptchaLogic(r.Context(), svcCtx) + l := captcha.NewGetCaptchaLogic(r, svcCtx) resp, err := l.GetCaptcha() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/core/health_check_handler.go b/api/internal/handler/core/health_check_handler.go index b5ec027a..ec3ff421 100644 --- a/api/internal/handler/core/health_check_handler.go +++ b/api/internal/handler/core/health_check_handler.go @@ -17,7 +17,7 @@ import ( func HealthCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := core.NewHealthCheckLogic(r.Context(), svcCtx) + l := core.NewHealthCheckLogic(r, svcCtx) err := l.HealthCheck() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/core/init_database_handler.go b/api/internal/handler/core/init_database_handler.go index dd5d92ed..2c3e5740 100644 --- a/api/internal/handler/core/init_database_handler.go +++ b/api/internal/handler/core/init_database_handler.go @@ -15,13 +15,11 @@ import ( // Initialize database | 初始化数据库 // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func InitDatabaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := core.NewInitDatabaseLogic(r.Context(), svcCtx) + l := core.NewInitDatabaseLogic(r, svcCtx) resp, err := l.InitDatabase() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/create_or_update_dictionary_detail_handler.go b/api/internal/handler/dictionary/create_or_update_dictionary_detail_handler.go index 4c98e8b5..d4027b02 100644 --- a/api/internal/handler/dictionary/create_or_update_dictionary_detail_handler.go +++ b/api/internal/handler/dictionary/create_or_update_dictionary_detail_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateDictionaryDetailReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.Hand return } - l := dictionary.NewCreateOrUpdateDictionaryDetailLogic(r.Context(), svcCtx) + l := dictionary.NewCreateOrUpdateDictionaryDetailLogic(r, svcCtx) resp, err := l.CreateOrUpdateDictionaryDetail(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/create_or_update_dictionary_handler.go b/api/internal/handler/dictionary/create_or_update_dictionary_handler.go index c7c3b21c..1c6412d2 100644 --- a/api/internal/handler/dictionary/create_or_update_dictionary_handler.go +++ b/api/internal/handler/dictionary/create_or_update_dictionary_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateDictionaryReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFun return } - l := dictionary.NewCreateOrUpdateDictionaryLogic(r.Context(), svcCtx) + l := dictionary.NewCreateOrUpdateDictionaryLogic(r, svcCtx) resp, err := l.CreateOrUpdateDictionary(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/delete_dictionary_detail_handler.go b/api/internal/handler/dictionary/delete_dictionary_detail_handler.go index 61bfbd7e..8961ae7f 100644 --- a/api/internal/handler/dictionary/delete_dictionary_detail_handler.go +++ b/api/internal/handler/dictionary/delete_dictionary_detail_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc return } - l := dictionary.NewDeleteDictionaryDetailLogic(r.Context(), svcCtx) + l := dictionary.NewDeleteDictionaryDetailLogic(r, svcCtx) resp, err := l.DeleteDictionaryDetail(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/delete_dictionary_handler.go b/api/internal/handler/dictionary/delete_dictionary_handler.go index 44fb978d..ef55f859 100644 --- a/api/internal/handler/dictionary/delete_dictionary_handler.go +++ b/api/internal/handler/dictionary/delete_dictionary_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := dictionary.NewDeleteDictionaryLogic(r.Context(), svcCtx) + l := dictionary.NewDeleteDictionaryLogic(r, svcCtx) resp, err := l.DeleteDictionary(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/get_detail_by_dictionary_name_handler.go b/api/internal/handler/dictionary/get_detail_by_dictionary_name_handler.go index c8767974..0c28adb7 100644 --- a/api/internal/handler/dictionary/get_detail_by_dictionary_name_handler.go +++ b/api/internal/handler/dictionary/get_detail_by_dictionary_name_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: DictionaryDetailListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetDetailByDictionaryNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetDetailByDictionaryNameHandler(svcCtx *svc.ServiceContext) http.HandlerFu return } - l := dictionary.NewGetDetailByDictionaryNameLogic(r.Context(), svcCtx) + l := dictionary.NewGetDetailByDictionaryNameLogic(r, svcCtx) resp, err := l.GetDetailByDictionaryName(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/dictionary/get_dictionary_list_handler.go b/api/internal/handler/dictionary/get_dictionary_list_handler.go index 704d533c..a823085c 100644 --- a/api/internal/handler/dictionary/get_dictionary_list_handler.go +++ b/api/internal/handler/dictionary/get_dictionary_list_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: DictionaryListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetDictionaryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetDictionaryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := dictionary.NewGetDictionaryListLogic(r.Context(), svcCtx) + l := dictionary.NewGetDictionaryListLogic(r, svcCtx) resp, err := l.GetDictionaryList(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/menu/create_or_update_menu_handler.go b/api/internal/handler/menu/create_or_update_menu_handler.go index 012890c0..c4ac3725 100644 --- a/api/internal/handler/menu/create_or_update_menu_handler.go +++ b/api/internal/handler/menu/create_or_update_menu_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateMenuReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := menu.NewCreateOrUpdateMenuLogic(r.Context(), svcCtx) + l := menu.NewCreateOrUpdateMenuLogic(r, svcCtx) resp, err := l.CreateOrUpdateMenu(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/menu/create_or_update_menu_param_handler.go b/api/internal/handler/menu/create_or_update_menu_param_handler.go index 90dd7c63..efdfe496 100644 --- a/api/internal/handler/menu/create_or_update_menu_param_handler.go +++ b/api/internal/handler/menu/create_or_update_menu_param_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateMenuParamReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc return } - l := menu.NewCreateOrUpdateMenuParamLogic(r.Context(), svcCtx) + l := menu.NewCreateOrUpdateMenuParamLogic(r, svcCtx) resp, err := l.CreateOrUpdateMenuParam(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/menu/delete_menu_handler.go b/api/internal/handler/menu/delete_menu_handler.go index 8a6ef4cc..500dfcc7 100644 --- a/api/internal/handler/menu/delete_menu_handler.go +++ b/api/internal/handler/menu/delete_menu_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := menu.NewDeleteMenuLogic(r.Context(), svcCtx) + l := menu.NewDeleteMenuLogic(r, svcCtx) resp, err := l.DeleteMenu(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/menu/delete_menu_param_handler.go b/api/internal/handler/menu/delete_menu_param_handler.go index 0f833476..c5df0a93 100644 --- a/api/internal/handler/menu/delete_menu_param_handler.go +++ b/api/internal/handler/menu/delete_menu_param_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := menu.NewDeleteMenuParamLogic(r.Context(), svcCtx) + l := menu.NewDeleteMenuParamLogic(r, svcCtx) resp, err := l.DeleteMenuParam(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/menu/get_menu_by_role_handler.go b/api/internal/handler/menu/get_menu_by_role_handler.go index 7967e702..30c79b93 100644 --- a/api/internal/handler/menu/get_menu_by_role_handler.go +++ b/api/internal/handler/menu/get_menu_by_role_handler.go @@ -3,10 +3,9 @@ package menu import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/menu" "github.com/suyuan32/simple-admin-core/api/internal/svc" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route get /menu/role menu GetMenuByRole @@ -17,8 +16,6 @@ import ( // // Responses: // 200: GetMenuListBase -// 401: SimpleMsg -// 500: SimpleMsg func GetMenuByRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/menu/get_menu_list_handler.go b/api/internal/handler/menu/get_menu_list_handler.go index afd7b67b..e9f5cf44 100644 --- a/api/internal/handler/menu/get_menu_list_handler.go +++ b/api/internal/handler/menu/get_menu_list_handler.go @@ -3,10 +3,9 @@ package menu import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/menu" "github.com/suyuan32/simple-admin-core/api/internal/svc" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route get /menu/list menu GetMenuList @@ -17,8 +16,6 @@ import ( // // Responses: // 200: MenuListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetMenuListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/menu/get_menu_param_list_by_menu_id_handler.go b/api/internal/handler/menu/get_menu_param_list_by_menu_id_handler.go index e88de1c2..6814105a 100644 --- a/api/internal/handler/menu/get_menu_param_list_by_menu_id_handler.go +++ b/api/internal/handler/menu/get_menu_param_list_by_menu_id_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: MenuParamListByMenuIdResp -// 401: SimpleMsg -// 500: SimpleMsg func GetMenuParamListByMenuIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetMenuParamListByMenuIdHandler(svcCtx *svc.ServiceContext) http.HandlerFun return } - l := menu.NewGetMenuParamListByMenuIdLogic(r.Context(), svcCtx) + l := menu.NewGetMenuParamListByMenuIdLogic(r, svcCtx) resp, err := l.GetMenuParamListByMenuId(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/oauth/create_or_update_provider_handler.go b/api/internal/handler/oauth/create_or_update_provider_handler.go index 8b4a9c06..13347d0e 100644 --- a/api/internal/handler/oauth/create_or_update_provider_handler.go +++ b/api/internal/handler/oauth/create_or_update_provider_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateProviderReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc return } - l := oauth.NewCreateOrUpdateProviderLogic(r.Context(), svcCtx) + l := oauth.NewCreateOrUpdateProviderLogic(r, svcCtx) resp, err := l.CreateOrUpdateProvider(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/oauth/delete_provider_handler.go b/api/internal/handler/oauth/delete_provider_handler.go index 6027c653..863fa792 100644 --- a/api/internal/handler/oauth/delete_provider_handler.go +++ b/api/internal/handler/oauth/delete_provider_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := oauth.NewDeleteProviderLogic(r.Context(), svcCtx) + l := oauth.NewDeleteProviderLogic(r, svcCtx) resp, err := l.DeleteProvider(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/oauth/get_provider_list_handler.go b/api/internal/handler/oauth/get_provider_list_handler.go index 88714603..f3ae93d7 100644 --- a/api/internal/handler/oauth/get_provider_list_handler.go +++ b/api/internal/handler/oauth/get_provider_list_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: ProviderListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetProviderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetProviderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := oauth.NewGetProviderListLogic(r.Context(), svcCtx) + l := oauth.NewGetProviderListLogic(r, svcCtx) resp, err := l.GetProviderList(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/oauth/oauth_callback_handler.go b/api/internal/handler/oauth/oauth_callback_handler.go index 653a549b..17e7d927 100644 --- a/api/internal/handler/oauth/oauth_callback_handler.go +++ b/api/internal/handler/oauth/oauth_callback_handler.go @@ -3,10 +3,9 @@ package oauth import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/oauth" "github.com/suyuan32/simple-admin-core/api/internal/svc" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route get /oauth/login/callback oauth OauthCallback @@ -17,8 +16,6 @@ import ( // // Responses: // 200: CallbackResp -// 401: SimpleMsg -// 500: SimpleMsg func OauthCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/oauth/oauth_login_handler.go b/api/internal/handler/oauth/oauth_login_handler.go index 753a5309..1e670d94 100644 --- a/api/internal/handler/oauth/oauth_login_handler.go +++ b/api/internal/handler/oauth/oauth_login_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: RedirectResp -// 401: SimpleMsg -// 500: SimpleMsg func OauthLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func OauthLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := oauth.NewOauthLoginLogic(r.Context(), svcCtx) + l := oauth.NewOauthLoginLogic(r, svcCtx) resp, err := l.OauthLogin(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/role/create_or_update_role_handler.go b/api/internal/handler/role/create_or_update_role_handler.go index 25929324..af4ec56a 100644 --- a/api/internal/handler/role/create_or_update_role_handler.go +++ b/api/internal/handler/role/create_or_update_role_handler.go @@ -22,9 +22,7 @@ import ( // type: RoleInfo // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := role.NewCreateOrUpdateRoleLogic(r.Context(), svcCtx) + l := role.NewCreateOrUpdateRoleLogic(r, svcCtx) resp, err := l.CreateOrUpdateRole(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/role/delete_role_handler.go b/api/internal/handler/role/delete_role_handler.go index 8c09db71..040ecc82 100644 --- a/api/internal/handler/role/delete_role_handler.go +++ b/api/internal/handler/role/delete_role_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := role.NewDeleteRoleLogic(r.Context(), svcCtx) + l := role.NewDeleteRoleLogic(r, svcCtx) resp, err := l.DeleteRole(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/role/get_role_list_handler.go b/api/internal/handler/role/get_role_list_handler.go index 8149b67d..8d16c532 100644 --- a/api/internal/handler/role/get_role_list_handler.go +++ b/api/internal/handler/role/get_role_list_handler.go @@ -3,11 +3,10 @@ package role import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" - "github.com/suyuan32/simple-admin-core/api/internal/logic/role" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" ) // swagger:route post /role/list role GetRoleList @@ -24,8 +23,6 @@ import ( // // Responses: // 200: RoleListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetRoleListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/api/internal/handler/role/update_role_status_handler.go b/api/internal/handler/role/update_role_status_handler.go index b25f2ed4..79db2d37 100644 --- a/api/internal/handler/role/update_role_status_handler.go +++ b/api/internal/handler/role/update_role_status_handler.go @@ -22,9 +22,7 @@ import ( // type: StatusCodeReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func UpdateRoleStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func UpdateRoleStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := role.NewUpdateRoleStatusLogic(r.Context(), svcCtx) + l := role.NewUpdateRoleStatusLogic(r, svcCtx) resp, err := l.UpdateRoleStatus(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/token/create_or_update_token_handler.go b/api/internal/handler/token/create_or_update_token_handler.go index c14c3c3d..58b5f8ba 100644 --- a/api/internal/handler/token/create_or_update_token_handler.go +++ b/api/internal/handler/token/create_or_update_token_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateTokenReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := token.NewCreateOrUpdateTokenLogic(r.Context(), svcCtx) + l := token.NewCreateOrUpdateTokenLogic(r, svcCtx) resp, err := l.CreateOrUpdateToken(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/token/delete_token_handler.go b/api/internal/handler/token/delete_token_handler.go index afe9ca4a..f510cf29 100644 --- a/api/internal/handler/token/delete_token_handler.go +++ b/api/internal/handler/token/delete_token_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := token.NewDeleteTokenLogic(r.Context(), svcCtx) + l := token.NewDeleteTokenLogic(r, svcCtx) resp, err := l.DeleteToken(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/token/get_token_list_handler.go b/api/internal/handler/token/get_token_list_handler.go index 1d4ec4c1..c64784d5 100644 --- a/api/internal/handler/token/get_token_list_handler.go +++ b/api/internal/handler/token/get_token_list_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: TokenListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetTokenListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetTokenListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := token.NewGetTokenListLogic(r.Context(), svcCtx) + l := token.NewGetTokenListLogic(r, svcCtx) resp, err := l.GetTokenList(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/token/logout_handler.go b/api/internal/handler/token/logout_handler.go index 2afcb216..84a5f1ef 100644 --- a/api/internal/handler/token/logout_handler.go +++ b/api/internal/handler/token/logout_handler.go @@ -22,9 +22,7 @@ import ( // type: UUIDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := token.NewLogoutLogic(r.Context(), svcCtx) + l := token.NewLogoutLogic(r, svcCtx) resp, err := l.Logout(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/token/update_token_status_handler.go b/api/internal/handler/token/update_token_status_handler.go index 33ff12e7..7d12fcd0 100644 --- a/api/internal/handler/token/update_token_status_handler.go +++ b/api/internal/handler/token/update_token_status_handler.go @@ -22,9 +22,7 @@ import ( // type: StatusCodeReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func UpdateTokenStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func UpdateTokenStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := token.NewUpdateTokenStatusLogic(r.Context(), svcCtx) + l := token.NewUpdateTokenStatusLogic(r, svcCtx) resp, err := l.UpdateTokenStatus(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/change_password_handler.go b/api/internal/handler/user/change_password_handler.go index 7188be28..0b03bb8e 100644 --- a/api/internal/handler/user/change_password_handler.go +++ b/api/internal/handler/user/change_password_handler.go @@ -22,9 +22,7 @@ import ( // type: ChangePasswordReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewChangePasswordLogic(r.Context(), svcCtx) + l := user.NewChangePasswordLogic(r, svcCtx) resp, err := l.ChangePassword(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/create_or_update_user_handler.go b/api/internal/handler/user/create_or_update_user_handler.go index 276fa2fb..d484bc5b 100644 --- a/api/internal/handler/user/create_or_update_user_handler.go +++ b/api/internal/handler/user/create_or_update_user_handler.go @@ -22,9 +22,7 @@ import ( // type: CreateOrUpdateUserReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func CreateOrUpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func CreateOrUpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewCreateOrUpdateUserLogic(r.Context(), svcCtx) + l := user.NewCreateOrUpdateUserLogic(r, svcCtx) resp, err := l.CreateOrUpdateUser(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/delete_user_handler.go b/api/internal/handler/user/delete_user_handler.go index 23c554ad..fa36bee7 100644 --- a/api/internal/handler/user/delete_user_handler.go +++ b/api/internal/handler/user/delete_user_handler.go @@ -22,9 +22,7 @@ import ( // type: IDReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewDeleteUserLogic(r.Context(), svcCtx) + l := user.NewDeleteUserLogic(r, svcCtx) resp, err := l.DeleteUser(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/get_user_info_handler.go b/api/internal/handler/user/get_user_info_handler.go index c54c81a8..ebd5cfe5 100644 --- a/api/internal/handler/user/get_user_info_handler.go +++ b/api/internal/handler/user/get_user_info_handler.go @@ -16,12 +16,10 @@ import ( // // Responses: // 200: GetUserInfoResp -// 401: SimpleMsg -// 500: SimpleMsg func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := user.NewGetUserInfoLogic(r.Context(), svcCtx) + l := user.NewGetUserInfoLogic(r, svcCtx) resp, err := l.GetUserInfo() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/get_user_list_handler.go b/api/internal/handler/user/get_user_list_handler.go index 596c909d..199835f5 100644 --- a/api/internal/handler/user/get_user_list_handler.go +++ b/api/internal/handler/user/get_user_list_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: UserListResp -// 401: SimpleMsg -// 500: SimpleMsg func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewGetUserListLogic(r.Context(), svcCtx) + l := user.NewGetUserListLogic(r, svcCtx) resp, err := l.GetUserList(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/get_user_perm_code_handler.go b/api/internal/handler/user/get_user_perm_code_handler.go index 917e5def..e8bb9642 100644 --- a/api/internal/handler/user/get_user_perm_code_handler.go +++ b/api/internal/handler/user/get_user_perm_code_handler.go @@ -16,12 +16,10 @@ import ( // // Responses: // 200: PermCodeResp -// 401: SimpleMsg -// 500: SimpleMsg func GetUserPermCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := user.NewGetUserPermCodeLogic(r.Context(), svcCtx) + l := user.NewGetUserPermCodeLogic(r, svcCtx) resp, err := l.GetUserPermCode() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/get_user_profile_handler.go b/api/internal/handler/user/get_user_profile_handler.go index 2173e9ff..8b68d39d 100644 --- a/api/internal/handler/user/get_user_profile_handler.go +++ b/api/internal/handler/user/get_user_profile_handler.go @@ -16,12 +16,10 @@ import ( // // Responses: // 200: ProfileResp -// 401: SimpleMsg -// 500: SimpleMsg func GetUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := user.NewGetUserProfileLogic(r.Context(), svcCtx) + l := user.NewGetUserProfileLogic(r, svcCtx) resp, err := l.GetUserProfile() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/login_handler.go b/api/internal/handler/user/login_handler.go index 973afd11..23568cd3 100644 --- a/api/internal/handler/user/login_handler.go +++ b/api/internal/handler/user/login_handler.go @@ -23,8 +23,6 @@ import ( // // Responses: // 200: LoginResp -// 401: SimpleMsg -// 500: SimpleMsg func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewLoginLogic(r.Context(), svcCtx) + l := user.NewLoginLogic(r, svcCtx) resp, err := l.Login(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/logout_handler.go b/api/internal/handler/user/logout_handler.go index 556adb77..b4f65935 100644 --- a/api/internal/handler/user/logout_handler.go +++ b/api/internal/handler/user/logout_handler.go @@ -15,13 +15,11 @@ import ( // Log out | 退出登陆 // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - l := user.NewLogoutLogic(r.Context(), svcCtx) + l := user.NewLogoutLogic(r, svcCtx) resp, err := l.Logout() if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/register_handler.go b/api/internal/handler/user/register_handler.go index 852dcae3..1bd7a186 100644 --- a/api/internal/handler/user/register_handler.go +++ b/api/internal/handler/user/register_handler.go @@ -22,9 +22,7 @@ import ( // type: RegisterReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewRegisterLogic(r.Context(), svcCtx) + l := user.NewRegisterLogic(r, svcCtx) resp, err := l.Register(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/update_user_profile_handler.go b/api/internal/handler/user/update_user_profile_handler.go index 278cbdc7..825c3270 100644 --- a/api/internal/handler/user/update_user_profile_handler.go +++ b/api/internal/handler/user/update_user_profile_handler.go @@ -22,9 +22,7 @@ import ( // type: ProfileReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func UpdateUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func UpdateUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewUpdateUserProfileLogic(r.Context(), svcCtx) + l := user.NewUpdateUserProfileLogic(r, svcCtx) resp, err := l.UpdateUserProfile(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/handler/user/update_user_status_handler.go b/api/internal/handler/user/update_user_status_handler.go index d3b6dba0..e2c2cf7f 100644 --- a/api/internal/handler/user/update_user_status_handler.go +++ b/api/internal/handler/user/update_user_status_handler.go @@ -22,9 +22,7 @@ import ( // type: StatusCodeReq // // Responses: -// 200: SimpleMsg -// 401: SimpleMsg -// 500: SimpleMsg +// 200: BaseMsgResp func UpdateUserStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +32,7 @@ func UpdateUserStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return } - l := user.NewUpdateUserStatusLogic(r.Context(), svcCtx) + l := user.NewUpdateUserStatusLogic(r, svcCtx) resp, err := l.UpdateUserStatus(&req) if err != nil { err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) diff --git a/api/internal/logic/api/create_or_update_api_logic.go b/api/internal/logic/api/create_or_update_api_logic.go index ee9f0eed..d2fa2df5 100644 --- a/api/internal/logic/api/create_or_update_api_logic.go +++ b/api/internal/logic/api/create_or_update_api_logic.go @@ -27,7 +27,7 @@ func NewCreateOrUpdateApiLogic(r *http.Request, svcCtx *svc.ServiceContext) *Cre } } -func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(req *types.CreateOrUpdateApiReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(req *types.CreateOrUpdateApiReq) (resp *types.BaseMsgResp, err error) { data, err := l.svcCtx.CoreRpc.CreateOrUpdateApi(l.ctx, &core.ApiInfo{ Id: req.Id, @@ -39,5 +39,5 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(req *types.CreateOrUpdateApiR if err != nil { return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, data.Msg)}, nil } diff --git a/api/internal/logic/api/delete_api_logic.go b/api/internal/logic/api/delete_api_logic.go index 641862bf..2ebe7136 100644 --- a/api/internal/logic/api/delete_api_logic.go +++ b/api/internal/logic/api/delete_api_logic.go @@ -27,14 +27,14 @@ func NewDeleteApiLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteApiLo } } -func (l *DeleteApiLogic) DeleteApi(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteApiLogic) DeleteApi(req *types.IDReq) (resp *types.BaseMsgResp, err error) { data, err := l.svcCtx.CoreRpc.DeleteApi(l.ctx, &core.IDReq{ Id: req.Id, }) if err != nil { return nil, err } - resp = &types.SimpleMsg{} + resp = &types.BaseMsgResp{} resp.Msg = data.Msg return resp, nil } diff --git a/api/internal/logic/api/get_api_list_logic.go b/api/internal/logic/api/get_api_list_logic.go index 263c1f01..f227e3e5 100644 --- a/api/internal/logic/api/get_api_list_logic.go +++ b/api/internal/logic/api/get_api_list_logic.go @@ -42,12 +42,11 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList return nil, err } resp = &types.ApiListResp{} - resp.Code = 0 - resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.SUCCESS) - resp.Total = data.GetTotal() + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = data.GetTotal() for _, v := range data.Data { - resp.Data = append(resp.Data, + resp.Data.Data = append(resp.Data.Data, types.ApiInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, diff --git a/api/internal/logic/authority/create_or_update_api_authority_logic.go b/api/internal/logic/authority/create_or_update_api_authority_logic.go index 8135a650..a6e029dd 100644 --- a/api/internal/logic/authority/create_or_update_api_authority_logic.go +++ b/api/internal/logic/authority/create_or_update_api_authority_logic.go @@ -7,8 +7,9 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/enum" + "github.com/suyuan32/simple-admin-core/pkg/i18n" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" ) @@ -16,17 +17,19 @@ type CreateOrUpdateApiAuthorityLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateApiAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateApiAuthorityLogic { +func NewCreateOrUpdateApiAuthorityLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateApiAuthorityLogic { return &CreateOrUpdateApiAuthorityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateApiAuthorityLogic) CreateOrUpdateApiAuthority(req *types.CreateOrUpdateApiAuthorityReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateApiAuthorityLogic) CreateOrUpdateApiAuthority(req *types.CreateOrUpdateApiAuthorityReq) (resp *types.BaseMsgResp, err error) { // clear old policies roleIdString := strconv.Itoa(int(req.RoleId)) var oldPolicies [][]string @@ -34,13 +37,12 @@ func (l *CreateOrUpdateApiAuthorityLogic) CreateOrUpdateApiAuthority(req *types. if len(oldPolicies) != 0 { removeResult, err := l.svcCtx.Casbin.RemoveFilteredPolicy(0, roleIdString) if err != nil { - return nil, &errorx.ApiError{ - Code: http.StatusInternalServerError, - Msg: err.Error(), - } + return &types.BaseMsgResp{Code: enum.Internal, + Msg: err.Error()}, nil } if !removeResult { - return nil, errorx.NewApiError(http.StatusInternalServerError, "cannot clear old policies") + return &types.BaseMsgResp{Code: enum.Internal, + Msg: l.svcCtx.Trans.Trans(l.lang, "casbin.removeFailed")}, nil } } // add new policies @@ -50,11 +52,12 @@ func (l *CreateOrUpdateApiAuthorityLogic) CreateOrUpdateApiAuthority(req *types. } addResult, err := l.svcCtx.Casbin.AddPolicies(policies) if err != nil { - return nil, err + return &types.BaseMsgResp{Code: enum.Internal, + Msg: l.svcCtx.Trans.Trans(l.lang, "casbin.addFailed")}, nil } if addResult { - return &types.SimpleMsg{Msg: errorx.UpdateSuccess}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.UpdateSuccess)}, nil } else { - return nil, errorx.NewApiError(http.StatusBadRequest, errorx.UpdateFailed) + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.UpdateFailed)}, nil } } diff --git a/api/internal/logic/authority/create_or_update_menu_authority_logic.go b/api/internal/logic/authority/create_or_update_menu_authority_logic.go index 30ae2a72..57cfe4e3 100644 --- a/api/internal/logic/authority/create_or_update_menu_authority_logic.go +++ b/api/internal/logic/authority/create_or_update_menu_authority_logic.go @@ -2,6 +2,7 @@ package authority import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type CreateOrUpdateMenuAuthorityLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateMenuAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuAuthorityLogic { +func NewCreateOrUpdateMenuAuthorityLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuAuthorityLogic { return &CreateOrUpdateMenuAuthorityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateMenuAuthorityLogic) CreateOrUpdateMenuAuthority(req *types.MenuAuthorityInfoReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateMenuAuthorityLogic) CreateOrUpdateMenuAuthority(req *types.MenuAuthorityInfoReq) (resp *types.BaseMsgResp, err error) { authority, err := l.svcCtx.CoreRpc.CreateOrUpdateMenuAuthority(l.ctx, &core.RoleMenuAuthorityReq{ RoleId: req.RoleId, MenuId: req.MenuIds, @@ -33,5 +36,5 @@ func (l *CreateOrUpdateMenuAuthorityLogic) CreateOrUpdateMenuAuthority(req *type return nil, err } - return &types.SimpleMsg{Msg: authority.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, authority.Msg)}, nil } diff --git a/api/internal/logic/authority/get_api_authority_logic.go b/api/internal/logic/authority/get_api_authority_logic.go index e7690ac4..41797cf5 100644 --- a/api/internal/logic/authority/get_api_authority_logic.go +++ b/api/internal/logic/authority/get_api_authority_logic.go @@ -2,10 +2,12 @@ package authority import ( "context" + "net/http" "strconv" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/zeromicro/go-zero/core/logx" ) @@ -14,13 +16,15 @@ type GetApiAuthorityLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetApiAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiAuthorityLogic { +func NewGetApiAuthorityLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetApiAuthorityLogic { return &GetApiAuthorityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -28,9 +32,10 @@ func (l *GetApiAuthorityLogic) GetApiAuthority(req *types.IDReq) (resp *types.Ap roleId := strconv.Itoa(int(req.Id)) data := l.svcCtx.Casbin.GetFilteredPolicy(0, roleId) resp = &types.ApiAuthorityListResp{} - resp.Total = uint64(len(data)) + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = uint64(len(data)) for _, v := range data { - resp.Data = append(resp.Data, types.ApiAuthorityInfo{ + resp.Data.Data = append(resp.Data.Data, types.ApiAuthorityInfo{ Path: v[1], Method: v[2], }) diff --git a/api/internal/logic/authority/get_menu_authority_logic.go b/api/internal/logic/authority/get_menu_authority_logic.go index ddeb36dd..2534e4b1 100644 --- a/api/internal/logic/authority/get_menu_authority_logic.go +++ b/api/internal/logic/authority/get_menu_authority_logic.go @@ -2,9 +2,11 @@ package authority import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetMenuAuthorityLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetMenuAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuAuthorityLogic { +func NewGetMenuAuthorityLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenuAuthorityLogic { return &GetMenuAuthorityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -31,13 +35,16 @@ func (l *GetMenuAuthorityLogic) GetMenuAuthority(req *types.IDReq) (resp *types. if err != nil { return nil, err } + resp = &types.MenuAuthorityInfoResp{ - RoleId: req.Id, - MenuIds: []uint64{}, + BaseDataInfo: types.BaseDataInfo{ + Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success), + }, + Data: types.MenuAuthorityInfoReq{ + RoleId: req.Id, + MenuIds: data.MenuId, + }, } - for _, v := range data.MenuId { - resp.MenuIds = append(resp.MenuIds, v) - } return resp, nil } diff --git a/api/internal/logic/captcha/get_captcha_logic.go b/api/internal/logic/captcha/get_captcha_logic.go index 157f3aa4..881a2528 100644 --- a/api/internal/logic/captcha/get_captcha_logic.go +++ b/api/internal/logic/captcha/get_captcha_logic.go @@ -4,15 +4,17 @@ import ( "context" "net/http" + "github.com/mojocn/base64Captcha" + "github.com/zeromicro/go-zero/core/stores/redis" + "github.com/suyuan32/simple-admin-core/api/internal/config" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/enum" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/pkg/utils" - "github.com/mojocn/base64Captcha" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/core/stores/redis" ) var Store *utils.RedisStore @@ -22,28 +24,36 @@ type GetCaptchaLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCaptchaLogic { +func NewGetCaptchaLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetCaptchaLogic { return &GetCaptchaLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaInfo, err error) { +func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaResp, err error) { if driver == nil || Store == nil { initStoreAndDriver(l.svcCtx.Config, l.svcCtx.Redis) } gen := base64Captcha.NewCaptcha(driver, Store) if id, b64s, err := gen.Generate(); err != nil { logx.Errorw("fail to generate captcha", logx.Field("detail", err.Error())) - return nil, errorx.NewApiError(http.StatusInternalServerError, "内部错误") + return &types.CaptchaResp{ + BaseDataInfo: types.BaseDataInfo{Code: enum.Internal, Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Failed)}, + Data: types.CaptchaInfo{}, + }, nil } else { - resp = &types.CaptchaInfo{ - CaptchaId: id, - ImgPath: b64s, + resp = &types.CaptchaResp{ + BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success)}, + Data: types.CaptchaInfo{ + CaptchaId: id, + ImgPath: b64s, + }, } return resp, nil } diff --git a/api/internal/logic/core/health_check_logic.go b/api/internal/logic/core/health_check_logic.go index b987b9b5..6f887548 100644 --- a/api/internal/logic/core/health_check_logic.go +++ b/api/internal/logic/core/health_check_logic.go @@ -2,6 +2,7 @@ package core import ( "context" + "net/http" "github.com/zeromicro/go-zero/core/logx" @@ -12,13 +13,15 @@ type HealthCheckLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewHealthCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthCheckLogic { +func NewHealthCheckLogic(r *http.Request, svcCtx *svc.ServiceContext) *HealthCheckLogic { return &HealthCheckLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } diff --git a/api/internal/logic/core/init_database_logic.go b/api/internal/logic/core/init_database_logic.go index b2a218e8..baf52b8e 100644 --- a/api/internal/logic/core/init_database_logic.go +++ b/api/internal/logic/core/init_database_logic.go @@ -2,35 +2,40 @@ package core import ( "context" + "errors" + "net/http" "time" - "github.com/suyuan32/simple-admin-core/rpc/types/core" - - "github.com/pkg/errors" "github.com/zeromicro/go-zero/core/errorx" - "github.com/zeromicro/go-zero/core/logx" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/enum" + "github.com/suyuan32/simple-admin-core/pkg/i18n" + "github.com/suyuan32/simple-admin-core/rpc/types/core" + + "github.com/zeromicro/go-zero/core/logx" ) type InitDatabaseLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewInitDatabaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InitDatabaseLogic { +func NewInitDatabaseLogic(r *http.Request, svcCtx *svc.ServiceContext) *InitDatabaseLogic { return &InitDatabaseLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *InitDatabaseLogic) InitDatabase() (resp *types.SimpleMsg, err error) { +func (l *InitDatabaseLogic) InitDatabase() (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.InitDatabase(l.ctx, &core.Empty{}) if err != nil && !errors.Is(err, status.Error(codes.DeadlineExceeded, "context deadline exceeded")) { return nil, err @@ -40,20 +45,23 @@ func (l *InitDatabaseLogic) InitDatabase() (resp *types.SimpleMsg, err error) { time.Sleep(time.Second * 10) if initState, err := l.svcCtx.Redis.Get("database_init_state"); err == nil { if initState == "1" { - return &types.SimpleMsg{Msg: errorx.Success}, nil + return nil, errorx.NewCodeError(enum.InvalidArgument, + l.svcCtx.Trans.Trans(l.lang, "init.alreadyInit")) } } else { - return nil, status.Error(codes.Internal, errorx.RedisError) + return nil, errorx.NewCodeError(enum.Internal, + l.svcCtx.Trans.Trans(l.lang, i18n.RedisError)) } if errMsg, err := l.svcCtx.Redis.Get("database_error_msg"); err == nil { if errMsg != "" { - return nil, status.Error(codes.Internal, errMsg) + return nil, errorx.NewCodeError(enum.Internal, errMsg) } } else { - return nil, status.Error(codes.Internal, errorx.RedisError) + return nil, errorx.NewCodeError(enum.Internal, + l.svcCtx.Trans.Trans(l.lang, i18n.RedisError)) } } } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/dictionary/create_or_update_dictionary_detail_logic.go b/api/internal/logic/dictionary/create_or_update_dictionary_detail_logic.go index c2777c6c..73f7c494 100644 --- a/api/internal/logic/dictionary/create_or_update_dictionary_detail_logic.go +++ b/api/internal/logic/dictionary/create_or_update_dictionary_detail_logic.go @@ -2,6 +2,7 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type CreateOrUpdateDictionaryDetailLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateDictionaryDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateDictionaryDetailLogic { +func NewCreateOrUpdateDictionaryDetailLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateDictionaryDetailLogic { return &CreateOrUpdateDictionaryDetailLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(req *types.CreateOrUpdateDictionaryDetailReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(req *types.CreateOrUpdateDictionaryDetailReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.CreateOrUpdateDictionaryDetail(l.ctx, &core.DictionaryDetail{ Id: req.Id, Title: req.Title, @@ -38,5 +41,5 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(req return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/dictionary/create_or_update_dictionary_logic.go b/api/internal/logic/dictionary/create_or_update_dictionary_logic.go index ca3f4019..34dd636f 100644 --- a/api/internal/logic/dictionary/create_or_update_dictionary_logic.go +++ b/api/internal/logic/dictionary/create_or_update_dictionary_logic.go @@ -2,6 +2,7 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type CreateOrUpdateDictionaryLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateDictionaryLogic { +func NewCreateOrUpdateDictionaryLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateDictionaryLogic { return &CreateOrUpdateDictionaryLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(req *types.CreateOrUpdateDictionaryReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(req *types.CreateOrUpdateDictionaryReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.CreateOrUpdateDictionary(l.ctx, &core.DictionaryInfo{ Id: req.Id, Title: req.Title, @@ -37,5 +40,5 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(req *types.Crea return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/dictionary/delete_dictionary_detail_logic.go b/api/internal/logic/dictionary/delete_dictionary_detail_logic.go index 58970ae6..d5a738c0 100644 --- a/api/internal/logic/dictionary/delete_dictionary_detail_logic.go +++ b/api/internal/logic/dictionary/delete_dictionary_detail_logic.go @@ -2,6 +2,7 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,24 @@ type DeleteDictionaryDetailLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteDictionaryDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryDetailLogic { +func NewDeleteDictionaryDetailLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteDictionaryDetailLogic { return &DeleteDictionaryDetailLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteDictionaryDetailLogic) DeleteDictionaryDetail(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteDictionaryDetailLogic) DeleteDictionaryDetail(req *types.IDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.DeleteDictionaryDetail(l.ctx, &core.IDReq{Id: req.Id}) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/dictionary/delete_dictionary_logic.go b/api/internal/logic/dictionary/delete_dictionary_logic.go index 9bc7bd6d..6a21801a 100644 --- a/api/internal/logic/dictionary/delete_dictionary_logic.go +++ b/api/internal/logic/dictionary/delete_dictionary_logic.go @@ -2,6 +2,7 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,24 @@ type DeleteDictionaryLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryLogic { +func NewDeleteDictionaryLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteDictionaryLogic { return &DeleteDictionaryLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteDictionaryLogic) DeleteDictionary(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteDictionaryLogic) DeleteDictionary(req *types.IDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.DeleteDictionary(l.ctx, &core.IDReq{Id: req.Id}) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/dictionary/get_detail_by_dictionary_name_logic.go b/api/internal/logic/dictionary/get_detail_by_dictionary_name_logic.go index 0b22a2a9..e3bca644 100644 --- a/api/internal/logic/dictionary/get_detail_by_dictionary_name_logic.go +++ b/api/internal/logic/dictionary/get_detail_by_dictionary_name_logic.go @@ -2,9 +2,11 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetDetailByDictionaryNameLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetDetailByDictionaryNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDetailByDictionaryNameLogic { +func NewGetDetailByDictionaryNameLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetDetailByDictionaryNameLogic { return &GetDetailByDictionaryNameLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -32,9 +36,10 @@ func (l *GetDetailByDictionaryNameLogic) GetDetailByDictionaryName(req *types.Di } resp = &types.DictionaryDetailListResp{} - resp.Total = result.Total + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = result.Total for _, v := range result.Data { - resp.Data = append(resp.Data, types.DictionaryDetailInfo{ + resp.Data.Data = append(resp.Data.Data, types.DictionaryDetailInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, CreatedAt: v.CreatedAt, diff --git a/api/internal/logic/dictionary/get_dictionary_list_logic.go b/api/internal/logic/dictionary/get_dictionary_list_logic.go index 5d097a12..78945e8d 100644 --- a/api/internal/logic/dictionary/get_dictionary_list_logic.go +++ b/api/internal/logic/dictionary/get_dictionary_list_logic.go @@ -2,9 +2,11 @@ package dictionary import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetDictionaryListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetDictionaryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryListLogic { +func NewGetDictionaryListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetDictionaryListLogic { return &GetDictionaryListLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -37,9 +41,10 @@ func (l *GetDictionaryListLogic) GetDictionaryList(req *types.DictionaryListReq) } resp = &types.DictionaryListResp{} - resp.Total = result.Total + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = result.Total for _, v := range result.Data { - resp.Data = append(resp.Data, types.DictionaryInfo{ + resp.Data.Data = append(resp.Data.Data, types.DictionaryInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, CreatedAt: v.CreatedAt, diff --git a/api/internal/logic/menu/create_or_update_menu_logic.go b/api/internal/logic/menu/create_or_update_menu_logic.go index 90c9a5e6..6bf43e48 100644 --- a/api/internal/logic/menu/create_or_update_menu_logic.go +++ b/api/internal/logic/menu/create_or_update_menu_logic.go @@ -2,6 +2,7 @@ package menu import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,18 +15,20 @@ type CreateOrUpdateMenuLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuLogic { +func NewCreateOrUpdateMenuLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuLogic { return &CreateOrUpdateMenuLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(req *types.CreateOrUpdateMenuReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.CreateOrUpdateMenu(l.ctx, &core.CreateOrUpdateMenuReq{ +func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(req *types.CreateOrUpdateMenuReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.CreateOrUpdateMenu(l.ctx, &core.CreateOrUpdateMenuReq{ Id: req.Id, MenuType: req.MenuType, ParentId: req.ParentId, @@ -54,5 +57,5 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(req *types.CreateOrUpdateMe if err != nil { return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/menu/create_or_update_menu_param_logic.go b/api/internal/logic/menu/create_or_update_menu_param_logic.go index 7e8d9625..6197c735 100644 --- a/api/internal/logic/menu/create_or_update_menu_param_logic.go +++ b/api/internal/logic/menu/create_or_update_menu_param_logic.go @@ -2,6 +2,7 @@ package menu import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type CreateOrUpdateMenuParamLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateMenuParamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuParamLogic { +func NewCreateOrUpdateMenuParamLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuParamLogic { return &CreateOrUpdateMenuParamLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(req *types.CreateOrUpdateMenuParamReq) (resp *types.SimpleMsg, err error) { +func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(req *types.CreateOrUpdateMenuParamReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.CreateOrUpdateMenuParam(l.ctx, &core.CreateOrUpdateMenuParamReq{ Id: req.Id, MenuId: req.MenuId, @@ -37,5 +40,5 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(req *types.Create return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/menu/delete_menu_logic.go b/api/internal/logic/menu/delete_menu_logic.go index 95774f33..9c9de3b4 100644 --- a/api/internal/logic/menu/delete_menu_logic.go +++ b/api/internal/logic/menu/delete_menu_logic.go @@ -2,6 +2,7 @@ package menu import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,20 +15,22 @@ type DeleteMenuLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic { +func NewDeleteMenuLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteMenuLogic { return &DeleteMenuLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteMenuLogic) DeleteMenu(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteMenuLogic) DeleteMenu(req *types.IDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.DeleteMenu(l.ctx, &core.IDReq{Id: uint64(req.Id)}) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/menu/delete_menu_param_logic.go b/api/internal/logic/menu/delete_menu_param_logic.go index 79eaf094..635814ab 100644 --- a/api/internal/logic/menu/delete_menu_param_logic.go +++ b/api/internal/logic/menu/delete_menu_param_logic.go @@ -2,6 +2,7 @@ package menu import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,22 @@ type DeleteMenuParamLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteMenuParamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuParamLogic { +func NewDeleteMenuParamLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteMenuParamLogic { return &DeleteMenuParamLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteMenuParamLogic) DeleteMenuParam(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteMenuParamLogic) DeleteMenuParam(req *types.IDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.DeleteMenuParam(l.ctx, &core.IDReq{Id: req.Id}) - if err != nil { return nil, err } - - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/menu/get_menu_by_role_logic.go b/api/internal/logic/menu/get_menu_by_role_logic.go index ecd5efdd..f087dc93 100644 --- a/api/internal/logic/menu/get_menu_by_role_logic.go +++ b/api/internal/logic/menu/get_menu_by_role_logic.go @@ -7,6 +7,7 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -16,7 +17,7 @@ type GetMenuByRoleLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext - r *http.Request + lang string } func NewGetMenuByRoleLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenuByRoleLogic { @@ -24,19 +25,20 @@ func NewGetMenuByRoleLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenu Logger: logx.WithContext(r.Context()), ctx: r.Context(), svcCtx: svcCtx, - r: r, + lang: r.Header.Get("Accept-Language"), } } -func (l *GetMenuByRoleLogic) GetMenuByRole() (resp []*types.GetMenuListBase, err error) { +func (l *GetMenuByRoleLogic) GetMenuByRole() (resp *types.GetMenuListBaseResp, err error) { roleId, _ := l.ctx.Value("roleId").(json.Number).Int64() data, err := l.svcCtx.CoreRpc.GetMenuListByRole(l.ctx, &core.IDReq{Id: uint64(roleId)}) if err != nil { return nil, err } - var result []*types.GetMenuListBase - result = l.convertRoleMenuList(data.Data, l.r.Header.Get("Accept-Language")) - return result, nil + resp = &types.GetMenuListBaseResp{} + resp.Data.Data = l.convertRoleMenuList(data.Data, l.lang) + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + return resp, nil } func (l *GetMenuByRoleLogic) convertRoleMenuList(data []*core.MenuInfo, lang string) []*types.GetMenuListBase { diff --git a/api/internal/logic/menu/get_menu_list_logic.go b/api/internal/logic/menu/get_menu_list_logic.go index a3a0dd61..91a83053 100644 --- a/api/internal/logic/menu/get_menu_list_logic.go +++ b/api/internal/logic/menu/get_menu_list_logic.go @@ -6,6 +6,7 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -15,7 +16,7 @@ type GetMenuListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext - r *http.Request + lang string } func NewGetMenuListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenuListLogic { @@ -23,7 +24,7 @@ func NewGetMenuListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenuLi Logger: logx.WithContext(r.Context()), ctx: r.Context(), svcCtx: svcCtx, - r: r, + lang: r.Header.Get("Accept-Language"), } } @@ -36,8 +37,9 @@ func (l *GetMenuListLogic) GetMenuList() (resp *types.MenuListResp, err error) { return nil, err } resp = &types.MenuListResp{} - resp.Total = data.Total - resp.Data = l.convertMenuList(data.Data, l.r.Header.Get("Accept-Language")) + resp.Data.Total = data.Total + resp.Data.Data = l.convertMenuList(data.Data, l.lang) + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) return resp, nil } diff --git a/api/internal/logic/menu/get_menu_param_list_by_menu_id_logic.go b/api/internal/logic/menu/get_menu_param_list_by_menu_id_logic.go index 5b5ef324..3a8dbbdf 100644 --- a/api/internal/logic/menu/get_menu_param_list_by_menu_id_logic.go +++ b/api/internal/logic/menu/get_menu_param_list_by_menu_id_logic.go @@ -2,9 +2,11 @@ package menu import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetMenuParamListByMenuIdLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetMenuParamListByMenuIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuParamListByMenuIdLogic { +func NewGetMenuParamListByMenuIdLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetMenuParamListByMenuIdLogic { return &GetMenuParamListByMenuIdLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -31,9 +35,10 @@ func (l *GetMenuParamListByMenuIdLogic) GetMenuParamListByMenuId(req *types.IDRe } resp = &types.MenuParamListByMenuIdResp{} - resp.Total = result.Total + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = result.Total for _, v := range result.Data { - resp.Data = append(resp.Data, types.MenuParamResp{ + resp.Data.Data = append(resp.Data.Data, types.MenuParamInfo{ BaseInfo: types.BaseInfo{Id: v.Id, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt}, DataType: v.Type, Key: v.Key, diff --git a/api/internal/logic/oauth/create_or_update_provider_logic.go b/api/internal/logic/oauth/create_or_update_provider_logic.go index eb1f7023..218b28f8 100644 --- a/api/internal/logic/oauth/create_or_update_provider_logic.go +++ b/api/internal/logic/oauth/create_or_update_provider_logic.go @@ -2,6 +2,7 @@ package oauth import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,18 +15,20 @@ type CreateOrUpdateProviderLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateProviderLogic { +func NewCreateOrUpdateProviderLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateProviderLogic { return &CreateOrUpdateProviderLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(req *types.CreateOrUpdateProviderReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.CreateOrUpdateProvider(l.ctx, +func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(req *types.CreateOrUpdateProviderReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.CreateOrUpdateProvider(l.ctx, &core.ProviderInfo{ Id: req.Id, Name: req.Name, @@ -41,5 +44,5 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(req *types.CreateOr if err != nil { return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/oauth/delete_provider_logic.go b/api/internal/logic/oauth/delete_provider_logic.go index c17aa161..4437ace4 100644 --- a/api/internal/logic/oauth/delete_provider_logic.go +++ b/api/internal/logic/oauth/delete_provider_logic.go @@ -2,6 +2,7 @@ package oauth import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,24 @@ type DeleteProviderLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProviderLogic { +func NewDeleteProviderLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteProviderLogic { return &DeleteProviderLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteProviderLogic) DeleteProvider(req *types.IDReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.DeleteProvider(l.ctx, &core.IDReq{ +func (l *DeleteProviderLogic) DeleteProvider(req *types.IDReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.DeleteProvider(l.ctx, &core.IDReq{ Id: uint64(req.Id), }) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/oauth/get_provider_list_logic.go b/api/internal/logic/oauth/get_provider_list_logic.go index f9eb3ace..ebd5c337 100644 --- a/api/internal/logic/oauth/get_provider_list_logic.go +++ b/api/internal/logic/oauth/get_provider_list_logic.go @@ -2,6 +2,7 @@ package oauth import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,13 +15,15 @@ type GetProviderListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetProviderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProviderListLogic { +func NewGetProviderListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetProviderListLogic { return &GetProviderListLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } diff --git a/api/internal/logic/oauth/oauth_callback_logic.go b/api/internal/logic/oauth/oauth_callback_logic.go index 696f3e10..59393c77 100644 --- a/api/internal/logic/oauth/oauth_callback_logic.go +++ b/api/internal/logic/oauth/oauth_callback_logic.go @@ -18,6 +18,7 @@ type OauthCallbackLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string r *http.Request } @@ -25,8 +26,9 @@ func NewOauthCallbackLogic(r *http.Request, svcCtx *svc.ServiceContext) *OauthCa return &OauthCallbackLogic{ Logger: logx.WithContext(r.Context()), ctx: r.Context(), - r: r, svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), + r: r, } } diff --git a/api/internal/logic/oauth/oauth_login_logic.go b/api/internal/logic/oauth/oauth_login_logic.go index 90d13e46..4d4791c4 100644 --- a/api/internal/logic/oauth/oauth_login_logic.go +++ b/api/internal/logic/oauth/oauth_login_logic.go @@ -2,25 +2,29 @@ package oauth import ( "context" - - "github.com/zeromicro/go-zero/core/logx" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" + + "github.com/zeromicro/go-zero/core/logx" ) type OauthLoginLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewOauthLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OauthLoginLogic { +func NewOauthLoginLogic(r *http.Request, svcCtx *svc.ServiceContext) *OauthLoginLogic { return &OauthLoginLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -33,5 +37,8 @@ func (l *OauthLoginLogic) OauthLogin(req *types.OauthLoginReq) (resp *types.Redi return nil, err } - return &types.RedirectResp{URL: result.Url}, nil + return &types.RedirectResp{ + BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success)}, + Data: types.RedirectInfo{URL: result.Url}, + }, nil } diff --git a/api/internal/logic/role/create_or_update_role_logic.go b/api/internal/logic/role/create_or_update_role_logic.go index 61ce6350..4e6fe6c6 100644 --- a/api/internal/logic/role/create_or_update_role_logic.go +++ b/api/internal/logic/role/create_or_update_role_logic.go @@ -2,6 +2,7 @@ package role import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,18 +15,20 @@ type CreateOrUpdateRoleLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateRoleLogic { +func NewCreateOrUpdateRoleLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateRoleLogic { return &CreateOrUpdateRoleLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(req *types.RoleInfo) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.CreateOrUpdateRole(l.ctx, &core.RoleInfo{ +func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(req *types.RoleInfo) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.CreateOrUpdateRole(l.ctx, &core.RoleInfo{ Id: req.Id, Name: req.Name, Value: req.Value, @@ -37,7 +40,5 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(req *types.RoleInfo) (resp if err != nil { return nil, err } - resp = &types.SimpleMsg{} - resp.Msg = data.Msg - return resp, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/role/delete_role_logic.go b/api/internal/logic/role/delete_role_logic.go index b1af1519..08ebbed6 100644 --- a/api/internal/logic/role/delete_role_logic.go +++ b/api/internal/logic/role/delete_role_logic.go @@ -2,6 +2,7 @@ package role import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,24 +15,24 @@ type DeleteRoleLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic { +func NewDeleteRoleLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteRoleLogic { return &DeleteRoleLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteRoleLogic) DeleteRole(req *types.IDReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.DeleteRole(l.ctx, &core.IDReq{ +func (l *DeleteRoleLogic) DeleteRole(req *types.IDReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.DeleteRole(l.ctx, &core.IDReq{ Id: req.Id, }) if err != nil { return nil, err } - resp = &types.SimpleMsg{} - resp.Msg = data.Msg - return resp, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/role/get_role_list_logic.go b/api/internal/logic/role/get_role_list_logic.go index a2cfb158..d9379e61 100644 --- a/api/internal/logic/role/get_role_list_logic.go +++ b/api/internal/logic/role/get_role_list_logic.go @@ -6,6 +6,7 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -15,7 +16,7 @@ type GetRoleListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext - r *http.Request + lang string } func NewGetRoleListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetRoleListLogic { @@ -23,7 +24,7 @@ func NewGetRoleListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetRoleLi Logger: logx.WithContext(r.Context()), ctx: r.Context(), svcCtx: svcCtx, - r: r, + lang: r.Header.Get("Accept-Language"), } } @@ -36,17 +37,16 @@ func (l *GetRoleListLogic) GetRoleList(req *types.PageInfo) (resp *types.RoleLis return nil, err } resp = &types.RoleListResp{} - resp.Total = data.Total - - lang := l.r.Header.Get("Accept-Language") + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = data.Total for _, v := range data.Data { - resp.Data = append(resp.Data, types.RoleInfo{ + resp.Data.Data = append(resp.Data.Data, types.RoleInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, CreatedAt: v.CreatedAt, }, - Title: l.svcCtx.Trans.Trans(lang, v.Name), + Title: l.svcCtx.Trans.Trans(l.lang, v.Name), Name: v.Name, Value: v.Value, DefaultRouter: v.DefaultRouter, diff --git a/api/internal/logic/role/update_role_status_logic.go b/api/internal/logic/role/update_role_status_logic.go index 536d5ae7..6a50733d 100644 --- a/api/internal/logic/role/update_role_status_logic.go +++ b/api/internal/logic/role/update_role_status_logic.go @@ -2,6 +2,7 @@ package role import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,23 +15,25 @@ type UpdateRoleStatusLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewUpdateRoleStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleStatusLogic { +func NewUpdateRoleStatusLogic(r *http.Request, svcCtx *svc.ServiceContext) *UpdateRoleStatusLogic { return &UpdateRoleStatusLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *UpdateRoleStatusLogic) UpdateRoleStatus(req *types.StatusCodeReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.UpdateRoleStatus(l.ctx, &core.StatusCodeReq{ +func (l *UpdateRoleStatusLogic) UpdateRoleStatus(req *types.StatusCodeReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.UpdateRoleStatus(l.ctx, &core.StatusCodeReq{ Id: req.Id, Status: req.Status, }) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/token/create_or_update_token_logic.go b/api/internal/logic/token/create_or_update_token_logic.go index ab8cd53d..047baf6b 100644 --- a/api/internal/logic/token/create_or_update_token_logic.go +++ b/api/internal/logic/token/create_or_update_token_logic.go @@ -2,6 +2,7 @@ package token import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,29 +15,25 @@ type CreateOrUpdateTokenLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateTokenLogic { +func NewCreateOrUpdateTokenLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateTokenLogic { return &CreateOrUpdateTokenLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(req *types.CreateOrUpdateTokenReq) (resp *types.SimpleMsg, err error) { - result, err := l.svcCtx.CoreRpc.CreateOrUpdateToken(l.ctx, &core.TokenInfo{ - Id: req.Id, - Uuid: req.UUID, - Token: req.Token, - Source: req.Source, - Status: req.Status, - ExpiredAt: req.ExpiredAt, +func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(req *types.CreateOrUpdateTokenReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.UpdateRoleStatus(l.ctx, &core.StatusCodeReq{ + Id: req.Id, + Status: req.Status, }) - if err != nil { return nil, err } - - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/token/delete_token_logic.go b/api/internal/logic/token/delete_token_logic.go index 4e591245..46855120 100644 --- a/api/internal/logic/token/delete_token_logic.go +++ b/api/internal/logic/token/delete_token_logic.go @@ -2,6 +2,7 @@ package token import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,24 @@ type DeleteTokenLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteTokenLogic { +func NewDeleteTokenLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteTokenLogic { return &DeleteTokenLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteTokenLogic) DeleteToken(req *types.IDReq) (resp *types.SimpleMsg, err error) { +func (l *DeleteTokenLogic) DeleteToken(req *types.IDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.DeleteToken(l.ctx, &core.IDReq{Id: req.Id}) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/token/get_token_list_logic.go b/api/internal/logic/token/get_token_list_logic.go index 1a5e1185..c886e0a2 100644 --- a/api/internal/logic/token/get_token_list_logic.go +++ b/api/internal/logic/token/get_token_list_logic.go @@ -2,9 +2,11 @@ package token import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetTokenListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetTokenListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTokenListLogic { +func NewGetTokenListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetTokenListLogic { return &GetTokenListLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -39,10 +43,11 @@ func (l *GetTokenListLogic) GetTokenList(req *types.TokenListReq) (resp *types.T } resp = &types.TokenListResp{} - resp.Total = result.Total + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = result.Total for _, v := range result.Data { - resp.Data = append(resp.Data, types.TokenInfo{ + resp.Data.Data = append(resp.Data.Data, types.TokenInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, CreatedAt: v.CreatedAt, diff --git a/api/internal/logic/token/logout_logic.go b/api/internal/logic/token/logout_logic.go index b94afa0d..81ed60f9 100644 --- a/api/internal/logic/token/logout_logic.go +++ b/api/internal/logic/token/logout_logic.go @@ -2,6 +2,7 @@ package token import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,22 +15,24 @@ type LogoutLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic { +func NewLogoutLogic(r *http.Request, svcCtx *svc.ServiceContext) *LogoutLogic { return &LogoutLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *LogoutLogic) Logout(req *types.UUIDReq) (resp *types.SimpleMsg, err error) { +func (l *LogoutLogic) Logout(req *types.UUIDReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.BlockUserAllToken(l.ctx, &core.UUIDReq{Uuid: req.UUID}) if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: result.Msg}, nil } diff --git a/api/internal/logic/token/update_token_status_logic.go b/api/internal/logic/token/update_token_status_logic.go index 06e8ec1f..e957fb02 100644 --- a/api/internal/logic/token/update_token_status_logic.go +++ b/api/internal/logic/token/update_token_status_logic.go @@ -2,6 +2,7 @@ package token import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type UpdateTokenStatusLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewUpdateTokenStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTokenStatusLogic { +func NewUpdateTokenStatusLogic(r *http.Request, svcCtx *svc.ServiceContext) *UpdateTokenStatusLogic { return &UpdateTokenStatusLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *UpdateTokenStatusLogic) UpdateTokenStatus(req *types.StatusCodeReq) (resp *types.SimpleMsg, err error) { +func (l *UpdateTokenStatusLogic) UpdateTokenStatus(req *types.StatusCodeReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.UpdateTokenStatus(l.ctx, &core.StatusCodeReq{ Id: req.Id, Status: req.Status, @@ -34,5 +37,5 @@ func (l *UpdateTokenStatusLogic) UpdateTokenStatus(req *types.StatusCodeReq) (re return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: result.Msg}, nil } diff --git a/api/internal/logic/user/change_password_logic.go b/api/internal/logic/user/change_password_logic.go index ee24f63c..055c9be3 100644 --- a/api/internal/logic/user/change_password_logic.go +++ b/api/internal/logic/user/change_password_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type ChangePasswordLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewChangePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChangePasswordLogic { +func NewChangePasswordLogic(r *http.Request, svcCtx *svc.ServiceContext) *ChangePasswordLogic { return &ChangePasswordLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *ChangePasswordLogic) ChangePassword(req *types.ChangePasswordReq) (resp *types.SimpleMsg, err error) { +func (l *ChangePasswordLogic) ChangePassword(req *types.ChangePasswordReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.ChangePassword(l.ctx, &core.ChangePasswordReq{ Uuid: l.ctx.Value("userId").(string), OldPassword: req.OldPassword, @@ -33,5 +36,5 @@ func (l *ChangePasswordLogic) ChangePassword(req *types.ChangePasswordReq) (resp if err != nil { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/user/create_or_update_user_logic.go b/api/internal/logic/user/create_or_update_user_logic.go index fa53c046..bce647aa 100644 --- a/api/internal/logic/user/create_or_update_user_logic.go +++ b/api/internal/logic/user/create_or_update_user_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,18 +15,20 @@ type CreateOrUpdateUserLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewCreateOrUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateUserLogic { +func NewCreateOrUpdateUserLogic(r *http.Request, svcCtx *svc.ServiceContext) *CreateOrUpdateUserLogic { return &CreateOrUpdateUserLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(req *types.CreateOrUpdateUserReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.CreateOrUpdateUser(l.ctx, &core.CreateOrUpdateUserReq{ +func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(req *types.CreateOrUpdateUserReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.CreateOrUpdateUser(l.ctx, &core.CreateOrUpdateUserReq{ Id: req.Id, Avatar: req.Avatar, RoleId: req.RoleId, @@ -41,5 +44,5 @@ func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(req *types.CreateOrUpdateUs return nil, err } - return &types.SimpleMsg{Msg: data.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/user/delete_user_logic.go b/api/internal/logic/user/delete_user_logic.go index d0b4f043..83251aee 100644 --- a/api/internal/logic/user/delete_user_logic.go +++ b/api/internal/logic/user/delete_user_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,24 +15,24 @@ type DeleteUserLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic { +func NewDeleteUserLogic(r *http.Request, svcCtx *svc.ServiceContext) *DeleteUserLogic { return &DeleteUserLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *DeleteUserLogic) DeleteUser(req *types.IDReq) (resp *types.SimpleMsg, err error) { - data, err := l.svcCtx.CoreRpc.DeleteUser(l.ctx, &core.IDReq{Id: uint64(req.Id)}) +func (l *DeleteUserLogic) DeleteUser(req *types.IDReq) (resp *types.BaseMsgResp, err error) { + result, err := l.svcCtx.CoreRpc.DeleteUser(l.ctx, &core.IDReq{Id: uint64(req.Id)}) if err != nil { return nil, err } - return &types.SimpleMsg{ - Msg: data.Msg, - }, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/user/get_user_info_logic.go b/api/internal/logic/user/get_user_info_logic.go index 9b2e56cc..ae3de3b9 100644 --- a/api/internal/logic/user/get_user_info_logic.go +++ b/api/internal/logic/user/get_user_info_logic.go @@ -4,11 +4,13 @@ import ( "context" "net/http" + "github.com/zeromicro/go-zero/core/errorx" + "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" ) @@ -16,13 +18,15 @@ type GetUserInfoLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic { +func NewGetUserInfoLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetUserInfoLogic { return &GetUserInfoLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -37,13 +41,16 @@ func (l *GetUserInfoLogic) GetUserInfo() (resp *types.GetUserInfoResp, err error } return &types.GetUserInfoResp{ - UUID: user.Uuid, - Username: user.Username, - Nickname: user.Nickname, - Avatar: user.Avatar, - Roles: types.GetUserRoleInfo{ - RoleName: user.RoleName, - Value: user.RoleValue, + BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success)}, + Data: types.UserBaseInfo{ + UUID: user.Uuid, + Username: user.Username, + Nickname: user.Nickname, + Avatar: user.Avatar, + Roles: types.GetUserRoleInfo{ + RoleName: user.RoleName, + Value: user.RoleValue, + }, }, }, nil } diff --git a/api/internal/logic/user/get_user_list_logic.go b/api/internal/logic/user/get_user_list_logic.go index 7dc8b5ee..87c6610b 100644 --- a/api/internal/logic/user/get_user_list_logic.go +++ b/api/internal/logic/user/get_user_list_logic.go @@ -2,9 +2,11 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetUserListLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic { +func NewGetUserListLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetUserListLogic { return &GetUserListLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -56,7 +60,8 @@ func (l *GetUserListLogic) GetUserList(req *types.GetUserListReq) (resp *types.U }) } resp = &types.UserListResp{} - resp.Total = uint64(data.Total) - resp.Data = res + resp.Data.Total = data.Total + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Data = res return resp, nil } diff --git a/api/internal/logic/user/get_user_perm_code_logic.go b/api/internal/logic/user/get_user_perm_code_logic.go index 1d45d5be..d4c82afd 100644 --- a/api/internal/logic/user/get_user_perm_code_logic.go +++ b/api/internal/logic/user/get_user_perm_code_logic.go @@ -5,10 +5,12 @@ import ( "fmt" "net/http" + "github.com/zeromicro/go-zero/core/errorx" + "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" ) @@ -16,13 +18,15 @@ type GetUserPermCodeLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetUserPermCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserPermCodeLogic { +func NewGetUserPermCodeLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetUserPermCodeLogic { return &GetUserPermCodeLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -34,5 +38,6 @@ func (l *GetUserPermCodeLogic) GetUserPermCode() (resp *types.PermCodeResp, err Msg: "login.requireLogin", } } - return &types.PermCodeResp{Data: []string{fmt.Sprintf("%v", roleId)}}, nil + return &types.PermCodeResp{BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success)}, + Data: []string{fmt.Sprintf("%v", roleId)}}, nil } diff --git a/api/internal/logic/user/get_user_profile_logic.go b/api/internal/logic/user/get_user_profile_logic.go index de78927b..430899a3 100644 --- a/api/internal/logic/user/get_user_profile_logic.go +++ b/api/internal/logic/user/get_user_profile_logic.go @@ -2,9 +2,11 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -14,13 +16,15 @@ type GetUserProfileLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic { +func NewGetUserProfileLogic(r *http.Request, svcCtx *svc.ServiceContext) *GetUserProfileLogic { return &GetUserProfileLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -32,7 +36,9 @@ func (l *GetUserProfileLogic) GetUserProfile() (resp *types.ProfileResp, err err return nil, err } - resp = &types.ProfileResp{ + resp = &types.ProfileResp{} + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data = types.ProfileInfo{ Nickname: result.Nickname, Avatar: result.Avatar, Mobile: result.Mobile, diff --git a/api/internal/logic/user/login_logic.go b/api/internal/logic/user/login_logic.go index 5399d3b7..08ee5497 100644 --- a/api/internal/logic/user/login_logic.go +++ b/api/internal/logic/user/login_logic.go @@ -5,13 +5,16 @@ import ( "net/http" "time" + "github.com/golang-jwt/jwt/v4" + "github.com/zeromicro/go-zero/core/errorx" + "github.com/suyuan32/simple-admin-core/api/internal/logic/captcha" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/enum" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" - "github.com/golang-jwt/jwt/v4" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" ) @@ -19,13 +22,15 @@ type LoginLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic { +func NewLoginLogic(r *http.Request, svcCtx *svc.ServiceContext) *LoginLogic { return &LoginLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } @@ -63,17 +68,20 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro } resp = &types.LoginResp{ - UserId: user.Id, - Token: token, - Expire: uint64(expiredAt), - Role: types.RoleInfoSimple{ - Value: user.RoleValue, - RoleName: user.RoleName, + BaseDataInfo: types.BaseDataInfo{Msg: l.svcCtx.Trans.Trans(l.lang, i18n.Success)}, + Data: types.LoginInfo{ + UserId: user.Id, + Token: token, + Expire: uint64(expiredAt), + Role: types.RoleInfoSimple{ + Value: user.RoleValue, + RoleName: user.RoleName, + }, }, } return resp, nil } else { - return nil, errorx.NewApiError(http.StatusBadRequest, "login.wrongCaptcha") + return nil, errorx.NewCodeError(enum.InvalidArgument, "login.wrongCaptcha") } } diff --git a/api/internal/logic/user/logout_logic.go b/api/internal/logic/user/logout_logic.go index 19db8e78..b75fe727 100644 --- a/api/internal/logic/user/logout_logic.go +++ b/api/internal/logic/user/logout_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type LogoutLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic { +func NewLogoutLogic(r *http.Request, svcCtx *svc.ServiceContext) *LogoutLogic { return &LogoutLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *LogoutLogic) Logout() (resp *types.SimpleMsg, err error) { +func (l *LogoutLogic) Logout() (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.BlockUserAllToken(l.ctx, &core.UUIDReq{Uuid: l.ctx.Value("userId").(string)}) @@ -32,5 +35,5 @@ func (l *LogoutLogic) Logout() (resp *types.SimpleMsg, err error) { return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/user/register_logic.go b/api/internal/logic/user/register_logic.go index bedf38ad..87ad7e36 100644 --- a/api/internal/logic/user/register_logic.go +++ b/api/internal/logic/user/register_logic.go @@ -4,12 +4,14 @@ import ( "context" "net/http" + "github.com/zeromicro/go-zero/core/errorx" + "github.com/suyuan32/simple-admin-core/api/internal/logic/captcha" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/enum" "github.com/suyuan32/simple-admin-core/rpc/types/core" - "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" ) @@ -17,17 +19,19 @@ type RegisterLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic { +func NewRegisterLogic(r *http.Request, svcCtx *svc.ServiceContext) *RegisterLogic { return &RegisterLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.SimpleMsg, err error) { +func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.BaseMsgResp, err error) { if ok := captcha.Store.Verify(req.CaptchaId, req.Captcha, true); ok { user, err := l.svcCtx.CoreRpc.CreateOrUpdateUser(l.ctx, &core.CreateOrUpdateUserReq{ @@ -41,11 +45,12 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.SimpleMsg, l.Logger.Error("register logic: create user err: ", err.Error()) return nil, err } - resp = &types.SimpleMsg{ - Msg: user.Msg, + resp = &types.BaseMsgResp{ + Msg: l.svcCtx.Trans.Trans(l.lang, user.Msg), } return resp, nil } else { - return nil, errorx.NewApiError(http.StatusBadRequest, "login.wrongCaptcha") + return nil, errorx.NewCodeError(enum.InvalidArgument, + l.svcCtx.Trans.Trans(l.lang, "login.wrongCaptcha")) } } diff --git a/api/internal/logic/user/update_user_profile_logic.go b/api/internal/logic/user/update_user_profile_logic.go index 0e58d28a..50effeae 100644 --- a/api/internal/logic/user/update_user_profile_logic.go +++ b/api/internal/logic/user/update_user_profile_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type UpdateUserProfileLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewUpdateUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserProfileLogic { +func NewUpdateUserProfileLogic(r *http.Request, svcCtx *svc.ServiceContext) *UpdateUserProfileLogic { return &UpdateUserProfileLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.ProfileReq) (resp *types.SimpleMsg, err error) { +func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.ProfileReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.UpdateProfile(l.ctx, &core.UpdateProfileReq{ Uuid: l.ctx.Value("userId").(string), Nickname: req.Nickname, @@ -37,5 +40,5 @@ func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.ProfileReq) (resp return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: result.Msg}, nil } diff --git a/api/internal/logic/user/update_user_status_logic.go b/api/internal/logic/user/update_user_status_logic.go index fc68d8bb..c801081a 100644 --- a/api/internal/logic/user/update_user_status_logic.go +++ b/api/internal/logic/user/update_user_status_logic.go @@ -2,6 +2,7 @@ package user import ( "context" + "net/http" "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" @@ -14,17 +15,19 @@ type UpdateUserStatusLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + lang string } -func NewUpdateUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserStatusLogic { +func NewUpdateUserStatusLogic(r *http.Request, svcCtx *svc.ServiceContext) *UpdateUserStatusLogic { return &UpdateUserStatusLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + lang: r.Header.Get("Accept-Language"), } } -func (l *UpdateUserStatusLogic) UpdateUserStatus(req *types.StatusCodeReq) (resp *types.SimpleMsg, err error) { +func (l *UpdateUserStatusLogic) UpdateUserStatus(req *types.StatusCodeReq) (resp *types.BaseMsgResp, err error) { result, err := l.svcCtx.CoreRpc.UpdateUserStatus(l.ctx, &core.StatusCodeReq{ Id: req.Id, Status: req.Status, @@ -34,5 +37,5 @@ func (l *UpdateUserStatusLogic) UpdateUserStatus(req *types.StatusCodeReq) (resp return nil, err } - return &types.SimpleMsg{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: result.Msg}, nil } diff --git a/api/internal/middleware/authority_middleware.go b/api/internal/middleware/authority_middleware.go index ab6912de..91c469ed 100644 --- a/api/internal/middleware/authority_middleware.go +++ b/api/internal/middleware/authority_middleware.go @@ -37,7 +37,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { // check the role status roleStatus, err := m.Rds.Hget("roleData", fmt.Sprintf("%s_status", roleId)) if err != nil { - logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) httpx.Error(w, errorx.NewApiErrorWithoutMsg(http.StatusUnauthorized)) return } else if roleStatus == "0" { diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 959269ca..02e19914 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -33,19 +33,25 @@ type RoleInfo struct { OrderNo uint32 `json:"orderNo" validate:"number,max=1000"` } -// The response data of role list | 角色列表数据 -// swagger:response RoleListResp +// The response data of role list | 角色列表返回数据 +// swagger:model RoleListResp type RoleListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The role list data | 角色列表数据 + Data RoleListInfo `json:"data"` +} + +// The data of role list | 角色列表数据 +// swagger:model RoleListInfo +type RoleListInfo struct { + BaseListInfo // The role list data | 角色列表数据 - // in: body Data []RoleInfo `json:"data"` } // The basic response with data | 基础带数据信息 -// swagger:model BaseDataResp -type BaseDataResp struct { +// swagger:model BaseDataInfo +type BaseDataInfo struct { // Error code | 错误代码 Code int `json:"code"` // Message | 提示信息 @@ -55,12 +61,8 @@ type BaseDataResp struct { } // The basic response with data | 基础带数据信息 -// swagger:model BaseListResp -type BaseListResp struct { - // Error code | 错误代码 - Code int `json:"code"` - // Message | 提示信息 - Msg string `json:"msg"` +// swagger:model BaseListInfo +type BaseListInfo struct { // The total number of data | 数据总数 Total uint64 `json:"total"` // Data | 数据 @@ -68,10 +70,12 @@ type BaseListResp struct { } // The basic response without data | 基础不带数据信息 -// swagger:response BaseResp -type BaseResp struct { - Code int `json:"code"` - Msg string `json:"msg"` +// swagger:model BaseMsgResp +type BaseMsgResp struct { + // Error code | 错误代码 + Code int `json:"code"` + // Message | 提示信息 + Msg string `json:"msg"` } // The simplest message | 最简单的信息 @@ -171,9 +175,17 @@ type LoginReq struct { Captcha string `json:"captcha" validate:"len=5"` } -// The login response data | 登录返回数据 -// swagger:response LoginResp +// The log in response data | 登录返回数据 +// swagger:model LoginResp type LoginResp struct { + BaseDataInfo + // The log in information | 登陆返回的数据信息 + Data LoginInfo `json:"data"` +} + +// The log in information | 登陆返回的数据信息 +// swagger:model LoginInfo +type LoginInfo struct { // User's UUID | 用户的UUID UserId string `json:"userId"` // User's role information| 用户的角色信息 @@ -185,9 +197,9 @@ type LoginResp struct { Expire uint64 `json:"expire"` } -// The profile response data | 个人信息返回数据 -// swagger:response ProfileResp -type ProfileResp struct { +// The profile information | 个人信息 +// swagger:model ProfileInfo +type ProfileInfo struct { // user's nickname | 用户的昵称 Nickname string `json:"nickname"` // The user's avatar path | 用户的头像路径 @@ -198,6 +210,14 @@ type ProfileResp struct { Email string `json:"email"` } +// The profile response data | 个人信息返回数据 +// swagger:model ProfileResp +type ProfileResp struct { + BaseDataInfo + // The profile information | 个人信息 + Data ProfileInfo `json:"data"` +} + // The profile request data | 个人信息请求参数 // swagger:model ProfileReq type ProfileReq struct { @@ -215,7 +235,7 @@ type ProfileReq struct { } // The simple role data | 简单的角色数据 -// swagger:response RoleInfoSimple +// swagger:model RoleInfoSimple type RoleInfoSimple struct { // Role name | 角色名 RoleName string `json:"roleName"` @@ -263,7 +283,7 @@ type ChangePasswordReq struct { } // The response data of user's information | 用户信息返回数据 -// swagger:response UserInfoResp +// swagger:model UserInfoResp type UserInfoResp struct { BaseInfo // User's UUID | 用户的UUID @@ -288,8 +308,16 @@ type UserInfoResp struct { } // The response data of user's basic information | 用户基本信息返回数据 -// swagger:response GetUserInfoResp +// swagger:model GetUserInfoResp type GetUserInfoResp struct { + BaseDataInfo + // The data of user's basic information | 用户基本信息 + Data UserBaseInfo `json:"data"` +} + +// The data of user's basic information | 用户基本信息 +// swagger:model UserBaseInfo +type UserBaseInfo struct { // User's UUID | 用户的UUID UUID string `json:"userId"` // User's name | 用户名 @@ -312,19 +340,26 @@ type GetUserRoleInfo struct { Value string `json:"value"` } -// The response data of user list | 用户列表数据 -// swagger:response UserListResp +// The response data of user list | 用户列表返回数据 +// swagger:model UserListResp type UserListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The user list data | 用户列表数据 + Data UserListInfo `json:"data"` +} + +// The response data of user list | 用户列表数据 +// swagger:model UserListInfo +type UserListInfo struct { + BaseListInfo // The user list data | 用户列表数据 - // in: body Data []UserInfoResp `json:"data"` } // The permission code for front end permission control | 权限码: 用于前端权限控制 -// swagger:response PermCodeResp +// swagger:model PermCodeResp type PermCodeResp struct { + BaseDataInfo // Permission code data | 权限码数据 Data []string `json:"data"` } @@ -430,7 +465,7 @@ type MenuInfo struct { } // The meta data of menu | 菜单的meta数据 -// swagger:response Meta +// swagger:model Meta type Meta struct { // Menu title show in page | 菜单显示名 // Max length: 50 @@ -463,17 +498,23 @@ type Meta struct { RealPath string `json:"realPath,omitempty" validate:"max=200"` } -// The response data of menu list | 菜单列表数据 -// swagger:response MenuListResp +// The response data of menu list | 菜单列表返回数据 +// swagger:model MenuListResp type MenuListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The menu list data | 菜单列表数据 + Data MenuListInfo `json:"data"` +} + +// The data of menu list | 菜单列表数据 +// swagger:model MenuListInfo +type MenuListInfo struct { + BaseListInfo // The menu list data | 菜单列表数据 - // in: body Data []*MenuInfo `json:"data"` } -// The response data of role menu list, show after user login | 角色菜单列表数据, 登录后自动获取 +// The response data of role menu list data | 角色菜单列表数据 type GetMenuListBase struct { // Menu type: directory or menu | 菜单类型: 目录或菜单 MenuType uint32 `json:"type"` @@ -500,6 +541,22 @@ type GetMenuListBase struct { Children []*GetMenuListBase `json:"children"` } +// The response data of role menu list, show after user login | 角色菜单列表数据, 登录后自动获取 +// swagger:model GetMenuListBaseResp +type GetMenuListBaseResp struct { + BaseDataInfo + // The data of role menu list data | 角色菜单列表数据 + Data GetMenuListBaseInfo `json:"data"` +} + +// The data of role menu list, show after user login | 角色菜单列表数据 +// swagger:model GetMenuListBaseInfo +type GetMenuListBaseInfo struct { + BaseListInfo + // The response data of role menu list data | 角色菜单列表数据 + Data []*GetMenuListBase `json:"data"` +} + // Create or update menu information request params | 创建或更新菜单信息参数 // swagger:model CreateOrUpdateMenuReq type CreateOrUpdateMenuReq struct { @@ -567,9 +624,17 @@ type CreateOrUpdateMenuParamReq struct { Value string `json:"value" validate:"min=1,max=100"` } -// The response data of menu parameters | 菜单参数列表数据 -// swagger:response MenuParamResp +// The response data of menu parameters | 菜单参数返回数据 +// swagger:model MenuParamResp type MenuParamResp struct { + BaseDataInfo + // The information of menu parameter | 菜单参数数据 + Data MenuParamInfo `json:"data"` +} + +// The information of menu parameter | 菜单参数数据 +// swagger:model MenuParamInfo +type MenuParamInfo struct { BaseInfo // Data Type | 数据类型 DataType string `json:"dataType"` @@ -580,22 +645,36 @@ type MenuParamResp struct { } // The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 -// swagger:response MenuParamListByMenuIdResp +// swagger:model MenuParamListByMenuIdResp type MenuParamListByMenuIdResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo // The menu list data | 菜单列表数据 - // in: body - Data []MenuParamResp `json:"data"` + Data MenuParamListByMenuIdInfo `json:"data"` } -// The response data of captcha | 验证码返回数据 +// The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 +// swagger:model MenuParamListByMenuIdInfo +type MenuParamListByMenuIdInfo struct { + BaseListInfo + // The menu list data | 菜单列表数据 + Data []MenuParamInfo `json:"data"` +} + +// The information of captcha | 验证码数据 // swagger:model CaptchaInfo type CaptchaInfo struct { CaptchaId string `json:"captchaId"` ImgPath string `json:"imgPath"` } +// The response data of captcha | 验证码返回数据 +// swagger:model CaptchaResp +type CaptchaResp struct { + BaseDataInfo + // The menu authorization data | 菜单授权信息数据 + Data CaptchaInfo `json:"data"` +} + // The response data of API information | API信息 // swagger:model ApiInfo type ApiInfo struct { @@ -642,7 +721,15 @@ type CreateOrUpdateApiReq struct { // The response data of API list | API列表数据 // swagger:model ApiListResp type ApiListResp struct { - BaseListResp + BaseDataInfo + // API list data | API 列表数据 + Data ApiListInfo `json:"data"` +} + +// API list data | API 列表数据 +// swagger:model ApiListInfo +type ApiListInfo struct { + BaseListInfo // The API list data | API列表数据 Data []ApiInfo `json:"data"` } @@ -686,10 +773,18 @@ type CreateOrUpdateApiAuthorityReq struct { Data []ApiAuthorityInfo `json:"data"` } -// The response data of api authorization list | API授权列表数据 +// The response data of api authorization list | API授权列表返回数据 // swagger:model ApiAuthorityListResp type ApiAuthorityListResp struct { - BaseListResp + BaseDataInfo + // The api authorization list data | API授权列表数据 + Data ApiAuthorityListInfo `json:"data"` +} + +// The data of api authorization list | API授权列表数据 +// swagger:model ApiAuthorityListInfo +type ApiAuthorityListInfo struct { + BaseListInfo // The api authorization list data | API授权列表数据 Data []ApiAuthorityInfo `json:"data"` } @@ -707,9 +802,11 @@ type MenuAuthorityInfoReq struct { } // Menu authorization response data | 菜单授权信息数据 -// swagger:response MenuAuthorityInfoResp +// swagger:model MenuAuthorityInfoResp type MenuAuthorityInfoResp struct { - BaseDataResp + BaseDataInfo + // The menu authorization data | 菜单授权信息数据 + Data MenuAuthorityInfoReq `json:"data"` } // The response data of dictionary information | 字典信息 @@ -752,12 +849,18 @@ type CreateOrUpdateDictionaryReq struct { } // The response data of dictionary list | 字典列表数据 -// swagger:response DictionaryListResp +// swagger:model DictionaryListResp type DictionaryListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The dictionary list data | 字典列表数据 + Data DictionaryListInfo `json:"data"` +} + +// The response data of dictionary list | 字典列表数据 +// swagger:model DictionaryListInfo +type DictionaryListInfo struct { + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryInfo `json:"data"` } @@ -788,12 +891,18 @@ type DictionaryDetailInfo struct { } // The response data of dictionary KV list | 字典值的列表数据 -// swagger:response DictionaryDetailListResp +// swagger:model DictionaryDetailListResp type DictionaryDetailListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The dictionary list data | 字典列表数据 + Data DictionaryDetailListInfo `json:"data"` +} + +// The data of dictionary KV list | 字典值的列表数据 +// swagger:model DictionaryDetailListInfo +type DictionaryDetailListInfo struct { + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryDetailInfo `json:"data"` } @@ -903,12 +1012,10 @@ type CreateOrUpdateProviderReq struct { } // The response data of provider list | 提供商列表数据 -// swagger:response ProviderListResp +// swagger:model ProviderListResp type ProviderListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseListInfo // The provider list data | 提供商列表数据 - // in: body Data []ProviderInfo `json:"data"` } @@ -926,14 +1033,23 @@ type OauthLoginReq struct { Provider string `json:"provider" validate:"max=40"` } -// Redirect response | 跳转网址 -// swagger:response RedirectResp +// Redirect response | 跳转网址返回信息 +// swagger:model RedirectResp type RedirectResp struct { + BaseDataInfo + // Redirect information | 跳转网址 + Data RedirectInfo `json:"data"` +} + +// Redirect information | 跳转网址 +// swagger:model RedirectInfo +type RedirectInfo struct { + // Redirect URL | 跳转网址 URL string `json:"URL"` } // The oauth callback response data | Oauth回调数据 -// swagger:response CallbackResp +// swagger:model CallbackResp type CallbackResp struct { // User's UUID | 用户的UUID UserId string `json:"userId"` @@ -987,13 +1103,19 @@ type CreateOrUpdateTokenReq struct { ExpiredAt int64 `json:"expiredAt" validate:"number"` } -// The response data of Token list | Token列表数据 -// swagger:response TokenListResp +// The response data of Token list | Token列表返回数据 +// swagger:model TokenListResp type TokenListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + // The token list data | Token列表数据 + Data TokenListInfo `json:"data"` +} + +// The data of Token list | Token列表数据 +// swagger:model TokenListInfo +type TokenListInfo struct { + BaseListInfo // The token list data | Token列表数据 - // in: body Data []TokenInfo `json:"data"` } diff --git a/core.yml b/core.yml index 3e55a676..783aad22 100644 --- a/core.yml +++ b/core.yml @@ -15,8 +15,24 @@ definitions: x-go-name: Path type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ApiAuthorityListInfo: + description: The data of api authorization list | API授权列表数据 + properties: + data: + description: The api authorization list data | API授权列表数据 + items: + $ref: '#/definitions/ApiAuthorityInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ApiAuthorityListResp: - description: The response data of api authorization list | API授权列表数据 + description: The response data of api authorization list | API授权列表返回数据 properties: code: description: Error code | 错误代码 @@ -24,20 +40,14 @@ definitions: type: integer x-go-name: Code data: - description: The api authorization list data | API授权列表数据 - items: - $ref: '#/definitions/ApiAuthorityInfo' - type: array + $ref: '#/definitions/ApiAuthorityListInfo' + description: Data | 数据 + type: string x-go-name: Data msg: description: Message | 提示信息 type: string x-go-name: Msg - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - x-go-name: Total type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ApiInfo: @@ -80,6 +90,22 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ApiListInfo: + description: API list data | API 列表数据 + properties: + data: + description: The API list data | API列表数据 + items: + $ref: '#/definitions/ApiInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ApiListReq: description: Get API list request params | API列表请求参数 properties: @@ -128,23 +154,17 @@ definitions: type: integer x-go-name: Code data: - description: The API list data | API列表数据 - items: - $ref: '#/definitions/ApiInfo' - type: array + $ref: '#/definitions/ApiListInfo' + description: Data | 数据 + type: string x-go-name: Data msg: description: Message | 提示信息 type: string x-go-name: Msg - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - x-go-name: Total type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - BaseDataResp: + BaseDataInfo: description: The basic response with data | 基础带数据信息 properties: code: @@ -182,31 +202,56 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - BaseListResp: + BaseListInfo: description: The basic response with data | 基础带数据信息 + properties: + data: + description: Data | 数据 + type: string + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + BaseMsgResp: + description: The basic response without data | 基础不带数据信息 properties: code: description: Error code | 错误代码 format: int64 type: integer x-go-name: Code - data: - description: Data | 数据 - type: string - x-go-name: Data msg: description: Message | 提示信息 type: string x-go-name: Msg - total: - description: The total number of data | 数据总数 + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + CallbackResp: + description: The oauth callback response data | Oauth回调数据 + properties: + expire: + description: Expire timestamp | 过期时间戳 format: uint64 type: integer - x-go-name: Total + x-go-name: Expire + role: + $ref: '#/definitions/RoleInfoSimple' + token: + description: Token for authorization | 验证身份的token + type: string + x-go-name: Token + userId: + description: User's UUID | 用户的UUID + type: string + x-go-name: UserId type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types CaptchaInfo: - description: The response data of captcha | 验证码返回数据 + description: The information of captcha | 验证码数据 properties: captchaId: type: string @@ -216,6 +261,25 @@ definitions: x-go-name: ImgPath type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + CaptchaResp: + description: The response data of captcha | 验证码返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/CaptchaInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ChangePasswordReq: description: change user's password request | 修改密码请求参数 properties: @@ -747,6 +811,41 @@ definitions: x-go-name: Value type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + DictionaryDetailListInfo: + description: The data of dictionary KV list | 字典值的列表数据 + properties: + data: + description: The dictionary list data | 字典列表数据 + items: + $ref: '#/definitions/DictionaryDetailInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + DictionaryDetailListResp: + description: The response data of dictionary KV list | 字典值的列表数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/DictionaryDetailListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types DictionaryDetailReq: description: Get dictionary detail list by dictionary name request | 根据字典名称获取对应键值请求 properties: @@ -793,6 +892,22 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + DictionaryListInfo: + description: The response data of dictionary list | 字典列表数据 + properties: + data: + description: The dictionary list data | 字典列表数据 + items: + $ref: '#/definitions/DictionaryInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types DictionaryListReq: description: Get dictionary list request params | 字典列表请求参数 properties: @@ -822,65 +937,193 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - GetUserListReq: - description: Get user list request | 获取用户列表请求参数 + DictionaryListResp: + description: The response data of dictionary list | 字典列表数据 properties: - email: - description: The user's email address | 用户的邮箱 - maxLength: 100 + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/DictionaryListInfo' + description: Data | 数据 type: string - x-go-name: Email - mobile: - description: User's mobile phone number | 用户的手机号码 - maxLength: 18 + x-go-name: Data + msg: + description: Message | 提示信息 type: string - x-go-name: Mobile - nickname: - description: User's nickname | 用户的昵称 - maxLength: 10 + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + GetMenuListBase: + description: The response data of role menu list data | 角色菜单列表数据 + properties: + children: + description: |- + children | 子集 + in: body + items: + $ref: '#/definitions/GetMenuListBase' + type: array + x-go-name: Children + component: + description: The component path | 组件路径 type: string - x-go-name: Nickname - page: - description: Page number | 第几页 - format: uint64 + x-go-name: Component + disabled: + description: If disabled | 是否禁用菜单 + type: boolean + x-go-name: Disabled + level: + description: The menu level | 菜单等级 + format: uint32 type: integer - x-go-name: Page - pageSize: - description: Page size | 单页数据行数 - format: uint64 - maximum: 100000 + x-go-name: MenuLevel + meta: + $ref: '#/definitions/Meta' + name: + description: Menu name | 菜单名 + type: string + x-go-name: Name + orderNo: + description: The sorting number | 排序编号 + format: uint32 type: integer - x-go-name: PageSize - roleId: - description: User's role ID | 用户的角色ID + x-go-name: OrderNo + parentId: + description: Parent menu ID | 父级菜单ID format: uint64 - maximum: 1000 type: integer - x-go-name: RoleId - username: - description: User Name | 用户名 - maxLength: 20 + x-go-name: ParentId + path: + description: The path to visit menu | 菜单访问路径 type: string - x-go-name: Username - required: - - page - - pageSize + x-go-name: Path + redirect: + description: Redirect path | 跳转路径 + type: string + x-go-name: Redirect + type: + description: 'Menu type: directory or menu | 菜单类型: 目录或菜单' + format: uint32 + type: integer + x-go-name: MenuType type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - GetUserRoleInfo: - description: The response data of user's basic role information | 用户角色信息数据 + GetMenuListBaseInfo: + description: The data of role menu list, show after user login | 角色菜单列表数据 properties: - roleName: - description: Role name | 角色名 - type: string - x-go-name: RoleName - value: - description: Role value for permission control | 角色值用于前端页面组件显示权限 - type: string - x-go-name: Value + data: + description: The response data of role menu list data | 角色菜单列表数据 + items: + $ref: '#/definitions/GetMenuListBase' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - IDPathReq: + GetMenuListBaseResp: + description: The response data of role menu list, show after user login | 角色菜单列表数据, 登录后自动获取 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/GetMenuListBaseInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + GetUserInfoResp: + description: The response data of user's basic information | 用户基本信息返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/UserBaseInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + GetUserListReq: + description: Get user list request | 获取用户列表请求参数 + properties: + email: + description: The user's email address | 用户的邮箱 + maxLength: 100 + type: string + x-go-name: Email + mobile: + description: User's mobile phone number | 用户的手机号码 + maxLength: 18 + type: string + x-go-name: Mobile + nickname: + description: User's nickname | 用户的昵称 + maxLength: 10 + type: string + x-go-name: Nickname + page: + description: Page number | 第几页 + format: uint64 + type: integer + x-go-name: Page + pageSize: + description: Page size | 单页数据行数 + format: uint64 + maximum: 100000 + type: integer + x-go-name: PageSize + roleId: + description: User's role ID | 用户的角色ID + format: uint64 + maximum: 1000 + type: integer + x-go-name: RoleId + username: + description: User Name | 用户名 + maxLength: 20 + type: string + x-go-name: Username + required: + - page + - pageSize + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + GetUserRoleInfo: + description: The response data of user's basic role information | 用户角色信息数据 + properties: + roleName: + description: Role name | 角色名 + type: string + x-go-name: RoleName + value: + description: Role value for permission control | 角色值用于前端页面组件显示权限 + type: string + x-go-name: Value + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + IDPathReq: description: Basic id request | 基础id参数请求 properties: Id: @@ -903,6 +1146,26 @@ definitions: - id type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + LoginInfo: + description: The log in information | 登陆返回的数据信息 + properties: + expire: + description: Expire timestamp | 过期时间戳 + format: uint64 + type: integer + x-go-name: Expire + role: + $ref: '#/definitions/RoleInfoSimple' + token: + description: Token for authorization | 验证身份的token + type: string + x-go-name: Token + userId: + description: User's UUID | 用户的UUID + type: string + x-go-name: UserId + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types LoginReq: description: login request | 登录参数 properties: @@ -934,6 +1197,25 @@ definitions: - captcha type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + LoginResp: + description: The log in response data | 登录返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/LoginInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types MenuAuthorityInfoReq: description: Create or update menu authorization information request params | 创建或更新菜单授权信息参数 properties: @@ -955,6 +1237,25 @@ definitions: - menuIds type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuAuthorityInfoResp: + description: Menu authorization response data | 菜单授权信息数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/MenuAuthorityInfoReq' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types MenuInfo: description: The response data of menu information | 菜单返回数据 properties: @@ -1085,8 +1386,43 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - MenuParamResp: - description: The response data of menu parameters | 菜单参数列表数据 + MenuListInfo: + description: The data of menu list | 菜单列表数据 + properties: + data: + description: The menu list data | 菜单列表数据 + items: + $ref: '#/definitions/MenuInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuListResp: + description: The response data of menu list | 菜单列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/MenuListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuParamInfo: + description: The information of menu parameter | 菜单参数数据 properties: createdAt: description: Create date | 创建日期 @@ -1117,6 +1453,60 @@ definitions: x-go-name: Value type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuParamListByMenuIdInfo: + description: The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 + properties: + data: + description: The menu list data | 菜单列表数据 + items: + $ref: '#/definitions/MenuParamInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuParamListByMenuIdResp: + description: The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/MenuParamListByMenuIdInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + MenuParamResp: + description: The response data of menu parameters | 菜单参数返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/MenuParamInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types Meta: description: The meta data of menu | 菜单的meta数据 properties: @@ -1216,8 +1606,28 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - ProfileReq: - description: The profile request data | 个人信息请求参数 + PermCodeResp: + description: The permission code for front end permission control | 权限码: 用于前端权限控制 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + description: Permission code data | 权限码数据 + items: + type: string + type: array + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProfileInfo: + description: The profile information | 个人信息 properties: avatar: description: The user's avatar path | 用户的头像路径 @@ -1225,30 +1635,70 @@ definitions: x-go-name: Avatar email: description: The user's email address | 用户的邮箱 - maxLength: 100 type: string x-go-name: Email mobile: description: User's mobile phone number | 用户的手机号码 - maxLength: 18 type: string x-go-name: Mobile nickname: description: user's nickname | 用户的昵称 - maxLength: 10 type: string x-go-name: Nickname type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - ProviderInfo: - description: The response data of oauth provider information | 提供者信息 + ProfileReq: + description: The profile request data | 个人信息请求参数 properties: - authStyle: - description: Auth Style is specifies how the endpoint wants the client ID & client secret sent. The zero value means to auto-detect. | 鉴权方式, 0 表示自动检测 - format: int64 - type: integer - x-go-name: AuthStyle - authURL: + avatar: + description: The user's avatar path | 用户的头像路径 + type: string + x-go-name: Avatar + email: + description: The user's email address | 用户的邮箱 + maxLength: 100 + type: string + x-go-name: Email + mobile: + description: User's mobile phone number | 用户的手机号码 + maxLength: 18 + type: string + x-go-name: Mobile + nickname: + description: user's nickname | 用户的昵称 + maxLength: 10 + type: string + x-go-name: Nickname + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProfileResp: + description: The profile response data | 个人信息返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/ProfileInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProviderInfo: + description: The response data of oauth provider information | 提供者信息 + properties: + authStyle: + description: Auth Style is specifies how the endpoint wants the client ID & client secret sent. The zero value means to auto-detect. | 鉴权方式, 0 表示自动检测 + format: int64 + type: integer + x-go-name: AuthStyle + authURL: description: Auth URL | 鉴权URL type: string x-go-name: AuthURL @@ -1297,6 +1747,49 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProviderListResp: + description: The response data of provider list | 提供商列表数据 + properties: + data: + description: The provider list data | 提供商列表数据 + items: + $ref: '#/definitions/ProviderInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + RedirectInfo: + description: Redirect information | 跳转网址 + properties: + URL: + description: Redirect URL | 跳转网址 + type: string + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + RedirectResp: + description: Redirect response | 跳转网址返回信息 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/RedirectInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types RegisterReq: description: register request | 注册参数 properties: @@ -1410,6 +1903,41 @@ definitions: x-go-name: Value type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + RoleListInfo: + description: The data of role list | 角色列表数据 + properties: + data: + description: The role list data | 角色列表数据 + items: + $ref: '#/definitions/RoleInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + RoleListResp: + description: The response data of role list | 角色列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/RoleListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types StatusCodeReq: description: The request params of setting boolean status | 设置状态参数 properties: @@ -1469,6 +1997,22 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + TokenListInfo: + description: The data of Token list | Token列表数据 + properties: + data: + description: The token list data | Token列表数据 + items: + $ref: '#/definitions/TokenInfo' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types TokenListReq: description: Get token list request params | token列表请求参数 properties: @@ -1507,6 +2051,25 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + TokenListResp: + description: The response data of Token list | Token列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/TokenListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types UUIDReq: description: Basic UUID request | 基础UUID参数请求 properties: @@ -1518,6 +2081,29 @@ definitions: - UUID type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + UserBaseInfo: + description: The data of user's basic information | 用户基本信息 + properties: + avatar: + description: The user's avatar path | 用户的头像路径 + type: string + x-go-name: Avatar + nickname: + description: User's nickname | 用户的昵称 + type: string + x-go-name: Nickname + roles: + $ref: '#/definitions/GetUserRoleInfo' + userId: + description: User's UUID | 用户的UUID + type: string + x-go-name: UUID + username: + description: User's name | 用户名 + type: string + x-go-name: Username + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types UserInfoResp: description: The response data of user's information | 用户信息返回数据 properties: @@ -1577,6 +2163,41 @@ definitions: x-go-name: Username type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + UserListInfo: + description: The response data of user list | 用户列表数据 + properties: + data: + description: The user list data | 用户列表数据 + items: + $ref: '#/definitions/UserInfoResp' + type: array + x-go-name: Data + total: + description: The total number of data | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + UserListResp: + description: The response data of user list | 用户列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/UserListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types host: localhost:9100 info: contact: @@ -1597,11 +2218,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete API information | 删除API信息 tags: - api @@ -1616,11 +2235,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update API information | 创建或更新API tags: - api @@ -1639,10 +2256,6 @@ paths: description: ApiListResp schema: $ref: '#/definitions/ApiListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' summary: Get API list | 获取API列表 tags: - api @@ -1658,11 +2271,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update API authorization information | 创建或更新API权限 tags: - authority @@ -1681,10 +2292,6 @@ paths: description: ApiAuthorityListResp schema: $ref: '#/definitions/ApiAuthorityListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' summary: Get role's API authorization list | 获取角色api权限列表 tags: - authority @@ -1700,11 +2307,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update menu authorization information | 创建或更新菜单权限 tags: - authority @@ -1720,11 +2325,9 @@ paths: type: object responses: "200": - $ref: '#/responses/MenuAuthorityInfoResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: MenuAuthorityInfoResp + schema: + $ref: '#/definitions/MenuAuthorityInfoResp' summary: Get role's menu authorization list | 获取角色菜单权限列表 tags: - authority @@ -1734,13 +2337,9 @@ paths: operationId: GetCaptcha responses: "200": - description: CaptchaInfo + description: CaptchaResp schema: - $ref: '#/definitions/CaptchaInfo' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + $ref: '#/definitions/CaptchaResp' summary: Get captcha | 获取验证码 tags: - captcha @@ -1757,11 +2356,9 @@ paths: operationId: InitDatabase responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Initialize database | 初始化数据库 tags: - core @@ -1777,11 +2374,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete dictionary information | 删除字典信息 tags: - dictionary @@ -1796,11 +2391,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update dictionary information | 创建或更新字典信息 tags: - dictionary @@ -1816,11 +2409,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete dictionary KV information | 删除字典键值信息 tags: - dictionary @@ -1835,11 +2426,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update dictionary KV information | 创建或更新字典键值信息 tags: - dictionary @@ -1855,11 +2444,9 @@ paths: type: object responses: "200": - $ref: '#/responses/DictionaryDetailListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: DictionaryDetailListResp + schema: + $ref: '#/definitions/DictionaryDetailListResp' summary: Get dictionary detail list by dictionary name | 根据字典名获取字典键值列表 tags: - dictionary @@ -1875,11 +2462,9 @@ paths: type: object responses: "200": - $ref: '#/responses/DictionaryListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: DictionaryListResp + schema: + $ref: '#/definitions/DictionaryListResp' summary: Get dictionary list | 获取字典列表 tags: - dictionary @@ -1895,11 +2480,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete menu information | 删除菜单信息 tags: - menu @@ -1914,11 +2497,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update menu information | 创建或更新菜单 tags: - menu @@ -1928,11 +2509,9 @@ paths: operationId: GetMenuList responses: "200": - $ref: '#/responses/MenuListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: MenuListResp + schema: + $ref: '#/definitions/MenuListResp' summary: Get menu list | 获取菜单列表 tags: - menu @@ -1948,11 +2527,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete menu extra parameters | 删除菜单额外参数 tags: - menu @@ -1967,11 +2544,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update menu parameters | 创建或更新菜单参数 tags: - menu @@ -1987,11 +2562,9 @@ paths: type: object responses: "200": - $ref: '#/responses/MenuParamListByMenuIdResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: MenuParamListByMenuIdResp + schema: + $ref: '#/definitions/MenuParamListByMenuIdResp' summary: Get menu extra parameters by menu ID | 获取某个菜单的额外参数列表 tags: - menu @@ -2001,11 +2574,9 @@ paths: operationId: GetMenuByRole responses: "200": - $ref: '#/responses/GetMenuListBase' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: GetMenuListBase + schema: + $ref: '#/definitions/GetMenuListBase' summary: Get role's menu list API | 获取角色菜单列表 tags: - menu @@ -2021,11 +2592,9 @@ paths: type: object responses: "200": - $ref: '#/responses/RedirectResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: RedirectResp + schema: + $ref: '#/definitions/RedirectResp' summary: Oauth log in | Oauth 登录 tags: - oauth @@ -2035,11 +2604,9 @@ paths: operationId: OauthCallback responses: "200": - $ref: '#/responses/CallbackResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: CallbackResp + schema: + $ref: '#/definitions/CallbackResp' summary: Oauth log in callback route | Oauth 登录返回调接口 tags: - oauth @@ -2055,11 +2622,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete provider information | 删除提供商信息 tags: - oauth @@ -2074,11 +2639,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update Provider information | 创建或更新提供商 tags: - oauth @@ -2094,11 +2657,9 @@ paths: type: object responses: "200": - $ref: '#/responses/ProviderListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: ProviderListResp + schema: + $ref: '#/definitions/ProviderListResp' summary: Get provider list | 获取提供商列表 tags: - oauth @@ -2114,11 +2675,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete role information | 删除角色信息 tags: - role @@ -2133,11 +2692,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update role information | 创建或更新角色 tags: - role @@ -2153,11 +2710,9 @@ paths: type: object responses: "200": - $ref: '#/responses/RoleListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: RoleListResp + schema: + $ref: '#/definitions/RoleListResp' summary: Get role list | 获取角色列表 tags: - role @@ -2173,11 +2728,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Set role status | 设置角色状态 tags: - role @@ -2193,11 +2746,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete token information | 删除token信息 tags: - token @@ -2212,11 +2763,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update Token information | 创建或更新Token tags: - token @@ -2232,11 +2781,9 @@ paths: type: object responses: "200": - $ref: '#/responses/TokenListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: TokenListResp + schema: + $ref: '#/definitions/TokenListResp' summary: Get Token list | 获取token列表 tags: - token @@ -2252,11 +2799,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Force logging out by user UUID | 根据UUID强制用户退出 tags: - token @@ -2272,11 +2817,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Set token status | 设置token状态 tags: - token @@ -2292,11 +2835,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Delete user information | 删除用户信息 tags: - user @@ -2311,11 +2852,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Create or update user's information | 新增或更新用户 tags: - user @@ -2331,11 +2870,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Change Password | 修改密码 tags: - user @@ -2345,11 +2882,9 @@ paths: operationId: GetUserInfo responses: "200": - $ref: '#/responses/GetUserInfoResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: GetUserInfoResp + schema: + $ref: '#/definitions/GetUserInfoResp' summary: Get user basic information | 获取用户基本信息 tags: - user @@ -2365,11 +2900,9 @@ paths: type: object responses: "200": - $ref: '#/responses/UserListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: UserListResp + schema: + $ref: '#/definitions/UserListResp' summary: Get user list | 获取用户列表 tags: - user @@ -2385,11 +2918,9 @@ paths: type: object responses: "200": - $ref: '#/responses/LoginResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' summary: Log in | 登录 tags: - user @@ -2399,11 +2930,9 @@ paths: operationId: Logout responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Log out | 退出登陆 tags: - user @@ -2413,11 +2942,9 @@ paths: operationId: GetUserPermCode responses: "200": - $ref: '#/responses/PermCodeResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: PermCodeResp + schema: + $ref: '#/definitions/PermCodeResp' summary: Get user's permission code | 获取用户权限码 tags: - user @@ -2427,11 +2954,9 @@ paths: operationId: GetUserProfile responses: "200": - $ref: '#/responses/ProfileResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: ProfileResp + schema: + $ref: '#/definitions/ProfileResp' summary: Get user's profile | 获取用户个人信息 tags: - user @@ -2446,11 +2971,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Update user's profile | 更新用户个人信息 tags: - user @@ -2466,11 +2989,9 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Register | 注册 tags: - user @@ -2486,199 +3007,15 @@ paths: type: object responses: "200": - $ref: '#/responses/SimpleMsg' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: BaseMsgResp + schema: + $ref: '#/definitions/BaseMsgResp' summary: Set user's status | 更新用户状态 tags: - user produces: - application/json responses: - BaseResp: - description: The basic response without data | 基础不带数据信息 - headers: - code: - format: int64 - type: integer - msg: - type: string - CallbackResp: - description: The oauth callback response data | Oauth回调数据 - headers: - expire: - description: Expire timestamp | 过期时间戳 - format: uint64 - type: integer - token: - description: Token for authorization | 验证身份的token - type: string - userId: - description: User's UUID | 用户的UUID - type: string - schema: - $ref: '#/definitions/RoleInfoSimple' - DictionaryDetailListResp: - description: The response data of dictionary KV list | 字典值的列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/DictionaryDetailInfo' - type: array - DictionaryListResp: - description: The response data of dictionary list | 字典列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/DictionaryInfo' - type: array - GetUserInfoResp: - description: The response data of user's basic information | 用户基本信息返回数据 - headers: - avatar: - description: The user's avatar path | 用户的头像路径 - type: string - nickname: - description: User's nickname | 用户的昵称 - type: string - userId: - description: User's UUID | 用户的UUID - type: string - username: - description: User's name | 用户名 - type: string - schema: - $ref: '#/definitions/GetUserRoleInfo' - LoginResp: - description: The login response data | 登录返回数据 - headers: - expire: - description: Expire timestamp | 过期时间戳 - format: uint64 - type: integer - token: - description: Token for authorization | 验证身份的token - type: string - userId: - description: User's UUID | 用户的UUID - type: string - schema: - $ref: '#/definitions/RoleInfoSimple' - MenuAuthorityInfoResp: - description: Menu authorization response data | 菜单授权信息数据 - headers: - code: - description: Error code | 错误代码 - format: int64 - type: integer - data: - description: Data | 数据 - type: string - msg: - description: Message | 提示信息 - type: string - MenuListResp: - description: The response data of menu list | 菜单列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/MenuInfo' - type: array - MenuParamListByMenuIdResp: - description: The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/MenuParamResp' - type: array - MenuParamResp: - description: The response data of menu parameters | 菜单参数列表数据 - headers: - createdAt: - description: Create date | 创建日期 - format: int64 - type: integer - dataType: - description: Data Type | 数据类型 - type: string - id: - description: ID - format: uint64 - type: integer - key: - description: Key | 键 - type: string - updatedAt: - description: Update date | 更新日期 - format: int64 - type: integer - value: - description: Value | 值 - type: string - Meta: - description: The meta data of menu | 菜单的meta数据 - headers: - affix: - description: Affix tab | 是否固定标签 - type: boolean - carryParam: - description: The route carries parameters or not | 如果该路由会携带参数,且需要在tab页上面显示。则需要设置为true - type: boolean - currentActiveMenu: - description: Current active menu, if not nil, it will active the tab | 当前激活的菜单 - maxLength: 30 - type: string - dynamicLevel: - description: The maximum number of pages the router can open | 动态路由可打开Tab页数 - format: uint32 - type: integer - frameSrc: - description: Iframe path | 内嵌iframe的地址 - type: string - hideBreadcrumb: - description: If hide the breadcrumb | 隐藏面包屑 - type: boolean - hideChildrenInMenu: - description: Hide children menu or not | 隐藏所有子菜单 - type: boolean - hideMenu: - description: Hide menu | 隐藏菜单 - type: boolean - hideTab: - description: Hide the tab header | 当前路由不在标签页显示 - type: boolean - icon: - description: Menu Icon | 菜单图标 - maxLength: 50 - type: string - ignoreKeepAlive: - description: Do not keep alive the tab | 不缓存Tab - type: boolean - realPath: - description: The real path of the route without dynamic part | 动态路由的实际Path, 即去除路由的动态部分 - type: string - title: - description: Menu title show in page | 菜单显示名 - maxLength: 50 - type: string PageList: description: The page response data model | 列表返回信息 headers: @@ -2691,139 +3028,12 @@ responses: description: Total number | 数据总数 format: uint64 type: integer - PermCodeResp: - description: The permission code for front end permission control | 权限码: 用于前端权限控制 - headers: - data: - description: Permission code data | 权限码数据 - items: - type: string - type: array - ProfileResp: - description: The profile response data | 个人信息返回数据 - headers: - avatar: - description: The user's avatar path | 用户的头像路径 - type: string - email: - description: The user's email address | 用户的邮箱 - type: string - mobile: - description: User's mobile phone number | 用户的手机号码 - type: string - nickname: - description: user's nickname | 用户的昵称 - type: string - ProviderListResp: - description: The response data of provider list | 提供商列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/ProviderInfo' - type: array - RedirectResp: - description: Redirect response | 跳转网址 - headers: - URL: - type: string - RoleInfoSimple: - description: The simple role data | 简单的角色数据 - headers: - roleName: - description: Role name | 角色名 - type: string - value: - description: Role value | 角色值 - type: string - RoleListResp: - description: The response data of role list | 角色列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/RoleInfo' - type: array SimpleMsg: description: The simplest message | 最简单的信息 headers: msg: description: Message | 信息 type: string - TokenListResp: - description: The response data of Token list | Token列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/TokenInfo' - type: array - UserInfoResp: - description: The response data of user's information | 用户信息返回数据 - headers: - UUID: - description: User's UUID | 用户的UUID - type: string - avatar: - description: The user's avatar path | 用户的头像路径 - type: string - createdAt: - description: Create date | 创建日期 - format: int64 - type: integer - email: - description: The user's email address | 用户的邮箱 - type: string - id: - description: ID - format: uint64 - type: integer - mobile: - description: User's mobile phone number | 用户的手机号码 - type: string - nickname: - description: User's nickname | 用户的昵称 - type: string - roleId: - description: User's role id | 用户的角色ID - format: uint64 - type: integer - sideMode: - description: The user's layout mode | 用户的布局 - type: string - status: - description: |- - The user's status | 用户状态 - 1 normal, 2 ban | 1 正常 2 拉黑 - format: uint64 - type: integer - updatedAt: - description: Update date | 更新日期 - format: int64 - type: integer - username: - description: User Name | 用户名 - type: string - UserListResp: - description: The response data of user list | 用户列表数据 - headers: - total: - description: The total number of data | 数据总数 - format: uint64 - type: integer - schema: - items: - $ref: '#/definitions/UserInfoResp' - type: array schemes: - http - https diff --git a/docs/simple-admin/en/docs/ent.md b/docs/simple-admin/en/docs/ent.md index f7f9ad54..21f55b74 100644 --- a/docs/simple-admin/en/docs/ent.md +++ b/docs/simple-admin/en/docs/ent.md @@ -168,7 +168,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/en/docs/global_vars.md b/docs/simple-admin/en/docs/global_vars.md index 5f2e78d4..59e1435d 100644 --- a/docs/simple-admin/en/docs/global_vars.md +++ b/docs/simple-admin/en/docs/global_vars.md @@ -93,7 +93,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -116,7 +116,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/zh-cn/docs/ent.md b/docs/simple-admin/zh-cn/docs/ent.md index 55d10e6e..5b1af604 100644 --- a/docs/simple-admin/zh-cn/docs/ent.md +++ b/docs/simple-admin/zh-cn/docs/ent.md @@ -168,7 +168,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/docs/simple-admin/zh-cn/docs/global_vars.md b/docs/simple-admin/zh-cn/docs/global_vars.md index a9d94e4b..38c96f5d 100644 --- a/docs/simple-admin/zh-cn/docs/global_vars.md +++ b/docs/simple-admin/zh-cn/docs/global_vars.md @@ -92,7 +92,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(i18n.ApiAlreadyExists) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -115,7 +115,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/go.mod b/go.mod index 851ea421..5168b483 100644 --- a/go.mod +++ b/go.mod @@ -13,13 +13,11 @@ require ( github.com/go-playground/validator/v10 v10.11.1 github.com/go-redis/redis/v8 v8.11.5 github.com/go-sql-driver/mysql v1.6.0 - github.com/golang-jwt/jwt/v4 v4.4.2 github.com/google/uuid v1.3.0 github.com/lib/pq v1.10.7 github.com/mattn/go-sqlite3 v1.14.16 github.com/mojocn/base64Captcha v1.3.5 github.com/nicksnyder/go-i18n/v2 v2.2.0 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.0 github.com/zeromicro/go-zero v1.4.2 golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b @@ -29,7 +27,7 @@ require ( google.golang.org/protobuf v1.28.1 ) -replace github.com/zeromicro/go-zero v1.4.2 => github.com/suyuan32/simple-admin-tools v0.0.8 +replace github.com/zeromicro/go-zero v1.4.2 => github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc require ( ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd // indirect @@ -53,6 +51,7 @@ require ( github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt/v4 v4.4.2 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect @@ -87,6 +86,7 @@ require ( github.com/openzipkin/zipkin-go v0.4.0 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.13.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect diff --git a/go.sum b/go.sum index 8a46e41e..b16ff2ac 100644 --- a/go.sum +++ b/go.sum @@ -865,8 +865,8 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/suyuan32/simple-admin-tools v0.0.8 h1:k6ujipGBGzEMXI13XY5ugJ/4aTQv4xyu60tNbffC9DQ= -github.com/suyuan32/simple-admin-tools v0.0.8/go.mod h1:/AGheJnwIhsVrNHsCsCY3JfDKTeUvuon3xBTZv1RnjI= +github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc h1:8qAIzvll7Ws4PGPSUBKVPOU6OCNJRiUaEhEET6tXng8= +github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc/go.mod h1:/AGheJnwIhsVrNHsCsCY3JfDKTeUvuon3xBTZv1RnjI= github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/pkg/enum/errorcode.go b/pkg/enum/errorcode.go new file mode 100644 index 00000000..f207e91d --- /dev/null +++ b/pkg/enum/errorcode.go @@ -0,0 +1,166 @@ +package enum + +const ( + // OK is returned on success. + OK int = 0 + + // Canceled indicates the operation was canceled (typically by the caller). + // + // The gRPC framework will generate this error code when cancellation + // is requested. + Canceled int = 1 + + // Unknown error. An example of where this error may be returned is + // if a Status value received from another address space belongs to + // an error-space that is not known in this address space. Also + // errors raised by APIs that do not return enough error information + // may be converted to this error. + // + // The gRPC framework will generate this error code in the above two + // mentioned cases. + Unknown int = 2 + + // InvalidArgument indicates client specified an invalid argument. + // Note that this differs from FailedPrecondition. It indicates arguments + // that are problematic regardless of the state of the system + // (e.g., a malformed file name). + // + // This error code will not be generated by the gRPC framework. + InvalidArgument int = 3 + + // DeadlineExceeded means operation expired before completion. + // For operations that change the state of the system, this error may be + // returned even if the operation has completed successfully. For + // example, a successful response from a server could have been delayed + // long enough for the deadline to expire. + // + // The gRPC framework will generate this error code when the deadline is + // exceeded. + DeadlineExceeded int = 4 + + // NotFound means some requested entity (e.g., file or directory) was + // not found. + // + // This error code will not be generated by the gRPC framework. + NotFound int = 5 + + // AlreadyExists means an attempt to create an entity failed because one + // already exists. + // + // This error code will not be generated by the gRPC framework. + AlreadyExists int = 6 + + // PermissionDenied indicates the caller does not have permission to + // execute the specified operation. It must not be used for rejections + // caused by exhausting some resource (use ResourceExhausted + // instead for those errors). It must not be + // used if the caller cannot be identified (use Unauthenticated + // instead for those errors). + // + // This error code will not be generated by the gRPC core framework, + // but expect authentication middleware to use it. + PermissionDenied int = 7 + + // ResourceExhausted indicates some resource has been exhausted, perhaps + // a per-user quota, or perhaps the entire file system is out of space. + // + // This error code will be generated by the gRPC framework in + // out-of-memory and server overload situations, or when a message is + // larger than the configured maximum size. + ResourceExhausted int = 8 + + // FailedPrecondition indicates operation was rejected because the + // system is not in a state required for the operation's execution. + // For example, directory to be deleted may be non-empty, an rmdir + // operation is applied to a non-directory, etc. + // + // A litmus test that may help a service implementor in deciding + // between FailedPrecondition, Aborted, and Unavailable: + // (a) Use Unavailable if the client can retry just the failing call. + // (b) Use Aborted if the client should retry at a higher-level + // (e.g., restarting a read-modify-write sequence). + // (c) Use FailedPrecondition if the client should not retry until + // the system state has been explicitly fixed. E.g., if an "rmdir" + // fails because the directory is non-empty, FailedPrecondition + // should be returned since the client should not retry unless + // they have first fixed up the directory by deleting files from it. + // (d) Use FailedPrecondition if the client performs conditional + // REST Get/Update/Delete on a resource and the resource on the + // server does not match the condition. E.g., conflicting + // read-modify-write on the same resource. + // + // This error code will not be generated by the gRPC framework. + FailedPrecondition int = 9 + + // Aborted indicates the operation was aborted, typically due to a + // concurrency issue like sequencer check failures, transaction aborts, + // etc. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will not be generated by the gRPC framework. + Aborted int = 10 + + // OutOfRange means operation was attempted past the valid range. + // E.g., seeking or reading past end of file. + // + // Unlike InvalidArgument, this error indicates a problem that may + // be fixed if the system state changes. For example, a 32-bit file + // system will generate InvalidArgument if asked to read at an + // offset that is not in the range [0,2^32-1], but it will generate + // OutOfRange if asked to read from an offset past the current + // file size. + // + // There is a fair bit of overlap between FailedPrecondition and + // OutOfRange. We recommend using OutOfRange (the more specific + // error) when it applies so that callers who are iterating through + // a space can easily look for an OutOfRange error to detect when + // they are done. + // + // This error code will not be generated by the gRPC framework. + OutOfRange int = 11 + + // Unimplemented indicates operation is not implemented or not + // supported/enabled in this service. + // + // This error code will be generated by the gRPC framework. Most + // commonly, you will see this error code when a method implementation + // is missing on the server. It can also be generated for unknown + // compression algorithms or a disagreement as to whether an RPC should + // be streaming. + Unimplemented int = 12 + + // Internal errors. Means some invariants expected by underlying + // system has been broken. If you see one of these errors, + // something is very broken. + // + // This error code will be generated by the gRPC framework in several + // internal error conditions. + Internal int = 13 + + // Unavailable indicates the service is currently unavailable. + // This is a most likely a transient condition and may be corrected + // by retrying with a backoff. Note that it is not always safe to retry + // non-idempotent operations. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will be generated by the gRPC framework during + // abrupt shutdown of a server process or network connection. + Unavailable int = 14 + + // DataLoss indicates unrecoverable data loss or corruption. + // + // This error code will not be generated by the gRPC framework. + DataLoss int = 15 + + // Unauthenticated indicates the request does not have valid + // authentication credentials for the operation. + // + // The gRPC framework will generate this error code when the + // authentication metadata is invalid or a Credentials callback fails, + // but also expect authentication middleware to generate it. + Unauthenticated int = 16 +) diff --git a/pkg/enum/status.go b/pkg/enum/status.go index ef409cd6..2decfe8d 100644 --- a/pkg/enum/status.go +++ b/pkg/enum/status.go @@ -4,3 +4,5 @@ const ( StatusBanned uint8 = iota StatusNormal ) + +const () diff --git a/pkg/i18n/locale/en.json b/pkg/i18n/locale/en.json index d7b266e6..7a6a9016 100644 --- a/pkg/i18n/locale/en.json +++ b/pkg/i18n/locale/en.json @@ -124,5 +124,9 @@ }, "oauth": { "createAccount": "Please register an account with this email or bind the email to an account" + }, + "casbin": { + "removeFailed": "Fail to remove old policies", + "addFailed": "Fail to add new policies" } } diff --git a/pkg/i18n/locale/zh.json b/pkg/i18n/locale/zh.json index 0d30c0fa..eafe4854 100644 --- a/pkg/i18n/locale/zh.json +++ b/pkg/i18n/locale/zh.json @@ -124,5 +124,9 @@ }, "oauth": { "createAccount": "请创建一个该邮箱的账号或绑定该邮箱到一个账号" + }, + "casbin": { + "removeFailed": "无法删除旧规则", + "addFailed": "无法添加新规则" } } diff --git a/pkg/i18n/translator.go b/pkg/i18n/translator.go index ccbbc624..529123a9 100644 --- a/pkg/i18n/translator.go +++ b/pkg/i18n/translator.go @@ -63,6 +63,12 @@ func (l *Translator) TransError(lang string, err error) error { message = err.Error() } return errorx.NewApiError(errcode.CodeFromGrpcError(err), message) + } else if codeErr, ok := err.(*errorx.CodeError); ok { + message, e := l.MatchLocalizer(lang).LocalizeMessage(&i18n.Message{ID: codeErr.Error()}) + if e != nil { + message = codeErr.Error() + } + return errorx.NewCodeError(codeErr.Code, message) } else if apiErr, ok := err.(*errorx.ApiError); ok { message, e := l.MatchLocalizer(lang).LocalizeMessage(&i18n.Message{ID: apiErr.Error()}) if e != nil { diff --git a/pkg/i18n/var.go b/pkg/i18n/var.go index 184f117f..e8220ada 100644 --- a/pkg/i18n/var.go +++ b/pkg/i18n/var.go @@ -1,17 +1,17 @@ package i18n const ( - SUCCESS = "common.success" - FAILED = "common.failed" - UPDATE_SUCCESS = "common.updateSuccess" - UPDATE_FAILED = "common.updateFailed" - CREATE_SUCCESS = "common.createSuccess" - CREATE_FAILED = "common.createFailed" - DELETE_SUCCESS = "common.deleteSuccess" - DELETE_FAILED = "common.deleteFailed" - CHANGE_STATUS_SUCCESS = "common.changeStatusSuccess" - CHANGE_STATUS_FAILED = "common.changeStatusFailed" - TARGET_NOT_FOUND = "common.targetNotExist" - DATABASE_ERROR = "common.databaseError" - REDIS_ERROR = "common.redisError" + Success = "common.success" + Failed = "common.failed" + UpdateSuccess = "common.updateSuccess" + UpdateFailed = "common.updateFailed" + CreateSuccess = "common.createSuccess" + CreateFailed = "common.createFailed" + DeleteSuccess = "common.deleteSuccess" + DeleteFailed = "common.deleteFailed" + ChangeStatusSuccess = "common.changeStatusSuccess" + ChangeStatusFailed = "common.changeStatusFailed" + TargetNotFound = "common.targetNotExist" + DatabaseError = "common.databaseError" + RedisError = "common.redisError" ) diff --git a/pkg/msg/logmsg/msg.go b/pkg/msg/logmsg/msg.go index 09ba216a..4d95ddd6 100644 --- a/pkg/msg/logmsg/msg.go +++ b/pkg/msg/logmsg/msg.go @@ -1,13 +1,13 @@ package logmsg const ( - CREATE_SUCCESS = "create successfully" - CREATE_FAILED = "create failed" - DELETE_SUCCESS = "delete successful" - DELETE_FAILED = "delete failed" - UPDATE_SUCCESS = "update successful" - UPDATE_FAILED = "update failed" - TARGET_NOT_FOUND = "target not found" - DATABASE_ERROR = "database error" - REDIS_ERROR = "redis error" + CreateSuccess string = "create successfully" + CreateFailed string = "create failed" + DeleteSuccess string = "delete successful" + DeleteFailed string = "delete failed" + UpdateSuccess string = "update successful" + UpdateFailed string = "update failed" + TargetNotFound string = "target not found" + DatabaseError string = "database error" + RedisError string = "redis error" ) diff --git a/rpc/internal/logic/block_user_all_token_logic.go b/rpc/internal/logic/block_user_all_token_logic.go index a18a9e00..0a1536ad 100644 --- a/rpc/internal/logic/block_user_all_token_logic.go +++ b/rpc/internal/logic/block_user_all_token_logic.go @@ -38,7 +38,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -55,7 +55,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -63,7 +63,7 @@ func (l *BlockUserAllTokenLogic) BlockUserAllToken(in *core.UUIDReq) (*core.Base for _, v := range tokenData { err := l.svcCtx.Redis.Set("token_"+v.Token, "1") if err != nil { - logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.RedisError) } } diff --git a/rpc/internal/logic/change_password_logic.go b/rpc/internal/logic/change_password_logic.go index f838b8ec..260b1039 100644 --- a/rpc/internal/logic/change_password_logic.go +++ b/rpc/internal/logic/change_password_logic.go @@ -38,7 +38,7 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core. logx.Errorw(err.Error(), logx.Field("uuid", in.Uuid)) return nil, statuserr.NewInvalidArgumentError("login.userNotExist") default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -56,7 +56,7 @@ func (l *ChangePasswordLogic) ChangePassword(in *core.ChangePasswordReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_api_logic.go b/rpc/internal/logic/create_or_update_api_logic.go index 6a54f191..e2326a1f 100644 --- a/rpc/internal/logic/create_or_update_api_logic.go +++ b/rpc/internal/logic/create_or_update_api_logic.go @@ -43,7 +43,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("apis.apiExists") default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -66,7 +66,7 @@ func (l *CreateOrUpdateApiLogic) CreateOrUpdateApi(in *core.ApiInfo) (*core.Base logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_dictionary_detail_logic.go b/rpc/internal/logic/create_or_update_dictionary_detail_logic.go index 1989da7f..1218af7e 100644 --- a/rpc/internal/logic/create_or_update_dictionary_detail_logic.go +++ b/rpc/internal/logic/create_or_update_dictionary_detail_logic.go @@ -32,7 +32,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in exist, err := l.svcCtx.DB.Dictionary.Query().Where(dictionary.IDEQ(in.DictionaryId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -56,7 +56,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -79,7 +79,7 @@ func (l *CreateOrUpdateDictionaryDetailLogic) CreateOrUpdateDictionaryDetail(in logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_dictionary_logic.go b/rpc/internal/logic/create_or_update_dictionary_logic.go index 06cc3d7d..e8ccb77a 100644 --- a/rpc/internal/logic/create_or_update_dictionary_logic.go +++ b/rpc/internal/logic/create_or_update_dictionary_logic.go @@ -42,10 +42,10 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio if err != nil { if ent.IsConstraintError(err) { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) } - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -57,12 +57,12 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio } if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, err.Error()) } if !exist { - logx.Errorw(logmsg.TARGET_NOT_FOUND, logx.Field("id", in.Id)) + logx.Errorw(logmsg.TargetNotFound, logx.Field("id", in.Id)) return nil, status.Error(codes.InvalidArgument, errorx.UpdateFailed) } @@ -74,8 +74,8 @@ func (l *CreateOrUpdateDictionaryLogic) CreateOrUpdateDictionary(in *core.Dictio Exec(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) - return nil, statuserr.NewInvalidArgumentError(logmsg.UPDATE_FAILED) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) + return nil, statuserr.NewInvalidArgumentError(logmsg.UpdateFailed) } return &core.BaseResp{Msg: errorx.UpdateSuccess}, nil diff --git a/rpc/internal/logic/create_or_update_menu_logic.go b/rpc/internal/logic/create_or_update_menu_logic.go index 0eebd6fc..e24eb902 100644 --- a/rpc/internal/logic/create_or_update_menu_logic.go +++ b/rpc/internal/logic/create_or_update_menu_logic.go @@ -42,7 +42,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -89,7 +89,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -98,7 +98,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu } else { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.IDEQ(in.ParentId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, err } @@ -142,7 +142,7 @@ func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(in *core.CreateOrUpdateMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_menu_param_logic.go b/rpc/internal/logic/create_or_update_menu_param_logic.go index 5c0d0ceb..9e6e652d 100644 --- a/rpc/internal/logic/create_or_update_menu_param_logic.go +++ b/rpc/internal/logic/create_or_update_menu_param_logic.go @@ -43,7 +43,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -52,7 +52,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr } else { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.IDEQ(in.MenuId)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -77,7 +77,7 @@ func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(in *core.CreateOr logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_provider_logic.go b/rpc/internal/logic/create_or_update_provider_logic.go index 9ef9f546..e781f500 100644 --- a/rpc/internal/logic/create_or_update_provider_logic.go +++ b/rpc/internal/logic/create_or_update_provider_logic.go @@ -48,7 +48,7 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(in *core.ProviderIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -76,7 +76,7 @@ func (l *CreateOrUpdateProviderLogic) CreateOrUpdateProvider(in *core.ProviderIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_role_logic.go b/rpc/internal/logic/create_or_update_role_logic.go index f4dac645..96f4bcc1 100644 --- a/rpc/internal/logic/create_or_update_role_logic.go +++ b/rpc/internal/logic/create_or_update_role_logic.go @@ -47,7 +47,7 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(in *core.RoleInfo) (*core.B logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("role.duplicateRoleValue") default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -78,7 +78,7 @@ func (l *CreateOrUpdateRoleLogic) CreateOrUpdateRole(in *core.RoleInfo) (*core.B logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("role.duplicateRoleValue") default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -105,7 +105,7 @@ func (l *CreateOrUpdateRoleLogic) UpdateRoleInfoInRedis() error { logx.Error(err.Error()) return statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_token_logic.go b/rpc/internal/logic/create_or_update_token_logic.go index 8987be76..15cb7aa7 100644 --- a/rpc/internal/logic/create_or_update_token_logic.go +++ b/rpc/internal/logic/create_or_update_token_logic.go @@ -45,7 +45,7 @@ func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(in *core.TokenInfo) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -69,7 +69,7 @@ func (l *CreateOrUpdateTokenLogic) CreateOrUpdateToken(in *core.TokenInfo) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/create_or_update_user_logic.go b/rpc/internal/logic/create_or_update_user_logic.go index d4e1d317..d4fa7548 100644 --- a/rpc/internal/logic/create_or_update_user_logic.go +++ b/rpc/internal/logic/create_or_update_user_logic.go @@ -48,7 +48,7 @@ func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(in *core.CreateOrUpdateUser logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.CreateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -86,7 +86,7 @@ func (l *CreateOrUpdateUserLogic) CreateOrUpdateUser(in *core.CreateOrUpdateUser logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_api_logic.go b/rpc/internal/logic/delete_api_logic.go index f6aba651..223ff341 100644 --- a/rpc/internal/logic/delete_api_logic.go +++ b/rpc/internal/logic/delete_api_logic.go @@ -36,7 +36,7 @@ func (l *DeleteApiLogic) DeleteApi(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_dictionary_detail_logic.go b/rpc/internal/logic/delete_dictionary_detail_logic.go index 05593ec6..df061c46 100644 --- a/rpc/internal/logic/delete_dictionary_detail_logic.go +++ b/rpc/internal/logic/delete_dictionary_detail_logic.go @@ -36,7 +36,7 @@ func (l *DeleteDictionaryDetailLogic) DeleteDictionaryDetail(in *core.IDReq) (*c logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_menu_logic.go b/rpc/internal/logic/delete_menu_logic.go index aa57369a..710c2b08 100644 --- a/rpc/internal/logic/delete_menu_logic.go +++ b/rpc/internal/logic/delete_menu_logic.go @@ -32,7 +32,7 @@ func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { exist, err := l.svcCtx.DB.Menu.Query().Where(menu.ParentID(in.Id)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -46,7 +46,7 @@ func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { err = l.svcCtx.DB.Menu.Update().ClearParams().Exec(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } @@ -58,7 +58,7 @@ func (l *DeleteMenuLogic) DeleteMenu(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_menu_param_logic.go b/rpc/internal/logic/delete_menu_param_logic.go index ad39b13b..3bc6ef0b 100644 --- a/rpc/internal/logic/delete_menu_param_logic.go +++ b/rpc/internal/logic/delete_menu_param_logic.go @@ -36,7 +36,7 @@ func (l *DeleteMenuParamLogic) DeleteMenuParam(in *core.IDReq) (*core.BaseResp, logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_provider_logic.go b/rpc/internal/logic/delete_provider_logic.go index 292a348a..02355569 100644 --- a/rpc/internal/logic/delete_provider_logic.go +++ b/rpc/internal/logic/delete_provider_logic.go @@ -36,7 +36,7 @@ func (l *DeleteProviderLogic) DeleteProvider(in *core.IDReq) (*core.BaseResp, er logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_role_logic.go b/rpc/internal/logic/delete_role_logic.go index 6b7b1af2..d8099361 100644 --- a/rpc/internal/logic/delete_role_logic.go +++ b/rpc/internal/logic/delete_role_logic.go @@ -31,7 +31,7 @@ func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete func (l *DeleteRoleLogic) DeleteRole(in *core.IDReq) (*core.BaseResp, error) { exist, err := l.svcCtx.DB.User.Query().Where(user.RoleIDEQ(in.Id)).Exist(l.ctx) if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } @@ -49,7 +49,7 @@ func (l *DeleteRoleLogic) DeleteRole(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_token_logic.go b/rpc/internal/logic/delete_token_logic.go index 0dd8fa00..d89fca60 100644 --- a/rpc/internal/logic/delete_token_logic.go +++ b/rpc/internal/logic/delete_token_logic.go @@ -36,7 +36,7 @@ func (l *DeleteTokenLogic) DeleteToken(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/delete_user_logic.go b/rpc/internal/logic/delete_user_logic.go index 1b3442f4..fddae88b 100644 --- a/rpc/internal/logic/delete_user_logic.go +++ b/rpc/internal/logic/delete_user_logic.go @@ -36,7 +36,7 @@ func (l *DeleteUserLogic) DeleteUser(in *core.IDReq) (*core.BaseResp, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_detail_by_dictionary_name_logic.go b/rpc/internal/logic/get_detail_by_dictionary_name_logic.go index ccbce168..e38e09f4 100644 --- a/rpc/internal/logic/get_detail_by_dictionary_name_logic.go +++ b/rpc/internal/logic/get_detail_by_dictionary_name_logic.go @@ -40,7 +40,7 @@ func (l *GetDetailByDictionaryNameLogic) GetDetailByDictionaryName(in *core.Dict logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_authority_logic.go b/rpc/internal/logic/get_menu_authority_logic.go index 4b75fcf2..1f69daf9 100644 --- a/rpc/internal/logic/get_menu_authority_logic.go +++ b/rpc/internal/logic/get_menu_authority_logic.go @@ -38,7 +38,7 @@ func (l *GetMenuAuthorityLogic) GetMenuAuthority(in *core.IDReq) (*core.RoleMenu logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_list_by_role_logic.go b/rpc/internal/logic/get_menu_list_by_role_logic.go index cd4efaa5..1af74e03 100644 --- a/rpc/internal/logic/get_menu_list_by_role_logic.go +++ b/rpc/internal/logic/get_menu_list_by_role_logic.go @@ -39,7 +39,7 @@ func (l *GetMenuListByRoleLogic) GetMenuListByRole(in *core.IDReq) (*core.MenuIn logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go b/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go index 8825bc4f..cdeaf17c 100644 --- a/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go +++ b/rpc/internal/logic/get_menu_param_list_by_menu_id_logic.go @@ -37,7 +37,7 @@ func (l *GetMenuParamListByMenuIdLogic) GetMenuParamListByMenuId(in *core.IDReq) logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_role_by_id_logic.go b/rpc/internal/logic/get_role_by_id_logic.go index fc570465..eafbd183 100644 --- a/rpc/internal/logic/get_role_by_id_logic.go +++ b/rpc/internal/logic/get_role_by_id_logic.go @@ -36,7 +36,7 @@ func (l *GetRoleByIdLogic) GetRoleById(in *core.IDReq) (*core.RoleInfo, error) { logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_token_list_logic.go b/rpc/internal/logic/get_token_list_logic.go index f7a13700..e9b1c8b5 100644 --- a/rpc/internal/logic/get_token_list_logic.go +++ b/rpc/internal/logic/get_token_list_logic.go @@ -67,7 +67,7 @@ func (l *GetTokenListLogic) GetTokenList(in *core.TokenListReq) (*core.TokenList logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/get_user_by_id_logic.go b/rpc/internal/logic/get_user_by_id_logic.go index 6552795a..6ac9fcfc 100644 --- a/rpc/internal/logic/get_user_by_id_logic.go +++ b/rpc/internal/logic/get_user_by_id_logic.go @@ -38,7 +38,7 @@ func (l *GetUserByIdLogic) GetUserById(in *core.UUIDReq) (*core.UserInfoResp, er logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/init_database_logic.go b/rpc/internal/logic/init_database_logic.go index 034b18cc..7c6911a7 100644 --- a/rpc/internal/logic/init_database_logic.go +++ b/rpc/internal/logic/init_database_logic.go @@ -49,7 +49,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) logx.Error("last initialization is running") return nil, statuserr.NewInternalError(errorx.InitRunning) } else { - logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.RedisError) } } @@ -62,7 +62,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) check, err := l.svcCtx.DB.API.Query().Count(l.ctx) //if err != nil { - // logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + // logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) // l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) // return nil, status.Error(codes.Internal, err.Error()) //} @@ -70,7 +70,7 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) if check != 0 { err := l.svcCtx.Redis.Set("database_init_state", "1") if err != nil { - logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, errorx.RedisError) } return &core.BaseResp{Msg: errorx.AlreadyInit}, nil @@ -82,51 +82,51 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) // initialize table structure if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false)); err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertUserData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertRoleData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertMenuData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertApiData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertRoleMenuAuthorityData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertCasbinPoliciesData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } err = l.insertProviderData() if err != nil { - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) return nil, status.Error(codes.Internal, err.Error()) } diff --git a/rpc/internal/logic/login_logic.go b/rpc/internal/logic/login_logic.go index 4e3cb01e..59d1c5ad 100644 --- a/rpc/internal/logic/login_logic.go +++ b/rpc/internal/logic/login_logic.go @@ -42,7 +42,7 @@ func (l *LoginLogic) Login(in *core.LoginReq) (*core.LoginResp, error) { logx.Errorw("user not found", logx.Field("username", in.Username)) return nil, status.Error(codes.InvalidArgument, "login.userNotExist") } - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, status.Error(codes.Internal, errorx.DatabaseError) } @@ -73,7 +73,7 @@ func getRoleInfo(roleId uint64, rds *redis.Redis, db *ent.Client, ctx context.Co logx.Error("fail to find any roles") return "", "", status.Error(codes.NotFound, errorx.TargetNotFound) } - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return "", "", status.Error(codes.NotFound, errorx.TargetNotFound) } @@ -82,7 +82,7 @@ func getRoleInfo(roleId uint64, rds *redis.Redis, db *ent.Client, ctx context.Co err = rds.Hset("roleData", fmt.Sprintf("%d_value", v.ID), v.Value) err = rds.Hset("roleData", fmt.Sprintf("%d_status", v.ID), strconv.Itoa(int(v.Status))) if err != nil { - logx.Errorw(logmsg.REDIS_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) return "", "", statuserr.NewInternalError(errorx.RedisError) } if v.ID == roleId { diff --git a/rpc/internal/logic/oauth_callback_logic.go b/rpc/internal/logic/oauth_callback_logic.go index 8b865d87..4f0a8e9b 100644 --- a/rpc/internal/logic/oauth_callback_logic.go +++ b/rpc/internal/logic/oauth_callback_logic.go @@ -54,7 +54,7 @@ func (l *OauthCallbackLogic) OauthCallback(in *core.CallbackReq) (*core.LoginRes logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } @@ -97,7 +97,7 @@ func (l *OauthCallbackLogic) OauthCallback(in *core.CallbackReq) (*core.LoginRes logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError("login.userNotExist") default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/oauth_login_logic.go b/rpc/internal/logic/oauth_login_logic.go index d28f18f3..10ca48e1 100644 --- a/rpc/internal/logic/oauth_login_logic.go +++ b/rpc/internal/logic/oauth_login_logic.go @@ -44,7 +44,7 @@ func (l *OauthLoginLogic) OauthLogin(in *core.OauthLoginReq) (*core.OauthRedirec logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_profile_logic.go b/rpc/internal/logic/update_profile_logic.go index a6fb834e..f25cc05f 100644 --- a/rpc/internal/logic/update_profile_logic.go +++ b/rpc/internal/logic/update_profile_logic.go @@ -60,7 +60,7 @@ func (l *UpdateProfileLogic) UpdateProfile(in *core.UpdateProfileReq) (*core.Bas logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.UpdateFailed) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_role_status_logic.go b/rpc/internal/logic/update_role_status_logic.go index e9581f5d..8334a144 100644 --- a/rpc/internal/logic/update_role_status_logic.go +++ b/rpc/internal/logic/update_role_status_logic.go @@ -38,7 +38,7 @@ func (l *UpdateRoleStatusLogic) UpdateRoleStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_token_status_logic.go b/rpc/internal/logic/update_token_status_logic.go index 16acda10..06d9a742 100644 --- a/rpc/internal/logic/update_token_status_logic.go +++ b/rpc/internal/logic/update_token_status_logic.go @@ -38,7 +38,7 @@ func (l *UpdateTokenStatusLogic) UpdateTokenStatus(in *core.StatusCodeReq) (*cor logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } diff --git a/rpc/internal/logic/update_user_status_logic.go b/rpc/internal/logic/update_user_status_logic.go index 06df310b..b9f74f55 100644 --- a/rpc/internal/logic/update_user_status_logic.go +++ b/rpc/internal/logic/update_user_status_logic.go @@ -36,7 +36,7 @@ func (l *UpdateUserStatusLogic) UpdateUserStatus(in *core.StatusCodeReq) (*core. logx.Errorw(err.Error(), logx.Field("detail", in)) return nil, statuserr.NewInvalidArgumentError(errorx.TargetNotFound) default: - logx.Errorw(logmsg.DATABASE_ERROR, logx.Field("detail", err.Error())) + logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) return nil, statuserr.NewInternalError(errorx.DatabaseError) } } From ab9dca3175a793af1301985801cd170050473eb1 Mon Sep 17 00:00:00 2001 From: Ryan SU <1137661202@qq.com> Date: Sun, 13 Nov 2022 09:41:42 +0800 Subject: [PATCH 3/5] refactor: response data --- api/desc/oauth.api | 10 +++++++- api/desc/role.api | 2 +- .../logic/oauth/get_provider_list_logic.go | 6 +++-- api/internal/types/types.go | 12 ++++++++-- core.yml | 23 +++++++++++++++++-- pkg/ent/schema/dictionary.go | 2 +- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/api/desc/oauth.api b/api/desc/oauth.api index 66df0e93..38addc2d 100644 --- a/api/desc/oauth.api +++ b/api/desc/oauth.api @@ -99,8 +99,16 @@ type ( InfoURL string `json:"infoURL" validate:"max=200"` } - // The response data of provider list | 提供商列表数据 + // The response data of provider list | 提供商列表返回数据 ProviderListResp { + BaseDataInfo + + // The provider list data | 提供商列表数据 + Data ProviderListInfo `json:"data"` + } + + // The data of provider list | 提供商列表数据 + ProviderListInfo { BaseListInfo // The provider list data | 提供商列表数据 diff --git a/api/desc/role.api b/api/desc/role.api index a182a7c2..d321f9ca 100644 --- a/api/desc/role.api +++ b/api/desc/role.api @@ -41,7 +41,7 @@ type ( // Role remark | 角色备注 // Required : true // Max length: 200 - Remark string `json:"remark" validate:"omitempty,max=200"` + Remark string `json:"remark,optional" validate:"omitempty,max=200"` // Role's sorting number | 角色排序 // Required : true diff --git a/api/internal/logic/oauth/get_provider_list_logic.go b/api/internal/logic/oauth/get_provider_list_logic.go index ebd5c337..d3b912ca 100644 --- a/api/internal/logic/oauth/get_provider_list_logic.go +++ b/api/internal/logic/oauth/get_provider_list_logic.go @@ -6,6 +6,7 @@ import ( "github.com/suyuan32/simple-admin-core/api/internal/svc" "github.com/suyuan32/simple-admin-core/api/internal/types" + "github.com/suyuan32/simple-admin-core/pkg/i18n" "github.com/suyuan32/simple-admin-core/rpc/types/core" "github.com/zeromicro/go-zero/core/logx" @@ -37,9 +38,10 @@ func (l *GetProviderListLogic) GetProviderList(req *types.PageInfo) (resp *types return nil, err } resp = &types.ProviderListResp{} - resp.Total = data.GetTotal() + resp.Msg = l.svcCtx.Trans.Trans(l.lang, i18n.Success) + resp.Data.Total = data.GetTotal() for _, v := range data.Data { - resp.Data = append(resp.Data, + resp.Data.Data = append(resp.Data.Data, types.ProviderInfo{ BaseInfo: types.BaseInfo{ Id: v.Id, diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 02e19914..69d2a59d 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -26,7 +26,7 @@ type RoleInfo struct { // Role remark | 角色备注 // Required : true // Max length: 200 - Remark string `json:"remark" validate:"omitempty,max=200"` + Remark string `json:"remark,optional" validate:"omitempty,max=200"` // Role's sorting number | 角色排序 // Required : true // Maximum: 1000 @@ -1011,9 +1011,17 @@ type CreateOrUpdateProviderReq struct { InfoURL string `json:"infoURL" validate:"max=200"` } -// The response data of provider list | 提供商列表数据 +// The response data of provider list | 提供商列表返回数据 // swagger:model ProviderListResp type ProviderListResp struct { + BaseDataInfo + // The provider list data | 提供商列表数据 + Data ProviderListInfo `json:"data"` +} + +// The data of provider list | 提供商列表数据 +// swagger:model ProviderListInfo +type ProviderListInfo struct { BaseListInfo // The provider list data | 提供商列表数据 Data []ProviderInfo `json:"data"` diff --git a/core.yml b/core.yml index 783aad22..ead87333 100644 --- a/core.yml +++ b/core.yml @@ -1747,8 +1747,8 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - ProviderListResp: - description: The response data of provider list | 提供商列表数据 + ProviderListInfo: + description: The data of provider list | 提供商列表数据 properties: data: description: The provider list data | 提供商列表数据 @@ -1763,6 +1763,25 @@ definitions: x-go-name: Total type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProviderListResp: + description: The response data of provider list | 提供商列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/ProviderListInfo' + description: Data | 数据 + type: string + x-go-name: Data + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types RedirectInfo: description: Redirect information | 跳转网址 properties: diff --git a/pkg/ent/schema/dictionary.go b/pkg/ent/schema/dictionary.go index de8f0b7c..258e0ee7 100644 --- a/pkg/ent/schema/dictionary.go +++ b/pkg/ent/schema/dictionary.go @@ -17,7 +17,7 @@ type Dictionary struct { func (Dictionary) Fields() []ent.Field { return []ent.Field{ field.String("title").Comment("the title shown in the ui | 展示名称 (建议配合i18n)"), - field.String("name").Comment("the name of dictionary for search | 字典搜索名称"), + field.String("name").Unique().Comment("the name of dictionary for search | 字典搜索名称"), field.String("desc").Comment("the status of dictionary (true enable | false disable) | 字典状态"), } } From 617a4556bd607aa95f68176a0c72a2226fd94ad3 Mon Sep 17 00:00:00 2001 From: Ryan SU <1137661202@qq.com> Date: Sun, 13 Nov 2022 12:08:00 +0800 Subject: [PATCH 4/5] refactor: response data --- api/desc/user.api | 2 +- .../logic/core/init_database_logic.go | 4 ++-- .../logic/user/update_user_profile_logic.go | 2 +- .../logic/user/update_user_status_logic.go | 2 +- api/internal/types/types.go | 2 +- go.sum | 5 ++++ pkg/ent/migrate/schema.go | 9 ++++++- pkg/ent/schema/api.go | 8 +++++++ pkg/i18n/translator.go | 7 +++--- rpc/internal/logic/init_database_logic.go | 24 +++++++++---------- 10 files changed, 42 insertions(+), 23 deletions(-) diff --git a/api/desc/user.api b/api/desc/user.api index cdca8724..c6098cde 100644 --- a/api/desc/user.api +++ b/api/desc/user.api @@ -271,7 +271,7 @@ type ( // User's mobile phone number | 用户的手机号码 // Required: true // Max length: 18 - Mobile string `json:"mobile" validate:"numeric,max=18"` + Mobile string `json:"mobile,optional" validate:"numeric,max=18"` // User's role id | 用户的角色ID // Required: true diff --git a/api/internal/logic/core/init_database_logic.go b/api/internal/logic/core/init_database_logic.go index baf52b8e..2dfab29d 100644 --- a/api/internal/logic/core/init_database_logic.go +++ b/api/internal/logic/core/init_database_logic.go @@ -42,7 +42,7 @@ func (l *InitDatabaseLogic) InitDatabase() (resp *types.BaseMsgResp, err error) } else if errors.Is(err, status.Error(codes.DeadlineExceeded, "context deadline exceeded")) { for { // wait 10 second for initialization - time.Sleep(time.Second * 10) + time.Sleep(time.Second * 5) if initState, err := l.svcCtx.Redis.Get("database_init_state"); err == nil { if initState == "1" { return nil, errorx.NewCodeError(enum.InvalidArgument, @@ -63,5 +63,5 @@ func (l *InitDatabaseLogic) InitDatabase() (resp *types.BaseMsgResp, err error) } } } - return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, l.svcCtx.Trans.Trans(l.lang, result.Msg))}, nil } diff --git a/api/internal/logic/user/update_user_profile_logic.go b/api/internal/logic/user/update_user_profile_logic.go index 50effeae..0f70f09e 100644 --- a/api/internal/logic/user/update_user_profile_logic.go +++ b/api/internal/logic/user/update_user_profile_logic.go @@ -40,5 +40,5 @@ func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.ProfileReq) (resp return nil, err } - return &types.BaseMsgResp{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/logic/user/update_user_status_logic.go b/api/internal/logic/user/update_user_status_logic.go index c801081a..e7a35ef6 100644 --- a/api/internal/logic/user/update_user_status_logic.go +++ b/api/internal/logic/user/update_user_status_logic.go @@ -37,5 +37,5 @@ func (l *UpdateUserStatusLogic) UpdateUserStatus(req *types.StatusCodeReq) (resp return nil, err } - return &types.BaseMsgResp{Msg: result.Msg}, nil + return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 69d2a59d..db734b1b 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -386,7 +386,7 @@ type CreateOrUpdateUserReq struct { // User's mobile phone number | 用户的手机号码 // Required: true // Max length: 18 - Mobile string `json:"mobile" validate:"numeric,max=18"` + Mobile string `json:"mobile,optional" validate:"numeric,max=18"` // User's role id | 用户的角色ID // Required: true // Maximum: 1000 diff --git a/go.sum b/go.sum index b16ff2ac..323acc09 100644 --- a/go.sum +++ b/go.sum @@ -609,6 +609,7 @@ github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peK github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= @@ -673,6 +674,7 @@ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtb github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -779,6 +781,7 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= @@ -833,6 +836,7 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -1285,6 +1289,7 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts= golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/ent/migrate/schema.go b/pkg/ent/migrate/schema.go index 8ef6938c..4ee9b823 100644 --- a/pkg/ent/migrate/schema.go +++ b/pkg/ent/migrate/schema.go @@ -24,6 +24,13 @@ var ( Name: "sys_apis", Columns: SysApisColumns, PrimaryKey: []*schema.Column{SysApisColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "api_path_method", + Unique: true, + Columns: []*schema.Column{SysApisColumns[3], SysApisColumns[6]}, + }, + }, } // SysDictionariesColumns holds the columns for the "sys_dictionaries" table. SysDictionariesColumns = []*schema.Column{ @@ -32,7 +39,7 @@ var ( {Name: "updated_at", Type: field.TypeTime}, {Name: "status", Type: field.TypeUint8, Nullable: true, Default: 1}, {Name: "title", Type: field.TypeString}, - {Name: "name", Type: field.TypeString}, + {Name: "name", Type: field.TypeString, Unique: true}, {Name: "desc", Type: field.TypeString}, } // SysDictionariesTable holds the schema information for the "sys_dictionaries" table. diff --git a/pkg/ent/schema/api.go b/pkg/ent/schema/api.go index f0deff68..deb95f18 100644 --- a/pkg/ent/schema/api.go +++ b/pkg/ent/schema/api.go @@ -5,6 +5,7 @@ import ( "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" "github.com/suyuan32/simple-admin-core/pkg/ent/schema/mixins" ) @@ -32,6 +33,13 @@ func (API) Edges() []ent.Edge { return nil } +func (API) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("path", "method"). + Unique(), + } +} + func (API) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{Table: "sys_apis"}, diff --git a/pkg/i18n/translator.go b/pkg/i18n/translator.go index 529123a9..64ff8ae2 100644 --- a/pkg/i18n/translator.go +++ b/pkg/i18n/translator.go @@ -10,6 +10,7 @@ import ( "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" "golang.org/x/text/language" + "google.golang.org/grpc/status" "github.com/suyuan32/simple-admin-core/pkg/utils" "github.com/suyuan32/simple-admin-core/pkg/utils/errcode" @@ -59,13 +60,13 @@ func (l *Translator) Trans(lang string, msgId string) string { func (l *Translator) TransError(lang string, err error) error { if errcode.IsGrpcError(err) { message, e := l.MatchLocalizer(lang).LocalizeMessage(&i18n.Message{ID: strings.Split(err.Error(), "desc = ")[1]}) - if e != nil { + if e != nil || message == "" { message = err.Error() } - return errorx.NewApiError(errcode.CodeFromGrpcError(err), message) + return status.Error(status.Code(err), message) } else if codeErr, ok := err.(*errorx.CodeError); ok { message, e := l.MatchLocalizer(lang).LocalizeMessage(&i18n.Message{ID: codeErr.Error()}) - if e != nil { + if e != nil || message == "" { message = codeErr.Error() } return errorx.NewCodeError(codeErr.Code, message) diff --git a/rpc/internal/logic/init_database_logic.go b/rpc/internal/logic/init_database_logic.go index 7c6911a7..79a680bb 100644 --- a/rpc/internal/logic/init_database_logic.go +++ b/rpc/internal/logic/init_database_logic.go @@ -16,8 +16,6 @@ import ( "github.com/zeromicro/go-zero/core/errorx" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stores/redis" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) type InitDatabaseLogic struct { @@ -71,67 +69,67 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error) err := l.svcCtx.Redis.Set("database_init_state", "1") if err != nil { logx.Errorw(logmsg.RedisError, logx.Field("detail", err.Error())) - return nil, status.Error(codes.Internal, errorx.RedisError) + return nil, statuserr.NewInternalError(errorx.RedisError) } return &core.BaseResp{Msg: errorx.AlreadyInit}, nil } // set default state value l.svcCtx.Redis.Setex("database_error_msg", "", 300) - l.svcCtx.Redis.Set("database_init_state", "0") + l.svcCtx.Redis.Setex("database_init_state", "0", 300) // initialize table structure if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false)); err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertUserData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertRoleData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertMenuData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertApiData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertRoleMenuAuthorityData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertCasbinPoliciesData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } err = l.insertProviderData() if err != nil { logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error())) l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300) - return nil, status.Error(codes.Internal, err.Error()) + return nil, statuserr.NewInternalError(err.Error()) } - l.svcCtx.Redis.Set("database_init_state", "1") + l.svcCtx.Redis.Setex("database_init_state", "1", 300) return &core.BaseResp{Msg: errorx.Success}, nil } From 205dace208e19c3c67ab837d24317ddfe1e95065 Mon Sep 17 00:00:00 2001 From: Ryan SU <1137661202@qq.com> Date: Sun, 13 Nov 2022 12:34:32 +0800 Subject: [PATCH 5/5] docs: update error_handling.md --- docs/simple-admin/en/docs/error_handling.md | 252 +++++++++++++++++- .../en/docs/web_develop_example.md | 3 +- .../simple-admin/zh-cn/docs/error_handling.md | 251 ++++++++++++++++- go.mod | 4 +- go.sum | 9 +- 5 files changed, 503 insertions(+), 16 deletions(-) diff --git a/docs/simple-admin/en/docs/error_handling.md b/docs/simple-admin/en/docs/error_handling.md index 2db5e03b..d1890937 100644 --- a/docs/simple-admin/en/docs/error_handling.md +++ b/docs/simple-admin/en/docs/error_handling.md @@ -8,12 +8,258 @@ status.Error(codes.Internal, result.Error.Error()) Just return status.Error -> Notice: codes.InvalidArgument will convert into http.http.StatusBadRequest in api service -> It will create prompt, you can control it by api ErrorMessageMode. + +> Easy way + +```text +statuserr.NewInternalError(msg) + +statuserr.NewInvalidArgumentError(msg) + +statuserr.NewNotFoundError(msg) + +statuserr.NewAlreadyExistsError(msg) + +statuserr.NewUnauthenticatedError +``` + > API Error +Use CodeError to return error in API layer. ```go -errorx.NewApiError(http.StatusUnauthorized, "Please log in") +errorx.CodeError(enum.InvalidArgument, "Please log in") +``` + +> Error code + +All error codes are in pkg/enum/errorcode. The first 17 error codes are the same as grpc, you can also add your own error code. + +```go +package enum + +const ( + // OK is returned on success. + OK int = 0 + + // Canceled indicates the operation was canceled (typically by the caller). + // + // The gRPC framework will generate this error code when cancellation + // is requested. + Canceled int = 1 + + // Unknown error. An example of where this error may be returned is + // if a Status value received from another address space belongs to + // an error-space that is not known in this address space. Also + // errors raised by APIs that do not return enough error information + // may be converted to this error. + // + // The gRPC framework will generate this error code in the above two + // mentioned cases. + Unknown int = 2 + + // InvalidArgument indicates client specified an invalid argument. + // Note that this differs from FailedPrecondition. It indicates arguments + // that are problematic regardless of the state of the system + // (e.g., a malformed file name). + // + // This error code will not be generated by the gRPC framework. + InvalidArgument int = 3 + + // DeadlineExceeded means operation expired before completion. + // For operations that change the state of the system, this error may be + // returned even if the operation has completed successfully. For + // example, a successful response from a server could have been delayed + // long enough for the deadline to expire. + // + // The gRPC framework will generate this error code when the deadline is + // exceeded. + DeadlineExceeded int = 4 + + // NotFound means some requested entity (e.g., file or directory) was + // not found. + // + // This error code will not be generated by the gRPC framework. + NotFound int = 5 + + // AlreadyExists means an attempt to create an entity failed because one + // already exists. + // + // This error code will not be generated by the gRPC framework. + AlreadyExists int = 6 + + // PermissionDenied indicates the caller does not have permission to + // execute the specified operation. It must not be used for rejections + // caused by exhausting some resource (use ResourceExhausted + // instead for those errors). It must not be + // used if the caller cannot be identified (use Unauthenticated + // instead for those errors). + // + // This error code will not be generated by the gRPC core framework, + // but expect authentication middleware to use it. + PermissionDenied int = 7 + + // ResourceExhausted indicates some resource has been exhausted, perhaps + // a per-user quota, or perhaps the entire file system is out of space. + // + // This error code will be generated by the gRPC framework in + // out-of-memory and server overload situations, or when a message is + // larger than the configured maximum size. + ResourceExhausted int = 8 + + // FailedPrecondition indicates operation was rejected because the + // system is not in a state required for the operation's execution. + // For example, directory to be deleted may be non-empty, an rmdir + // operation is applied to a non-directory, etc. + // + // A litmus test that may help a service implementor in deciding + // between FailedPrecondition, Aborted, and Unavailable: + // (a) Use Unavailable if the client can retry just the failing call. + // (b) Use Aborted if the client should retry at a higher-level + // (e.g., restarting a read-modify-write sequence). + // (c) Use FailedPrecondition if the client should not retry until + // the system state has been explicitly fixed. E.g., if an "rmdir" + // fails because the directory is non-empty, FailedPrecondition + // should be returned since the client should not retry unless + // they have first fixed up the directory by deleting files from it. + // (d) Use FailedPrecondition if the client performs conditional + // REST Get/Update/Delete on a resource and the resource on the + // server does not match the condition. E.g., conflicting + // read-modify-write on the same resource. + // + // This error code will not be generated by the gRPC framework. + FailedPrecondition int = 9 + + // Aborted indicates the operation was aborted, typically due to a + // concurrency issue like sequencer check failures, transaction aborts, + // etc. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will not be generated by the gRPC framework. + Aborted int = 10 + + // OutOfRange means operation was attempted past the valid range. + // E.g., seeking or reading past end of file. + // + // Unlike InvalidArgument, this error indicates a problem that may + // be fixed if the system state changes. For example, a 32-bit file + // system will generate InvalidArgument if asked to read at an + // offset that is not in the range [0,2^32-1], but it will generate + // OutOfRange if asked to read from an offset past the current + // file size. + // + // There is a fair bit of overlap between FailedPrecondition and + // OutOfRange. We recommend using OutOfRange (the more specific + // error) when it applies so that callers who are iterating through + // a space can easily look for an OutOfRange error to detect when + // they are done. + // + // This error code will not be generated by the gRPC framework. + OutOfRange int = 11 + + // Unimplemented indicates operation is not implemented or not + // supported/enabled in this service. + // + // This error code will be generated by the gRPC framework. Most + // commonly, you will see this error code when a method implementation + // is missing on the server. It can also be generated for unknown + // compression algorithms or a disagreement as to whether an RPC should + // be streaming. + Unimplemented int = 12 + + // Internal errors. Means some invariants expected by underlying + // system has been broken. If you see one of these errors, + // something is very broken. + // + // This error code will be generated by the gRPC framework in several + // internal error conditions. + Internal int = 13 + + // Unavailable indicates the service is currently unavailable. + // This is a most likely a transient condition and may be corrected + // by retrying with a backoff. Note that it is not always safe to retry + // non-idempotent operations. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will be generated by the gRPC framework during + // abrupt shutdown of a server process or network connection. + Unavailable int = 14 + + // DataLoss indicates unrecoverable data loss or corruption. + // + // This error code will not be generated by the gRPC framework. + DataLoss int = 15 + + // Unauthenticated indicates the request does not have valid + // authentication credentials for the operation. + // + // The gRPC framework will generate this error code when the + // authentication metadata is invalid or a Credentials callback fails, + // but also expect authentication middleware to generate it. + Unauthenticated int = 16 +) + +``` + +> Note: the code which is not 0 will show message in front-end, front-end control it via api ErrorMessageMode. + +> If you add the tag --transErr=true to generate Api files, it will add translation in handler. + +```shell +goctls api go --api ./api/desc/core.api --dir ./api --transErr=true +``` + +```go +package api + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + + "github.com/suyuan32/simple-admin-core/api/internal/logic/api" + "github.com/suyuan32/simple-admin-core/api/internal/svc" + "github.com/suyuan32/simple-admin-core/api/internal/types" +) + +// swagger:route post /api api CreateOrUpdateApi +// +// Create or update API information | 创建或更新API +// +// Create or update API information | 创建或更新API +// +// Parameters: +// + name: body +// require: true +// in: body +// type: CreateOrUpdateApiReq +// +// Responses: +// 200: BaseMsgResp + +func CreateOrUpdateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateOrUpdateApiReq + if err := httpx.Parse(r, &req); err != nil { + httpx.Error(w, err) + return + } + + l := api.NewCreateOrUpdateApiLogic(r, svcCtx) + resp, err := l.CreateOrUpdateApi(&req) + if err != nil { + err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) + httpx.Error(w, err) + } else { + httpx.OkJson(w, resp) + } + } +} + ``` +err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) \ No newline at end of file diff --git a/docs/simple-admin/en/docs/web_develop_example.md b/docs/simple-admin/en/docs/web_develop_example.md index 081841cf..4425b0db 100644 --- a/docs/simple-admin/en/docs/web_develop_example.md +++ b/docs/simple-admin/en/docs/web_develop_example.md @@ -79,8 +79,7 @@ export const Hello = (params: HelloReq, mode: ErrorMessageMode = 'modal') => { async function SayHello() { const result = await Hello({ name: name.value }, 'message'); - resp.value = 'Hello ' + result.msg; - console.log(result); + if (result.code === 0) resp.value = 'Hello ' + result.msg; } ``` diff --git a/docs/simple-admin/zh-cn/docs/error_handling.md b/docs/simple-admin/zh-cn/docs/error_handling.md index 085f9152..b8fadfc3 100644 --- a/docs/simple-admin/zh-cn/docs/error_handling.md +++ b/docs/simple-admin/zh-cn/docs/error_handling.md @@ -8,10 +8,257 @@ status.Error(codes.Internal, result.Error.Error()) 直接 return status.Error -> 注意: codes.InvalidArgument 会转化为前端 http.http.StatusBadRequest , 会产生弹窗, 通过 api ErrorMessageMode 控制 +> 简便方法 + +```text +statuserr.NewInternalError(msg) + +statuserr.NewInvalidArgumentError(msg) + +statuserr.NewNotFoundError(msg) + +statuserr.NewAlreadyExistsError(msg) + +statuserr.NewUnauthenticatedError +``` + > API 错误 +使用 CodeError 返回 API 层的错误, ```go -errorx.NewApiError(http.StatusUnauthorized, "Please log in") +errorx.CodeError(enum.InvalidArgument, "Please log in") ``` + +> 错误码 + +所有的错误码都放在 pkg/enum/errorcode 中, 默认前 17 个错误码与 grpc保持一致, 你也可以自己添加错误码 + +```go +package enum + +const ( + // OK is returned on success. + OK int = 0 + + // Canceled indicates the operation was canceled (typically by the caller). + // + // The gRPC framework will generate this error code when cancellation + // is requested. + Canceled int = 1 + + // Unknown error. An example of where this error may be returned is + // if a Status value received from another address space belongs to + // an error-space that is not known in this address space. Also + // errors raised by APIs that do not return enough error information + // may be converted to this error. + // + // The gRPC framework will generate this error code in the above two + // mentioned cases. + Unknown int = 2 + + // InvalidArgument indicates client specified an invalid argument. + // Note that this differs from FailedPrecondition. It indicates arguments + // that are problematic regardless of the state of the system + // (e.g., a malformed file name). + // + // This error code will not be generated by the gRPC framework. + InvalidArgument int = 3 + + // DeadlineExceeded means operation expired before completion. + // For operations that change the state of the system, this error may be + // returned even if the operation has completed successfully. For + // example, a successful response from a server could have been delayed + // long enough for the deadline to expire. + // + // The gRPC framework will generate this error code when the deadline is + // exceeded. + DeadlineExceeded int = 4 + + // NotFound means some requested entity (e.g., file or directory) was + // not found. + // + // This error code will not be generated by the gRPC framework. + NotFound int = 5 + + // AlreadyExists means an attempt to create an entity failed because one + // already exists. + // + // This error code will not be generated by the gRPC framework. + AlreadyExists int = 6 + + // PermissionDenied indicates the caller does not have permission to + // execute the specified operation. It must not be used for rejections + // caused by exhausting some resource (use ResourceExhausted + // instead for those errors). It must not be + // used if the caller cannot be identified (use Unauthenticated + // instead for those errors). + // + // This error code will not be generated by the gRPC core framework, + // but expect authentication middleware to use it. + PermissionDenied int = 7 + + // ResourceExhausted indicates some resource has been exhausted, perhaps + // a per-user quota, or perhaps the entire file system is out of space. + // + // This error code will be generated by the gRPC framework in + // out-of-memory and server overload situations, or when a message is + // larger than the configured maximum size. + ResourceExhausted int = 8 + + // FailedPrecondition indicates operation was rejected because the + // system is not in a state required for the operation's execution. + // For example, directory to be deleted may be non-empty, an rmdir + // operation is applied to a non-directory, etc. + // + // A litmus test that may help a service implementor in deciding + // between FailedPrecondition, Aborted, and Unavailable: + // (a) Use Unavailable if the client can retry just the failing call. + // (b) Use Aborted if the client should retry at a higher-level + // (e.g., restarting a read-modify-write sequence). + // (c) Use FailedPrecondition if the client should not retry until + // the system state has been explicitly fixed. E.g., if an "rmdir" + // fails because the directory is non-empty, FailedPrecondition + // should be returned since the client should not retry unless + // they have first fixed up the directory by deleting files from it. + // (d) Use FailedPrecondition if the client performs conditional + // REST Get/Update/Delete on a resource and the resource on the + // server does not match the condition. E.g., conflicting + // read-modify-write on the same resource. + // + // This error code will not be generated by the gRPC framework. + FailedPrecondition int = 9 + + // Aborted indicates the operation was aborted, typically due to a + // concurrency issue like sequencer check failures, transaction aborts, + // etc. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will not be generated by the gRPC framework. + Aborted int = 10 + + // OutOfRange means operation was attempted past the valid range. + // E.g., seeking or reading past end of file. + // + // Unlike InvalidArgument, this error indicates a problem that may + // be fixed if the system state changes. For example, a 32-bit file + // system will generate InvalidArgument if asked to read at an + // offset that is not in the range [0,2^32-1], but it will generate + // OutOfRange if asked to read from an offset past the current + // file size. + // + // There is a fair bit of overlap between FailedPrecondition and + // OutOfRange. We recommend using OutOfRange (the more specific + // error) when it applies so that callers who are iterating through + // a space can easily look for an OutOfRange error to detect when + // they are done. + // + // This error code will not be generated by the gRPC framework. + OutOfRange int = 11 + + // Unimplemented indicates operation is not implemented or not + // supported/enabled in this service. + // + // This error code will be generated by the gRPC framework. Most + // commonly, you will see this error code when a method implementation + // is missing on the server. It can also be generated for unknown + // compression algorithms or a disagreement as to whether an RPC should + // be streaming. + Unimplemented int = 12 + + // Internal errors. Means some invariants expected by underlying + // system has been broken. If you see one of these errors, + // something is very broken. + // + // This error code will be generated by the gRPC framework in several + // internal error conditions. + Internal int = 13 + + // Unavailable indicates the service is currently unavailable. + // This is a most likely a transient condition and may be corrected + // by retrying with a backoff. Note that it is not always safe to retry + // non-idempotent operations. + // + // See litmus test above for deciding between FailedPrecondition, + // Aborted, and Unavailable. + // + // This error code will be generated by the gRPC framework during + // abrupt shutdown of a server process or network connection. + Unavailable int = 14 + + // DataLoss indicates unrecoverable data loss or corruption. + // + // This error code will not be generated by the gRPC framework. + DataLoss int = 15 + + // Unauthenticated indicates the request does not have valid + // authentication credentials for the operation. + // + // The gRPC framework will generate this error code when the + // authentication metadata is invalid or a Credentials callback fails, + // but also expect authentication middleware to generate it. + Unauthenticated int = 16 +) + +``` + +> 注意: 所有错误都会被自动翻译, 不为0的错误会在前端产生弹窗, 通过 api ErrorMessageMode 控制 + +> 在生成 Api 的时候使用 --transErr=true 会在 handler 使用翻译 + +```shell +goctls api go --api ./api/desc/core.api --dir ./api --transErr=true +``` + +```go +package api + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + + "github.com/suyuan32/simple-admin-core/api/internal/logic/api" + "github.com/suyuan32/simple-admin-core/api/internal/svc" + "github.com/suyuan32/simple-admin-core/api/internal/types" +) + +// swagger:route post /api api CreateOrUpdateApi +// +// Create or update API information | 创建或更新API +// +// Create or update API information | 创建或更新API +// +// Parameters: +// + name: body +// require: true +// in: body +// type: CreateOrUpdateApiReq +// +// Responses: +// 200: BaseMsgResp + +func CreateOrUpdateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateOrUpdateApiReq + if err := httpx.Parse(r, &req); err != nil { + httpx.Error(w, err) + return + } + + l := api.NewCreateOrUpdateApiLogic(r, svcCtx) + resp, err := l.CreateOrUpdateApi(&req) + if err != nil { + err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) + httpx.Error(w, err) + } else { + httpx.OkJson(w, resp) + } + } +} + +``` + +err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err) \ No newline at end of file diff --git a/go.mod b/go.mod index 5168b483..c4ba0623 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/go-playground/validator/v10 v10.11.1 github.com/go-redis/redis/v8 v8.11.5 github.com/go-sql-driver/mysql v1.6.0 + github.com/golang-jwt/jwt/v4 v4.4.2 github.com/google/uuid v1.3.0 github.com/lib/pq v1.10.7 github.com/mattn/go-sqlite3 v1.14.16 @@ -27,7 +28,7 @@ require ( google.golang.org/protobuf v1.28.1 ) -replace github.com/zeromicro/go-zero v1.4.2 => github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc +replace github.com/zeromicro/go-zero v1.4.2 => github.com/suyuan32/simple-admin-tools v0.0.9 require ( ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd // indirect @@ -51,7 +52,6 @@ require ( github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang-jwt/jwt/v4 v4.4.2 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect diff --git a/go.sum b/go.sum index 323acc09..fbb7d11a 100644 --- a/go.sum +++ b/go.sum @@ -609,7 +609,6 @@ github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peK github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= @@ -674,7 +673,6 @@ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtb github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -781,7 +779,6 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= @@ -836,7 +833,6 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -869,8 +865,8 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc h1:8qAIzvll7Ws4PGPSUBKVPOU6OCNJRiUaEhEET6tXng8= -github.com/suyuan32/simple-admin-tools v0.0.9-0.20221112094007-452027d780fc/go.mod h1:/AGheJnwIhsVrNHsCsCY3JfDKTeUvuon3xBTZv1RnjI= +github.com/suyuan32/simple-admin-tools v0.0.9 h1:s6+RTJ7E2GZT0BZtsAIx7Wz83WZ8FDZJ/0qE31iO35Y= +github.com/suyuan32/simple-admin-tools v0.0.9/go.mod h1:/AGheJnwIhsVrNHsCsCY3JfDKTeUvuon3xBTZv1RnjI= github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -1289,7 +1285,6 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts= golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=