diff --git a/api/desc/apis.api b/api/desc/apis.api index 2f410a82..5fc1ad8d 100644 --- a/api/desc/apis.api +++ b/api/desc/apis.api @@ -63,17 +63,24 @@ type ( // The response data of API list | API列表数据 ApiListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // API list data | API 列表数据 + Data ApiListInfo `json:"data"` + } + + // API list data | API 列表数据 + ApiListInfo { + 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"` @@ -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 ebbc3237..cc71e0fb 100644 --- a/api/desc/authority.api +++ b/api/desc/authority.api @@ -33,13 +33,19 @@ type ( Data []ApiAuthorityInfo `json:"data"` } - // The response data of api authorization list | API授权列表数据 + // The response data of api authorization list | API授权列表返回数据 ApiAuthorityListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + 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授权列表数据 - // in: body Data []ApiAuthorityInfo `json:"data"` } @@ -55,13 +61,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"` } ) @@ -74,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 @@ -82,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 663df548..51c6d25e 100644 --- a/api/desc/base.api +++ b/api/desc/base.api @@ -9,16 +9,32 @@ 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 string `json:"data"` + + // Data | 数据 + Data string `json:"data,omitempty"` +} + +// The basic response with data | 基础带数据信息 +type BaseListInfo { + // 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 BaseMsgResp { + // 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..6eaa8147 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/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 935a81d3..ac20df27 100644 --- a/api/desc/dictionary.api +++ b/api/desc/dictionary.api @@ -58,11 +58,17 @@ type ( // The response data of dictionary list | 字典列表数据 DictionaryListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The dictionary list data | 字典列表数据 + Data DictionaryListInfo `json:"data"` + } + + // The response data of dictionary list | 字典列表数据 + DictionaryListInfo { + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryInfo `json:"data"` } @@ -98,11 +104,17 @@ type ( // The response data of dictionary KV list | 字典值的列表数据 DictionaryDetailListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The dictionary list data | 字典列表数据 + Data DictionaryDetailListInfo `json:"data"` + } + + // The data of dictionary KV list | 字典值的列表数据 + DictionaryDetailListInfo { + BaseListInfo // The dictionary list data | 字典列表数据 - // in: body Data []DictionaryDetailInfo `json:"data"` } @@ -153,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 @@ -165,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 6f225cf0..b30636f0 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 @@ -100,20 +100,27 @@ type ( RealPath string `json:"realPath,omitempty" validate:"max=200"` } - // The response data of menu list | 菜单列表数据 + // The response data of menu list | 菜单列表返回数据 MenuListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The menu list data | 菜单列表数据 + Data MenuListInfo `json:"data"` + } + + // The data of menu list | 菜单列表数据 + MenuListInfo { + 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 | 角色菜单列表数据 GetMenuListBase { // Menu type: directory or menu | 菜单类型: 目录或菜单 menuType uint32 `json:"type"` + // Parent menu ID | 父级菜单ID ParentId uint64 `json:"parentId"` @@ -146,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 @@ -226,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 | 数据类型 @@ -242,12 +273,18 @@ type ( // The response data of menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 MenuParamListByMenuIdResp { - // 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 menu parameters list which belong to some menu | 某个菜单的菜单参数列表数据 + MenuParamListByMenuIdInfo { + BaseListInfo + + // The menu list data | 菜单列表数据 + Data []MenuParamInfo `json:"data"` } ) @@ -260,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 @@ -276,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 @@ -284,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 0dd436df..38addc2d 100644 --- a/api/desc/oauth.api +++ b/api/desc/oauth.api @@ -99,13 +99,19 @@ type ( InfoURL string `json:"infoURL" validate:"max=200"` } - // The response data of provider list | 提供商列表数据 + // The response data of provider list | 提供商列表返回数据 ProviderListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The provider list data | 提供商列表数据 + Data ProviderListInfo `json:"data"` + } + + // The data of provider list | 提供商列表数据 + ProviderListInfo { + BaseListInfo // The provider list data | 提供商列表数据 - // in: body Data []ProviderInfo `json:"data"` } @@ -123,8 +129,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"` } @@ -168,11 +183,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 8b11a2b0..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 @@ -49,13 +49,19 @@ type ( OrderNo uint32 `json:"orderNo" validate:"number,max=1000"` } - // The response data of role list | 角色列表数据 + // The response data of role list | 角色列表返回数据 RoleListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The role list data | 角色列表数据 + Data RoleListInfo `json:"data"` + } + + // The data of role list | 角色列表数据 + RoleListInfo { + BaseListInfo // The role list data | 角色列表数据 - // in: body Data []RoleInfo `json:"data"` } ) @@ -69,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 @@ -81,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 429f344c..f99b8917 100644 --- a/api/desc/token.api +++ b/api/desc/token.api @@ -60,13 +60,19 @@ type ( ExpiredAt int64 `json:"expiredAt" validate:"number"` } - // The response data of Token list | Token列表数据 + // The response data of Token list | Token列表返回数据 TokenListResp { - // 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列表数据 + TokenListInfo { + BaseListInfo // The token list data | Token列表数据 - // in: body Data []TokenInfo `json:"data"` } @@ -100,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 @@ -112,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 ee77192e..c6098cde 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"` @@ -51,8 +59,8 @@ type ( Expire uint64 `json:"expire"` } - // The profile response data | 个人信息返回数据 - ProfileResp { + // The profile information | 个人信息 + ProfileInfo { // user's nickname | 用户的昵称 Nickname string `json:"nickname"` @@ -66,6 +74,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 +101,7 @@ type ( } // The simple role data | 简单的角色数据 - // swagger:response RoleInfoSimple + // swagger:model RoleInfoSimple RoleInfoSimple { // Role name | 角色名 RoleName string `json:"roleName"` @@ -172,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"` @@ -198,18 +222,26 @@ type ( Value string `json:"value"` } - // The response data of user list | 用户列表数据 + // The response data of user list | 用户列表返回数据 UserListResp { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + BaseDataInfo + + // The user list data | 用户列表数据 + Data UserListInfo `json:"data"` + } + + // The response data of user list | 用户列表数据 + UserListInfo { + 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"` } @@ -239,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 @@ -307,7 +339,7 @@ service core { // Register | 注册 @handler register - post /user/register (RegisterReq) returns (SimpleMsg) + post /user/register (RegisterReq) returns (BaseMsgResp) } @server( @@ -319,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 @@ -327,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 @@ -335,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 @@ -347,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 2de2bfca..64ad19f7 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 @@ -22,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) { @@ -34,7 +33,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..5ee8351b 100644 --- a/api/internal/handler/api/delete_api_handler.go +++ b/api/internal/handler/api/delete_api_handler.go @@ -22,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) { @@ -34,7 +32,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/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 9ec81aa2..d2fa2df5 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,17 +15,19 @@ 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"), } } -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, @@ -36,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 bd16afa7..2ebe7136 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,24 +15,26 @@ 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"), } } -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 38850be8..f227e3e5 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,12 +42,11 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList return nil, err } resp = &types.ApiListResp{} - resp.Total = data.GetTotal() - - lang := l.r.Header.Get("Accept-Language") + 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, @@ -54,7 +54,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/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..2dfab29d 100644 --- a/api/internal/logic/core/init_database_logic.go +++ b/api/internal/logic/core/init_database_logic.go @@ -2,58 +2,66 @@ 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 } 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 &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, 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..d3b912ca 100644 --- a/api/internal/logic/oauth/get_provider_list_logic.go +++ b/api/internal/logic/oauth/get_provider_list_logic.go @@ -2,9 +2,11 @@ package oauth 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 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"), } } @@ -34,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/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..0f70f09e 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: 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 fc68d8bb..e7a35ef6 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: l.svcCtx.Trans.Trans(l.lang, result.Msg)}, nil } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 205bed7b..db734b1b 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -26,36 +26,56 @@ 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 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:response BaseMsg -type BaseMsg struct { - Code int32 `json:"code"` - Msg string `json:"msg"` - Data string `json:"data"` +// swagger:model BaseDataInfo +type BaseDataInfo 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 BaseListInfo +type BaseListInfo struct { + // 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"` - Msg string `json:"msg"` +// swagger:model BaseMsgResp +type BaseMsgResp struct { + // Error code | 错误代码 + Code int `json:"code"` + // Message | 提示信息 + Msg string `json:"msg"` } // The simplest message | 最简单的信息 @@ -155,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| 用户的角色信息 @@ -169,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 | 用户的头像路径 @@ -182,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 { @@ -199,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"` @@ -247,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 @@ -272,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 | 用户名 @@ -296,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"` } @@ -335,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 @@ -414,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 @@ -447,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"` @@ -484,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 { @@ -551,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"` @@ -564,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 { @@ -624,12 +719,18 @@ 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"` + 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列表数据 - // in: body Data []ApiInfo `json:"data"` } @@ -672,13 +773,19 @@ type CreateOrUpdateApiAuthorityReq struct { Data []ApiAuthorityInfo `json:"data"` } -// The response data of api authorization list | API授权列表数据 -// swagger:response ApiAuthorityListResp +// The response data of api authorization list | API授权列表返回数据 +// swagger:model ApiAuthorityListResp type ApiAuthorityListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + 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授权列表数据 - // in: body Data []ApiAuthorityInfo `json:"data"` } @@ -694,13 +801,12 @@ type MenuAuthorityInfoReq struct { MenuIds []uint64 `json:"menuIds"` } -// Create or update menu authorization information request params | 创建或更新菜单授权信息参数 -// swagger:response MenuAuthorityInfoResp +// Menu authorization response data | 菜单授权信息数据 +// swagger:model MenuAuthorityInfoResp type MenuAuthorityInfoResp struct { - // role ID | 角色ID - RoleId uint64 `json:"roleId"` - // menu ID array | 菜单ID数组 - MenuIds []uint64 `json:"menuIds"` + BaseDataInfo + // The menu authorization data | 菜单授权信息数据 + Data MenuAuthorityInfoReq `json:"data"` } // The response data of dictionary information | 字典信息 @@ -743,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"` } @@ -779,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"` } @@ -893,13 +1011,19 @@ type CreateOrUpdateProviderReq struct { InfoURL string `json:"infoURL" validate:"max=200"` } -// The response data of provider list | 提供商列表数据 -// swagger:response ProviderListResp +// The response data of provider list | 提供商列表返回数据 +// swagger:model ProviderListResp type ProviderListResp struct { - // The total number of data | 数据总数 - Total uint64 `json:"total"` + 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 | 提供商列表数据 - // in: body Data []ProviderInfo `json:"data"` } @@ -917,14 +1041,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"` @@ -978,13 +1111,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 e351fee0..ead87333 100644 --- a/core.yml +++ b/core.yml @@ -15,6 +15,41 @@ 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授权列表返回数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/ApiAuthorityListInfo' + 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 ApiInfo: description: The response data of API information | API信息 properties: @@ -55,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: @@ -94,6 +145,43 @@ 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: + $ref: '#/definitions/ApiListInfo' + 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 + BaseDataInfo: + 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,8 +202,56 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + 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 + msg: + description: Message | 提示信息 + type: string + x-go-name: Msg + 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: 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 @@ -125,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: @@ -656,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: @@ -702,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: @@ -731,6 +937,134 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + DictionaryListResp: + description: The response data of dictionary list | 字典列表数据 + properties: + code: + description: Error code | 错误代码 + format: int64 + type: integer + x-go-name: Code + data: + $ref: '#/definitions/DictionaryListInfo' + 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 + 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: Component + disabled: + description: If disabled | 是否禁用菜单 + type: boolean + x-go-name: Disabled + level: + description: The menu level | 菜单等级 + format: uint32 + type: integer + 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: OrderNo + parentId: + description: Parent menu ID | 父级菜单ID + format: uint64 + type: integer + x-go-name: ParentId + path: + description: The path to visit menu | 菜单访问路径 + type: string + 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 + GetMenuListBaseInfo: + description: The data of role menu list, show after user login | 角色菜单列表数据 + properties: + 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 + 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: @@ -812,11 +1146,31 @@ definitions: - id type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - LoginReq: - description: login request | 登录参数 + LoginInfo: + description: The log in information | 登陆返回的数据信息 properties: - captcha: - description: The Captcha which users input | 用户输入的验证码 + 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: + captcha: + description: The Captcha which users input | 用户输入的验证码 maxLength: 5 type: string x-go-name: Captcha @@ -843,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: @@ -864,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: @@ -994,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 | 创建日期 @@ -1026,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: @@ -1125,6 +1606,47 @@ definitions: - pageSize type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + 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 | 用户的头像路径 + type: string + x-go-name: Avatar + email: + description: The user's email address | 用户的邮箱 + type: string + x-go-name: Email + mobile: + description: User's mobile phone number | 用户的手机号码 + type: string + x-go-name: Mobile + nickname: + description: user's nickname | 用户的昵称 + type: string + x-go-name: Nickname + type: object + x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types ProfileReq: description: The profile request data | 个人信息请求参数 properties: @@ -1149,6 +1671,25 @@ definitions: 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: @@ -1206,6 +1747,68 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types + ProviderListInfo: + description: The 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 + 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: + 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: @@ -1319,6 +1922,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: @@ -1378,6 +2016,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: @@ -1416,6 +2070,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: @@ -1427,18 +2100,41 @@ definitions: - UUID type: object x-go-package: github.com/suyuan32/simple-admin-core/api/internal/types - UserInfoResp: - description: The response data of user's information | 用户信息返回数据 + UserBaseInfo: + description: The data of user's basic information | 用户基本信息 properties: - UUID: - description: User's UUID | 用户的UUID - type: string avatar: description: The user's avatar path | 用户的头像路径 type: string x-go-name: Avatar - createdAt: - description: Create date | 创建日期 + 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: + UUID: + description: User's UUID | 用户的UUID + type: string + avatar: + description: The user's avatar path | 用户的头像路径 + type: string + x-go-name: Avatar + createdAt: + description: Create date | 创建日期 format: int64 type: integer x-go-name: CreatedAt @@ -1486,6 +2182,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: @@ -1506,11 +2237,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 @@ -1525,11 +2254,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 @@ -1545,11 +2272,9 @@ paths: type: object responses: "200": - $ref: '#/responses/ApiListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: ApiListResp + schema: + $ref: '#/definitions/ApiListResp' summary: Get API list | 获取API列表 tags: - api @@ -1565,11 +2290,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 @@ -1585,11 +2308,9 @@ paths: type: object responses: "200": - $ref: '#/responses/ApiAuthorityListResp' - "401": - $ref: '#/responses/SimpleMsg' - "500": - $ref: '#/responses/SimpleMsg' + description: ApiAuthorityListResp + schema: + $ref: '#/definitions/ApiAuthorityListResp' summary: Get role's API authorization list | 获取角色api权限列表 tags: - authority @@ -1605,11 +2326,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 @@ -1625,11 +2344,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 @@ -1639,13 +2356,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 @@ -1662,11 +2375,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 @@ -1682,11 +2393,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 @@ -1701,11 +2410,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 @@ -1721,11 +2428,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 @@ -1740,11 +2445,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 @@ -1760,11 +2463,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 @@ -1780,11 +2481,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 @@ -1800,11 +2499,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 @@ -1819,11 +2516,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 @@ -1833,11 +2528,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 @@ -1853,11 +2546,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 @@ -1872,11 +2563,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 @@ -1892,11 +2581,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 @@ -1906,11 +2593,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 @@ -1926,11 +2611,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 @@ -1940,11 +2623,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 @@ -1960,11 +2641,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 @@ -1979,11 +2658,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 @@ -1999,11 +2676,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 @@ -2019,11 +2694,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 @@ -2038,11 +2711,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 @@ -2058,11 +2729,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 @@ -2078,11 +2747,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 @@ -2098,11 +2765,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 @@ -2117,11 +2782,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 @@ -2137,11 +2800,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 @@ -2157,11 +2818,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 @@ -2177,11 +2836,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 @@ -2197,11 +2854,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 @@ -2216,11 +2871,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 @@ -2236,11 +2889,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 @@ -2250,11 +2901,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 @@ -2270,11 +2919,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 @@ -2290,11 +2937,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 @@ -2304,11 +2949,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 @@ -2318,11 +2961,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 @@ -2332,11 +2973,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 @@ -2351,11 +2990,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 @@ -2371,11 +3008,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 @@ -2391,231 +3026,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: - 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 - 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: Create or update menu authorization information request params | 创建或更新菜单授权信息参数 - headers: - menuIds: - description: menu ID array | 菜单ID数组 - items: - format: uint64 - type: integer - type: array - roleId: - description: role ID | 角色ID - format: uint64 - type: integer - 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: @@ -2628,139 +3047,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/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 851ea421..c4ba0623 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( 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 +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.8 +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 @@ -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..fbb7d11a 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 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= 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/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) | 字典状态"), } } 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 e0849f71..7a6a9016 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", @@ -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 d3219809..eafe4854 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": "目标不存在", @@ -124,5 +124,9 @@ }, "oauth": { "createAccount": "请创建一个该邮箱的账号或绑定该邮箱到一个账号" + }, + "casbin": { + "removeFailed": "无法删除旧规则", + "addFailed": "无法添加新规则" } } diff --git a/pkg/i18n/translator.go b/pkg/i18n/translator.go index ccbbc624..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,10 +60,16 @@ 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 || message == "" { + 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 new file mode 100644 index 00000000..e8220ada --- /dev/null +++ b/pkg/i18n/var.go @@ -0,0 +1,17 @@ +package i18n + +const ( + 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/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..4d95ddd6 100644 --- a/pkg/msg/logmsg/msg.go +++ b/pkg/msg/logmsg/msg.go @@ -7,7 +7,7 @@ const ( DeleteFailed string = "delete failed" UpdateSuccess string = "update successful" UpdateFailed string = "update failed" - TargetNotFound string = "target cannot be found" + TargetNotFound string = "target not found" DatabaseError string = "database error" RedisError string = "redis error" ) 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 }