From 1173086e2f4112ef2e18d835a8e7768ef76cc28a Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Wed, 20 Sep 2023 14:55:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0api=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=87=A0=E4=B9=8E=E5=AE=8C=E5=96=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 7 +- api/api.go | 57 + api/desc/all.api | 1 + api/desc/core/department.api | 6 +- api/desc/core/dictionary.api | 77 +- api/desc/core/model.api | 54 +- api/desc/core/oauth_provider.api | 10 + api/desc/core/user.api | 2 +- api/etc/api-dev.yaml | 70 + api/etc/api.yaml | 32 + api/internal/config/config.go | 27 + .../handler/auth/login_by_code_handler.go | 44 + api/internal/handler/auth/login_handler.go | 44 + .../handler/auth/oauth_callback_handler.go | 31 + .../auth/oauth_login_by_code_handler.go | 44 + .../auth/oauth_login_by_phone_handler.go | 44 + .../handler/auth/oauth_login_handler.go | 38 + api/internal/handler/auth/register_handler.go | 44 + .../handler/base/init_database_handler.go | 29 + .../handler/captcha/get_captcha_handler.go | 31 + .../captcha/validate_captcha_handler.go | 42 + .../create_department_admin_handler.go | 44 + .../delete_department_admin_handler.go | 42 + .../get_department_admin_handler.go | 38 + .../get_department_list_admin_handler.go | 38 + .../update_department_admin_handler.go | 42 + .../create_dictionary_admin_handler.go | 44 + .../delete_dictionary_admin_handler.go | 42 + .../create_dictionary_detail_admin_handler.go | 44 + .../delete_dictionary_detail_admin_handler.go | 36 + .../get_dictionary_detail_admin_handler.go | 38 + ...et_dictionary_detail_list_admin_handler.go | 38 + .../update_dictionary_detail_admin_handler.go | 42 + .../get_dictionary_admin_handler.go | 38 + .../get_dictionary_list_admin_handler.go | 38 + .../update_dictionary_admin_handler.go | 42 + .../district/get_district_children_handler.go | 38 + .../district/get_district_list_handler.go | 38 + .../district/get_district_name_handler.go | 38 + .../district/get_district_tree_handler.go | 38 + .../create_oauth_provider_admin_handler.go | 42 + .../delete_oauth_provider_admin_handler.go | 42 + .../get_oauth_provider_admin_handler.go | 38 + .../get_oauth_provider_list_admin_handler.go | 38 + .../update_oauth_provider_admin_handler.go | 42 + .../role_admin/create_role_admin_handler.go | 42 + .../role_admin/delete_role_admin_handler.go | 42 + .../role_admin/get_role_admin_handler.go | 38 + .../role_admin/get_role_list_admin_handler.go | 38 + .../role_admin/update_role_admin_handler.go | 42 + api/internal/handler/routes.go | 363 +++ .../disable_token_admin_handler.go | 42 + .../get_token_list_admin_handler.go | 38 + .../handler/user/get_current_user_handler.go | 31 + .../user_admin/create_user_admin_handler.go | 44 + .../user_admin/delete_user_admin_handler.go | 42 + .../user_admin/get_user_admin_handler.go | 38 + .../user_admin/get_user_list_admin_handler.go | 38 + .../user_admin/update_user_admin_handler.go | 42 + api/internal/logic/auth/auth.go | 89 + .../logic/auth/login_by_code_logic.go | 116 + api/internal/logic/auth/login_logic.go | 65 + .../logic/auth/oauth_callback_logic.go | 30 + .../logic/auth/oauth_login_by_code_logic.go | 30 + .../logic/auth/oauth_login_by_phone_logic.go | 49 + api/internal/logic/auth/oauth_login_logic.go | 30 + api/internal/logic/auth/register_logic.go | 73 + .../logic/base/init_database_logic.go | 31 + .../logic/captcha/get_captcha_logic.go | 35 + .../logic/captcha/validate_captcha_logic.go | 31 + .../create_department_admin_logic.go | 40 + .../delete_department_admin_logic.go | 33 + .../get_department_admin_logic.go | 43 + .../get_department_list_admin_logic.go | 46 + .../update_department_admin_logic.go | 37 + .../create_dictionary_admin_logic.go | 38 + .../delete_dictionary_admin_logic.go | 34 + .../create_dictionary_detail_admin_logic.go | 40 + .../delete_dictionary_detail_admin_logic.go | 37 + .../get_dictionary_detail_admin_logic.go | 48 + .../get_dictionary_detail_list_admin_logic.go | 55 + .../update_dictionary_detail_admin_logic.go | 38 + .../get_dictionary_admin_logic.go | 40 + .../get_dictionary_list_admin_logic.go | 47 + .../update_dictionary_admin_logic.go | 38 + .../district/get_district_children_logic.go | 41 + .../logic/district/get_district_list_logic.go | 46 + .../logic/district/get_district_name_logic.go | 41 + .../logic/district/get_district_tree_logic.go | 47 + .../create_oauth_provider_admin_logic.go | 39 + .../delete_oauth_provider_admin_logic.go | 33 + .../get_oauth_provider_admin_logic.go | 40 + .../get_oauth_provider_list_admin_logic.go | 47 + .../update_oauth_provider_admin_logic.go | 39 + .../role_admin/create_role_admin_logic.go | 37 + .../role_admin/delete_role_admin_logic.go | 33 + .../logic/role_admin/get_role_admin_logic.go | 41 + .../role_admin/get_role_list_admin_logic.go | 44 + .../role_admin/update_role_admin_logic.go | 37 + .../token_admin/disable_token_admin_logic.go | 30 + .../token_admin/get_token_list_admin_logic.go | 30 + .../logic/user/get_current_user_logic.go | 42 + .../user_admin/create_user_admin_logic.go | 43 + .../user_admin/delete_user_admin_logic.go | 33 + .../logic/user_admin/get_user_admin_logic.go | 46 + .../user_admin/get_user_list_admin_logic.go | 50 + .../user_admin/update_user_admin_logic.go | 37 + .../middleware/authority_middleware.go | 47 + api/internal/svc/cache/code_cache.go | 65 + api/internal/svc/captcha/captcha.go | 37 + api/internal/svc/convert.go | 219 ++ api/internal/svc/service_context.go | 81 + api/internal/types/types.go | 671 ++++++ api/internal/types/vars.go | 13 + dal/errx/errx.go | 24 +- dal/i18n/locale/zh.json | 12 +- dal/vars.go | 21 + go.mod | 12 +- go.sum | 57 +- n-admin-server.yml | 1956 ++++++++++++++++- rpc/core/etc/core.yaml | 7 +- 121 files changed, 7767 insertions(+), 98 deletions(-) create mode 100644 api/api.go create mode 100644 api/etc/api-dev.yaml create mode 100644 api/etc/api.yaml create mode 100644 api/internal/config/config.go create mode 100644 api/internal/handler/auth/login_by_code_handler.go create mode 100644 api/internal/handler/auth/login_handler.go create mode 100644 api/internal/handler/auth/oauth_callback_handler.go create mode 100644 api/internal/handler/auth/oauth_login_by_code_handler.go create mode 100644 api/internal/handler/auth/oauth_login_by_phone_handler.go create mode 100644 api/internal/handler/auth/oauth_login_handler.go create mode 100644 api/internal/handler/auth/register_handler.go create mode 100644 api/internal/handler/base/init_database_handler.go create mode 100644 api/internal/handler/captcha/get_captcha_handler.go create mode 100644 api/internal/handler/captcha/validate_captcha_handler.go create mode 100644 api/internal/handler/department_admin/create_department_admin_handler.go create mode 100644 api/internal/handler/department_admin/delete_department_admin_handler.go create mode 100644 api/internal/handler/department_admin/get_department_admin_handler.go create mode 100644 api/internal/handler/department_admin/get_department_list_admin_handler.go create mode 100644 api/internal/handler/department_admin/update_department_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/create_dictionary_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/delete_dictionary_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/detail/create_dictionary_detail_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/detail/delete_dictionary_detail_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/detail/get_dictionary_detail_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/detail/get_dictionary_detail_list_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/detail/update_dictionary_detail_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/get_dictionary_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/get_dictionary_list_admin_handler.go create mode 100644 api/internal/handler/dictionary_admin/update_dictionary_admin_handler.go create mode 100644 api/internal/handler/district/get_district_children_handler.go create mode 100644 api/internal/handler/district/get_district_list_handler.go create mode 100644 api/internal/handler/district/get_district_name_handler.go create mode 100644 api/internal/handler/district/get_district_tree_handler.go create mode 100644 api/internal/handler/oauthprovider_admin/create_oauth_provider_admin_handler.go create mode 100644 api/internal/handler/oauthprovider_admin/delete_oauth_provider_admin_handler.go create mode 100644 api/internal/handler/oauthprovider_admin/get_oauth_provider_admin_handler.go create mode 100644 api/internal/handler/oauthprovider_admin/get_oauth_provider_list_admin_handler.go create mode 100644 api/internal/handler/oauthprovider_admin/update_oauth_provider_admin_handler.go create mode 100644 api/internal/handler/role_admin/create_role_admin_handler.go create mode 100644 api/internal/handler/role_admin/delete_role_admin_handler.go create mode 100644 api/internal/handler/role_admin/get_role_admin_handler.go create mode 100644 api/internal/handler/role_admin/get_role_list_admin_handler.go create mode 100644 api/internal/handler/role_admin/update_role_admin_handler.go create mode 100644 api/internal/handler/routes.go create mode 100644 api/internal/handler/token_admin/disable_token_admin_handler.go create mode 100644 api/internal/handler/token_admin/get_token_list_admin_handler.go create mode 100644 api/internal/handler/user/get_current_user_handler.go create mode 100644 api/internal/handler/user_admin/create_user_admin_handler.go create mode 100644 api/internal/handler/user_admin/delete_user_admin_handler.go create mode 100644 api/internal/handler/user_admin/get_user_admin_handler.go create mode 100644 api/internal/handler/user_admin/get_user_list_admin_handler.go create mode 100644 api/internal/handler/user_admin/update_user_admin_handler.go create mode 100644 api/internal/logic/auth/auth.go create mode 100644 api/internal/logic/auth/login_by_code_logic.go create mode 100644 api/internal/logic/auth/login_logic.go create mode 100644 api/internal/logic/auth/oauth_callback_logic.go create mode 100644 api/internal/logic/auth/oauth_login_by_code_logic.go create mode 100644 api/internal/logic/auth/oauth_login_by_phone_logic.go create mode 100644 api/internal/logic/auth/oauth_login_logic.go create mode 100644 api/internal/logic/auth/register_logic.go create mode 100644 api/internal/logic/base/init_database_logic.go create mode 100644 api/internal/logic/captcha/get_captcha_logic.go create mode 100644 api/internal/logic/captcha/validate_captcha_logic.go create mode 100644 api/internal/logic/department_admin/create_department_admin_logic.go create mode 100644 api/internal/logic/department_admin/delete_department_admin_logic.go create mode 100644 api/internal/logic/department_admin/get_department_admin_logic.go create mode 100644 api/internal/logic/department_admin/get_department_list_admin_logic.go create mode 100644 api/internal/logic/department_admin/update_department_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/create_dictionary_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/delete_dictionary_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/detail/create_dictionary_detail_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/detail/delete_dictionary_detail_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/detail/get_dictionary_detail_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/detail/get_dictionary_detail_list_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/detail/update_dictionary_detail_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/get_dictionary_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/get_dictionary_list_admin_logic.go create mode 100644 api/internal/logic/dictionary_admin/update_dictionary_admin_logic.go create mode 100644 api/internal/logic/district/get_district_children_logic.go create mode 100644 api/internal/logic/district/get_district_list_logic.go create mode 100644 api/internal/logic/district/get_district_name_logic.go create mode 100644 api/internal/logic/district/get_district_tree_logic.go create mode 100644 api/internal/logic/oauthprovider_admin/create_oauth_provider_admin_logic.go create mode 100644 api/internal/logic/oauthprovider_admin/delete_oauth_provider_admin_logic.go create mode 100644 api/internal/logic/oauthprovider_admin/get_oauth_provider_admin_logic.go create mode 100644 api/internal/logic/oauthprovider_admin/get_oauth_provider_list_admin_logic.go create mode 100644 api/internal/logic/oauthprovider_admin/update_oauth_provider_admin_logic.go create mode 100644 api/internal/logic/role_admin/create_role_admin_logic.go create mode 100644 api/internal/logic/role_admin/delete_role_admin_logic.go create mode 100644 api/internal/logic/role_admin/get_role_admin_logic.go create mode 100644 api/internal/logic/role_admin/get_role_list_admin_logic.go create mode 100644 api/internal/logic/role_admin/update_role_admin_logic.go create mode 100644 api/internal/logic/token_admin/disable_token_admin_logic.go create mode 100644 api/internal/logic/token_admin/get_token_list_admin_logic.go create mode 100644 api/internal/logic/user/get_current_user_logic.go create mode 100644 api/internal/logic/user_admin/create_user_admin_logic.go create mode 100644 api/internal/logic/user_admin/delete_user_admin_logic.go create mode 100644 api/internal/logic/user_admin/get_user_admin_logic.go create mode 100644 api/internal/logic/user_admin/get_user_list_admin_logic.go create mode 100644 api/internal/logic/user_admin/update_user_admin_logic.go create mode 100644 api/internal/middleware/authority_middleware.go create mode 100644 api/internal/svc/cache/code_cache.go create mode 100644 api/internal/svc/captcha/captcha.go create mode 100644 api/internal/svc/convert.go create mode 100644 api/internal/svc/service_context.go create mode 100644 api/internal/types/types.go create mode 100644 api/internal/types/vars.go create mode 100644 dal/vars.go diff --git a/Makefile b/Makefile index 0ea1e6f..16e5582 100644 --- a/Makefile +++ b/Makefile @@ -68,4 +68,9 @@ gen-ent: # Generate Ent codes | 生成 Ent 的代码 --feature $(ENT_FEATURE) \ --template glob="./doc/ent/template/*.tmpl" \ ./rpc/$(SERVICE)/ent/schema - @echo "Generate Ent files successfully" \ No newline at end of file + @echo "Generate Ent files successfully" + +.PHONY: serve-swagger +serve-swagger: # Run the swagger server | 运行 swagger 服务 # lsof -i:36666 | awk 'NR!=1 {print $2}' | xargs killall -9 || true + swagger serve -F=swagger --host 0.0.0.0 --port 39999 n-admin-server.yml + @echo "Serve swagger-ui successfully" \ No newline at end of file diff --git a/api/api.go b/api/api.go new file mode 100644 index 0000000..807b6d9 --- /dev/null +++ b/api/api.go @@ -0,0 +1,57 @@ +// api +// +// Description: api service +// +// Schemes: http, https +// Host: localhost:0 +// BasePath: / +// Version: 0.0.1 +// SecurityDefinitions: +// Token: +// type: apiKey +// name: Authorization +// in: header +// Security: +// - Token: [] +// Consumes: +// - application/json +// +// Produces: +// - application/json +// +// swagger:meta +package main + +import ( + "flag" + "fmt" + "git.noahlan.cn/noahlan/ntool-biz/core/i18n" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/config" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "api/etc/api-dev.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c, conf.UseEnv()) + + server := rest.MustNewServer(c.RestConf, rest.WithCors(c.CORSConf.Address)) + defer server.Stop() + + // i18n + server.Use(i18n.WithI18nMiddleware()) + + ctx := svc.NewServiceContext(c) + handler.RegisterHandlers(server, ctx) + + fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) + server.Start() +} diff --git a/api/desc/all.api b/api/desc/all.api index 14bd281..2241277 100644 --- a/api/desc/all.api +++ b/api/desc/all.api @@ -8,3 +8,4 @@ import "core/captcha.api" import "core/district.api" import "core/oauth_provider.api" import "core/department.api" +import "core/dictionary.api" \ No newline at end of file diff --git a/api/desc/core/department.api b/api/desc/core/department.api index f7b83bc..39961c8 100644 --- a/api/desc/core/department.api +++ b/api/desc/core/department.api @@ -11,10 +11,10 @@ type ( Name string `json:"name,optional" form:"name,optional"` // Leader ID | 负责人ID - LeaderID int64 `json:"leaderId,string,optional" form:"leaderId,optional"` + LeaderId int64 `json:"leaderId,string,optional" form:"leaderId,optional"` // Parent ID | 父节点ID - ParentID int64 `json:"parentId,string,optional" form:"parentId,optional"` + ParentId int64 `json:"parentId,string,optional" form:"parentId,optional"` } // Department list response | 部门列表返回 @@ -52,5 +52,5 @@ service api { // Delete department | 删除部门 @handler deleteDepartmentAdmin - delete / (BaseID) + delete / (BaseIDs) } \ No newline at end of file diff --git a/api/desc/core/dictionary.api b/api/desc/core/dictionary.api index d22a3b7..1f10214 100644 --- a/api/desc/core/dictionary.api +++ b/api/desc/core/dictionary.api @@ -13,6 +13,9 @@ type ( // 搜索名称 Name string `json:"name,optional" form:"name,optional"` + // Status | 状态 + Status string `json:"status,optional" form:"status,optional"` + // Keyword | 综合搜索关键字 Keyword string `json:"keyword,optional" form:"keyword,optional"` } @@ -52,5 +55,77 @@ service api { // Delete dictionary | 删除字典 @handler deleteDictionaryAdmin - delete / (BaseID) + delete / (BaseIDs) +} + +///////////////////////////////// detail + +type ( + // Dictionary detail request | 字典项查询请求 + // swagger:parameters GetDictionaryDetailListAdmin GetDictionaryDetailAdmin + DictionaryDetailReq { + BaseID + *Pagination + + // 字典ID + DictionaryID int64 `json:"dictionaryId,string,optional" form:"dictionaryId,optional"` + + // Status | 状态 + Status string `json:"status,optional" form:"status,optional"` + + // 展示名称 + Title string `json:"title,optional" form:"title,optional"` + + // Key + Key string `json:"key,optional" form:"key,optional"` + + // Keyword | 综合搜索关键字 + Keyword string `json:"keyword,optional" form:"keyword,optional"` + } + + // Dictionary Detail list response | 字典项列表返回 + DictionaryDetailListResp { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + + // List | 数据列表 + List []*DictionaryDetailInfo `json:"list"` + } + + // Dictionary Detail request | 字典项删除请求 + // swagger:parameters DeleteDictionaryDetailAdmin + DeleteDictionaryDetailReq { + BaseIDs + + // 字典ID + DictionaryID int64 `json:"dictionaryId,string,optional" form:"dictionaryId,optional"` + } +) + +@server( + jwt: Auth + group: dictionary_admin/detail + middleware: Authority + prefix: /api/admin/dictionary/detail +) +service api { + // Create dictionary Detail | 创建字典项 + @handler createDictionaryDetailAdmin + post /create (DictionaryDetailInfo) returns (BaseID) + + // Update dictionary info | 更新字典项信息 + @handler updateDictionaryDetailAdmin + post /update (DictionaryDetailInfo) + + // Get dictionary list | 获取字典项列表 + @handler getDictionaryDetailListAdmin + get /list (DictionaryDetailReq) returns (DictionaryDetailListResp) + + // Get dictionary | 获取字典项 + @handler getDictionaryDetailAdmin + get / (DictionaryDetailReq) returns (DictionaryDetailInfo) + + // Delete dictionary | 删除字典项(批量) + @handler deleteDictionaryDetailAdmin + delete / (DeleteDictionaryDetailReq) } \ No newline at end of file diff --git a/api/desc/core/model.api b/api/desc/core/model.api index 4bd1309..0531b11 100644 --- a/api/desc/core/model.api +++ b/api/desc/core/model.api @@ -31,6 +31,8 @@ type ( Roles []string `json:"roles,optional"` // LoginRecord | 用户登录记录 LoginRecord *UserLoginRecordInfo `json:"loginRecord,optional"` + // Meta | 元数据 + Metas map[string]string `json:"metadata"` } // 用户登录记录 @@ -39,15 +41,15 @@ type ( TimeInfo // 用户ID - UserID int64 `json:"userId,string,optional"` + UserId int64 `json:"userId,string,optional"` // 最近一次登录时间 LastLoginAt string `json:"lastLoginAt,optional"` // 最近一次登录IPv4 LastLoginIpv4 string `json:"lastLoginIpv4,optional"` // 最近一次登录设备 LastLoginDevice string `json:"lastLoginDevice,optional"` - // 最近一次登录浏览器UA - LastLoginUA string `json:"lastLoginUa,optional"` + // 最近一次登录浏览器Ua + LastLoginUa string `json:"lastLoginUa,optional"` // 总登录次数 LoginCount uint64 `json:"loginCount,optional"` } @@ -59,10 +61,8 @@ type ( // Status | 状态 Status string `json:"status,optional"` - // User's ID | 用户ID - UserID int64 `json:"userId,string,optional"` - // Token type | 凭证类型 [Bearer] - TokenType string `json:"tokenType,optional"` + // User's Id | 用户ID + UserId int64 `json:"userId,string,optional"` // AccessToken | AccessToken 字符串 AccessToken string `json:"accessToken,optional"` // RefreshToken | RefreshToken 字符串 @@ -70,7 +70,7 @@ type ( // Source | Token来源,PCWeb/WechatMini/AlipayMini Source string `json:"source,optional"` // Expire Time | 过期时间 - ExpiredAt string `json:"expiredAt,optional"` + ExpiredAt int64 `json:"expiredAt,optional"` } // 用户社交平台信息 @@ -79,7 +79,7 @@ type ( TimeInfo // 系统用户ID - UserID int64 `json:"userId,string,optional"` + UserId int64 `json:"userId,string,optional"` // OAuth Provider | 服务提供商 Provider string `json:"provider,optional"` // Access Token | 用户在提供商最近一次登录的访问凭证 @@ -87,11 +87,11 @@ type ( // Refresh Token | 用户在提供商最近一次登录的刷新凭证 RefreshToken string `json:"refreshToken,optional"` // User's ID | 提供商用户ID,不一定存在 - UID string `json:"uid,optional"` - // OpenID | 用户在提供商的OpenID - OpenID string `json:"openId,optional"` - // UnionID | 用户在提供商的UnionID - UnionID string `json:"unionId,optional"` + Uid string `json:"uid,optional"` + // OpenId | 用户在提供商的OpenID + OpenId string `json:"openId,optional"` + // UnionId | 用户在提供商的UnionID + UnionId string `json:"unionId,optional"` // Key | 用户在提供商的用于解密的key Key string `json:"key,optional"` // Expires in | 访问凭证过期时长,单位:秒 @@ -128,11 +128,11 @@ type ( // Department name | 部门名称 Name string `json:"name,optional"` // Department leader | 部门负责人 - LeaderID int64 `json:"leaderId,string,optional"` + LeaderId int64 `json:"leaderId,string,optional"` // Remark | 备注 Remark string `json:"remark,optional"` // Parent ID | 直接父级ID - ParentID int64 `json:"parentId,string,optional"` + ParentId int64 `json:"parentId,string,optional"` // Leader | 部门负责人信息 Leader *UserInfo `json:"leader,optional"` @@ -150,19 +150,19 @@ type ( // The provider's name | 提供商名称 Name string `json:"name,optional"` // The client id | 客户端 id - ClientID string `json:"clientId,optional"` + ClientId string `json:"clientId,optional"` // The client secret | 客户端密钥 ClientSecret string `json:"clientSecret,optional"` // The redirect url | 跳转地址 - RedirectURL string `json:"redirectUrl,optional"` + RedirectUrl string `json:"redirectUrl,optional"` // The scopes | 权限范围 Scopes string `json:"scopes,optional"` // The auth url of the provider | 认证地址 - AuthURL string `json:"authUrl,optional"` + AuthUrl string `json:"authUrl,optional"` // The token url of the provider | 获取 Token 地址 - TokenURL string `json:"tokenUrl,optional"` + TokenUrl string `json:"tokenUrl,optional"` // The URL to request user information by token | 用户信息请求地址 - InfoURL string `json:"infoUrl,optional"` + InfoUrl string `json:"infoUrl,optional"` // The description of the provider | 提供商描述 Description string `json:"description,optional"` // The system internal oauth provider | 系统内置提供商 @@ -202,6 +202,14 @@ type ( Children []*DistrictInfo `json:"children,optional"` } + // CaptchaInfo | 验证码信息 + CaptchaInfo { + // CaptchaId | 验证码ID + CaptchaId string `json:"captchaId"` + // Base64 | 验证码图片 Base64 + Base64 string `json:"base64"` + } + // 字典信息 DictionaryInfo { BaseID @@ -235,8 +243,8 @@ type ( Key string `json:"key,optional"` // value | 值 Value string `json:"value,optional"` - // Dictionary ID | 字典ID - DictionaryID int64 `json:"dictionaryId,string,optional"` + // Dictionary Id | 字典ID + DictionaryId int64 `json:"dictionaryId,string,optional"` // Dictionary | 字典信息 Dictionary *DictionaryInfo `json:"dictionary,optional"` diff --git a/api/desc/core/oauth_provider.api b/api/desc/core/oauth_provider.api index ece0e1e..45ece81 100644 --- a/api/desc/core/oauth_provider.api +++ b/api/desc/core/oauth_provider.api @@ -18,6 +18,16 @@ type ( // Required: false // Example: wx21k2j193j2ksdfaak291l ClientId string `form:"clientId,optional"` + + // 是否系统内置 + // + // Required: false + System *bool `form:"system,optional"` + + // 是否已初始化 + // + // Required: false + Init *bool `form:"init,optional"` } // OAuth provider list response | OAuth提供商查询返回 diff --git a/api/desc/core/user.api b/api/desc/core/user.api index 2813cb1..7c55b63 100644 --- a/api/desc/core/user.api +++ b/api/desc/core/user.api @@ -52,7 +52,7 @@ service api { // Delete user | 删除用户 @handler deleteUserAdmin - delete / (BaseID) + delete / (BaseIDs) } @server( diff --git a/api/etc/api-dev.yaml b/api/etc/api-dev.yaml new file mode 100644 index 0000000..17a29c6 --- /dev/null +++ b/api/etc/api-dev.yaml @@ -0,0 +1,70 @@ +Name: api.api +Host: 0.0.0.0 +Port: 19999 +Timeout: 30000 + +Auth: + AccessSecret: "FZpng2gdo1ZrUndoWC7AqjpCVdoXkabi" # the same as core + AccessExpire: 259200 + +CORSConf: + Address: '*' + +Log: + ServiceName: apiApiLogger + Mode: console + Path: ./logs/api/api + Encoding: plain # json or plain + Level: debug + Stat: false + Compress: false + KeepDays: 7 + StackCoolDownMillis: 100 + +Prometheus: + Host: 0.0.0.0 + Port: 4000 + Path: /metrics + +CoreRpc: + NonBlock: true + Etcd: + Hosts: + - 192.168.1.155:2379 + Key: n-admin.core.rpc + +RedisConf: + Addr: 192.168.1.155:6379 + Type: node + +Captcha: + KeyLen: 4 + ImgWidth: 240 + ImgHeight: 80 + Driver: string + +# 多语言配置 +I18n: + Default: zh + RootPath: dal/i18n/locale + SortedParameterPrefix: p + +# Casbin +CasbinConf: + ModelText: | + [request_definition] + r = sub, obj, act + [policy_definition] + p = sub, obj, act + [role_definition] + g = _, _ + [policy_effect] + e = some(where (p.eft == allow)) + [matchers] + m = r.sub == p.sub && keyMatch2(r.obj, p.obj) && r.act == p.act + +RegisterConf: + DefaultPassword: "gvXYlSc8" + Description: "此用户很懒,什么都没留下。" + + diff --git a/api/etc/api.yaml b/api/etc/api.yaml new file mode 100644 index 0000000..b54d578 --- /dev/null +++ b/api/etc/api.yaml @@ -0,0 +1,32 @@ +Name: api.api +Host: 0.0.0.0 +Port: 0 +Timeout: 30000 + +Auth: + AccessSecret: # the same as core + AccessExpire: 259200 + +CORSConf: + Address: '*' + +Log: + ServiceName: apiApiLogger + Mode: console + Path: ./logs/api/api + Encoding: plain # json or plain + Level: debug + Stat: false + Compress: false + KeepDays: 7 + StackCoolDownMillis: 100 + +Prometheus: + Host: 0.0.0.0 + Port: 4000 + Path: /metrics + + + + + diff --git a/api/internal/config/config.go b/api/internal/config/config.go new file mode 100644 index 0000000..ee5ec27 --- /dev/null +++ b/api/internal/config/config.go @@ -0,0 +1,27 @@ +package config + +import ( + "git.noahlan.cn/noahlan/ntool-biz/core/captcha" + nconfig "git.noahlan.cn/noahlan/ntool-biz/core/config" + "git.noahlan.cn/noahlan/ntool-biz/core/i18n" + "github.com/zeromicro/go-zero/zrpc" + + "github.com/zeromicro/go-zero/rest" +) + +type Config struct { + rest.RestConf + Auth nconfig.AuthConf + CORSConf nconfig.CORSConf + RedisConf nconfig.RedisConf + Captcha captcha.Config `json:",optional"` + I18n i18n.Config `json:",optional"` + + RegisterConf RegisterConf + + CoreRpc zrpc.RpcClientConf +} + +type RegisterConf struct { + DefaultPassword string `json:",default=a123456"` +} diff --git a/api/internal/handler/auth/login_by_code_handler.go b/api/internal/handler/auth/login_by_code_handler.go new file mode 100644 index 0000000..f0a7535 --- /dev/null +++ b/api/internal/handler/auth/login_by_code_handler.go @@ -0,0 +1,44 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/auth/login/byCode auth LoginByCode +// +// Log in by code | 验证码登录,手机x邮箱 +// +// Log in by code | 验证码登录,手机x邮箱 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: LoginReq +// +// Responses: +// 200: LoginResp + +func LoginByCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.LoginReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewLoginByCodeLogic(r, r.Context(), svcCtx) + resp, err := l.LoginByCode(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/login_handler.go b/api/internal/handler/auth/login_handler.go new file mode 100644 index 0000000..1e9b8c1 --- /dev/null +++ b/api/internal/handler/auth/login_handler.go @@ -0,0 +1,44 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/auth/login auth Login +// +// Log in | 密码登录 +// +// Log in | 密码登录 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: LoginReq +// +// Responses: +// 200: LoginResp + +func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.LoginReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewLoginLogic(r, r.Context(), svcCtx) + resp, err := l.Login(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/oauth_callback_handler.go b/api/internal/handler/auth/oauth_callback_handler.go new file mode 100644 index 0000000..1081c22 --- /dev/null +++ b/api/internal/handler/auth/oauth_callback_handler.go @@ -0,0 +1,31 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" +) + +// swagger:route get /api/auth/oauth/login/callback auth OauthCallback +// +// Oauth log in callback route | Oauth 登录返回调接口,即redirect_uri +// +// Oauth log in callback route | Oauth 登录返回调接口,即redirect_uri +// +// Responses: +// 200: LoginResp + +func OauthCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + + l := auth.NewOauthCallbackLogic(r, r.Context(), svcCtx) + resp, err := l.OauthCallback() + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/oauth_login_by_code_handler.go b/api/internal/handler/auth/oauth_login_by_code_handler.go new file mode 100644 index 0000000..1c40d7b --- /dev/null +++ b/api/internal/handler/auth/oauth_login_by_code_handler.go @@ -0,0 +1,44 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/auth/oauth/login/byCode auth OauthLoginByCode +// +// Oauth log in by code | Oauth 第三方登录,客户端自行获取code进行登录 +// +// Oauth log in by code | Oauth 第三方登录,客户端自行获取code进行登录 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: OauthLoginByCodeReq +// +// Responses: +// 200: LoginResp + +func OauthLoginByCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthLoginByCodeReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewOauthLoginByCodeLogic(r, r.Context(), svcCtx) + resp, err := l.OauthLoginByCode(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/oauth_login_by_phone_handler.go b/api/internal/handler/auth/oauth_login_by_phone_handler.go new file mode 100644 index 0000000..f6d1923 --- /dev/null +++ b/api/internal/handler/auth/oauth_login_by_phone_handler.go @@ -0,0 +1,44 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/auth/oauth/login/byPhone auth OauthLoginByPhone +// +// Oauth log in by phone code | Oauth 第三方登录,客户端获取换取手机号的code进行登录 +// +// Oauth log in by phone code | Oauth 第三方登录,客户端获取换取手机号的code进行登录 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: OauthLoginByPhoneCodeReq +// +// Responses: +// 200: LoginResp + +func OauthLoginByPhoneHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthLoginByPhoneCodeReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewOauthLoginByPhoneLogic(r, r.Context(), svcCtx) + resp, err := l.OauthLoginByPhone(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/oauth_login_handler.go b/api/internal/handler/auth/oauth_login_handler.go new file mode 100644 index 0000000..9f19cc9 --- /dev/null +++ b/api/internal/handler/auth/oauth_login_handler.go @@ -0,0 +1,38 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/auth/oauth/login auth OauthLogin +// +// Oauth log in | Oauth 第三方登录,获取登录地址(通常针对PC网页登录,APP端自行获取code) +// +// Oauth log in | Oauth 第三方登录,获取登录地址(通常针对PC网页登录,APP端自行获取code) +// +// Responses: +// 200: OauthLoginResp + +func OauthLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthLoginReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewOauthLoginLogic(r, r.Context(), svcCtx) + resp, err := l.OauthLogin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/auth/register_handler.go b/api/internal/handler/auth/register_handler.go new file mode 100644 index 0000000..826254f --- /dev/null +++ b/api/internal/handler/auth/register_handler.go @@ -0,0 +1,44 @@ +package auth + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/auth" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/auth/register auth Register +// +// Register | 注册 +// +// Register | 注册 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: RegisterReq +// +// Responses: +// 200: BaseID + +func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.RegisterReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := auth.NewRegisterLogic(r, r.Context(), svcCtx) + resp, err := l.Register(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/base/init_database_handler.go b/api/internal/handler/base/init_database_handler.go new file mode 100644 index 0000000..21f375f --- /dev/null +++ b/api/internal/handler/base/init_database_handler.go @@ -0,0 +1,29 @@ +package base + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/base" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" +) + +// swagger:route get /api/base/initDatabase base InitDatabase +// +// Initialize database | 初始化数据库 +// +// Initialize database | 初始化数据库 +// + +func InitDatabaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + + l := base.NewInitDatabaseLogic(r, r.Context(), svcCtx) + err := l.InitDatabase() + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/captcha/get_captcha_handler.go b/api/internal/handler/captcha/get_captcha_handler.go new file mode 100644 index 0000000..8f23c38 --- /dev/null +++ b/api/internal/handler/captcha/get_captcha_handler.go @@ -0,0 +1,31 @@ +package captcha + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/captcha" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" +) + +// swagger:route get /api/captcha captcha GetCaptcha +// +// Get Captcha | 获取验证码 +// +// Get Captcha | 获取验证码 +// +// Responses: +// 200: CaptchaInfo + +func GetCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + + l := captcha.NewGetCaptchaLogic(r, r.Context(), svcCtx) + resp, err := l.GetCaptcha() + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/captcha/validate_captcha_handler.go b/api/internal/handler/captcha/validate_captcha_handler.go new file mode 100644 index 0000000..2beebf7 --- /dev/null +++ b/api/internal/handler/captcha/validate_captcha_handler.go @@ -0,0 +1,42 @@ +package captcha + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/captcha" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/captcha/validate captcha ValidateCaptcha +// +// Validating captcha | 验证验证码正确性 +// +// Validating captcha | 验证验证码正确性 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: ValidateCaptchaReq +// + +func ValidateCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.ValidateCaptchaReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := captcha.NewValidateCaptchaLogic(r, r.Context(), svcCtx) + err := l.ValidateCaptcha(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/department_admin/create_department_admin_handler.go b/api/internal/handler/department_admin/create_department_admin_handler.go new file mode 100644 index 0000000..f406732 --- /dev/null +++ b/api/internal/handler/department_admin/create_department_admin_handler.go @@ -0,0 +1,44 @@ +package department_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/department_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/department/create department_admin CreateDepartmentAdmin +// +// Create department | 创建部门 +// +// Create department | 创建部门 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DepartmentInfo +// +// Responses: +// 200: BaseID + +func CreateDepartmentAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DepartmentInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := department_admin.NewCreateDepartmentAdminLogic(r, r.Context(), svcCtx) + resp, err := l.CreateDepartmentAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/department_admin/delete_department_admin_handler.go b/api/internal/handler/department_admin/delete_department_admin_handler.go new file mode 100644 index 0000000..665c7ec --- /dev/null +++ b/api/internal/handler/department_admin/delete_department_admin_handler.go @@ -0,0 +1,42 @@ +package department_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/department_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route delete /api/admin/department department_admin DeleteDepartmentAdmin +// +// Delete department | 删除部门 +// +// Delete department | 删除部门 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseIDs +// + +func DeleteDepartmentAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseIDs + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := department_admin.NewDeleteDepartmentAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteDepartmentAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/department_admin/get_department_admin_handler.go b/api/internal/handler/department_admin/get_department_admin_handler.go new file mode 100644 index 0000000..f0fcc76 --- /dev/null +++ b/api/internal/handler/department_admin/get_department_admin_handler.go @@ -0,0 +1,38 @@ +package department_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/department_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/department department_admin GetDepartmentAdmin +// +// Get department | 获取部门 +// +// Get department | 获取部门 +// +// Responses: +// 200: DepartmentInfo + +func GetDepartmentAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DepartmentReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := department_admin.NewGetDepartmentAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDepartmentAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/department_admin/get_department_list_admin_handler.go b/api/internal/handler/department_admin/get_department_list_admin_handler.go new file mode 100644 index 0000000..15439d1 --- /dev/null +++ b/api/internal/handler/department_admin/get_department_list_admin_handler.go @@ -0,0 +1,38 @@ +package department_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/department_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/department/list department_admin GetDepartmentListAdmin +// +// Get department list | 获取部门列表 +// +// Get department list | 获取部门列表 +// +// Responses: +// 200: DepartmentListResp + +func GetDepartmentListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DepartmentReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := department_admin.NewGetDepartmentListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDepartmentListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/department_admin/update_department_admin_handler.go b/api/internal/handler/department_admin/update_department_admin_handler.go new file mode 100644 index 0000000..8c8b60a --- /dev/null +++ b/api/internal/handler/department_admin/update_department_admin_handler.go @@ -0,0 +1,42 @@ +package department_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/department_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/department/update department_admin UpdateDepartmentAdmin +// +// Update department info | 更新部门信息 +// +// Update department info | 更新部门信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DepartmentInfo +// + +func UpdateDepartmentAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DepartmentInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := department_admin.NewUpdateDepartmentAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateDepartmentAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/create_dictionary_admin_handler.go b/api/internal/handler/dictionary_admin/create_dictionary_admin_handler.go new file mode 100644 index 0000000..eb5d1a5 --- /dev/null +++ b/api/internal/handler/dictionary_admin/create_dictionary_admin_handler.go @@ -0,0 +1,44 @@ +package dictionary_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/dictionary/create dictionary_admin CreateDictionaryAdmin +// +// Create dictionary | 创建字典 +// +// Create dictionary | 创建字典 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DictionaryInfo +// +// Responses: +// 200: BaseID + +func CreateDictionaryAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := dictionary_admin.NewCreateDictionaryAdminLogic(r, r.Context(), svcCtx) + resp, err := l.CreateDictionaryAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/delete_dictionary_admin_handler.go b/api/internal/handler/dictionary_admin/delete_dictionary_admin_handler.go new file mode 100644 index 0000000..da90c5e --- /dev/null +++ b/api/internal/handler/dictionary_admin/delete_dictionary_admin_handler.go @@ -0,0 +1,42 @@ +package dictionary_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route delete /api/admin/dictionary dictionary_admin DeleteDictionaryAdmin +// +// Delete dictionary | 删除字典 +// +// Delete dictionary | 删除字典 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseIDs +// + +func DeleteDictionaryAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseIDs + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := dictionary_admin.NewDeleteDictionaryAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteDictionaryAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/detail/create_dictionary_detail_admin_handler.go b/api/internal/handler/dictionary_admin/detail/create_dictionary_detail_admin_handler.go new file mode 100644 index 0000000..2dc514d --- /dev/null +++ b/api/internal/handler/dictionary_admin/detail/create_dictionary_detail_admin_handler.go @@ -0,0 +1,44 @@ +package detail + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin/detail" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/dictionary/detail/create dictionary_admin/detail CreateDictionaryDetailAdmin +// +// Create dictionary Detail | 创建字典项 +// +// Create dictionary Detail | 创建字典项 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DictionaryDetailInfo +// +// Responses: +// 200: BaseID + +func CreateDictionaryDetailAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryDetailInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := detail.NewCreateDictionaryDetailAdminLogic(r, r.Context(), svcCtx) + resp, err := l.CreateDictionaryDetailAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/detail/delete_dictionary_detail_admin_handler.go b/api/internal/handler/dictionary_admin/detail/delete_dictionary_detail_admin_handler.go new file mode 100644 index 0000000..5db9c79 --- /dev/null +++ b/api/internal/handler/dictionary_admin/detail/delete_dictionary_detail_admin_handler.go @@ -0,0 +1,36 @@ +package detail + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin/detail" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route delete /api/admin/dictionary/detail dictionary_admin/detail DeleteDictionaryDetailAdmin +// +// Delete dictionary | 删除字典项(批量) +// +// Delete dictionary | 删除字典项(批量) +// + +func DeleteDictionaryDetailAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DeleteDictionaryDetailReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := detail.NewDeleteDictionaryDetailAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteDictionaryDetailAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_admin_handler.go b/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_admin_handler.go new file mode 100644 index 0000000..7ab8dfe --- /dev/null +++ b/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_admin_handler.go @@ -0,0 +1,38 @@ +package detail + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin/detail" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/dictionary/detail dictionary_admin/detail GetDictionaryDetailAdmin +// +// Get dictionary | 获取字典项 +// +// Get dictionary | 获取字典项 +// +// Responses: +// 200: DictionaryDetailInfo + +func GetDictionaryDetailAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryDetailReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := detail.NewGetDictionaryDetailAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDictionaryDetailAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_list_admin_handler.go b/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_list_admin_handler.go new file mode 100644 index 0000000..15a9135 --- /dev/null +++ b/api/internal/handler/dictionary_admin/detail/get_dictionary_detail_list_admin_handler.go @@ -0,0 +1,38 @@ +package detail + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin/detail" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/dictionary/detail/list dictionary_admin/detail GetDictionaryDetailListAdmin +// +// Get dictionary list | 获取字典项列表 +// +// Get dictionary list | 获取字典项列表 +// +// Responses: +// 200: DictionaryDetailListResp + +func GetDictionaryDetailListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryDetailReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := detail.NewGetDictionaryDetailListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDictionaryDetailListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/detail/update_dictionary_detail_admin_handler.go b/api/internal/handler/dictionary_admin/detail/update_dictionary_detail_admin_handler.go new file mode 100644 index 0000000..d7ee652 --- /dev/null +++ b/api/internal/handler/dictionary_admin/detail/update_dictionary_detail_admin_handler.go @@ -0,0 +1,42 @@ +package detail + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin/detail" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/dictionary/detail/update dictionary_admin/detail UpdateDictionaryDetailAdmin +// +// Update dictionary info | 更新字典项信息 +// +// Update dictionary info | 更新字典项信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DictionaryDetailInfo +// + +func UpdateDictionaryDetailAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryDetailInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := detail.NewUpdateDictionaryDetailAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateDictionaryDetailAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/get_dictionary_admin_handler.go b/api/internal/handler/dictionary_admin/get_dictionary_admin_handler.go new file mode 100644 index 0000000..6a3ceeb --- /dev/null +++ b/api/internal/handler/dictionary_admin/get_dictionary_admin_handler.go @@ -0,0 +1,38 @@ +package dictionary_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/dictionary dictionary_admin GetDictionaryAdmin +// +// Get dictionary | 获取字典 +// +// Get dictionary | 获取字典 +// +// Responses: +// 200: DictionaryInfo + +func GetDictionaryAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := dictionary_admin.NewGetDictionaryAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDictionaryAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/get_dictionary_list_admin_handler.go b/api/internal/handler/dictionary_admin/get_dictionary_list_admin_handler.go new file mode 100644 index 0000000..65f1386 --- /dev/null +++ b/api/internal/handler/dictionary_admin/get_dictionary_list_admin_handler.go @@ -0,0 +1,38 @@ +package dictionary_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/dictionary/list dictionary_admin GetDictionaryListAdmin +// +// Get dictionary list | 获取字典列表 +// +// Get dictionary list | 获取字典列表 +// +// Responses: +// 200: DictionaryListResp + +func GetDictionaryListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := dictionary_admin.NewGetDictionaryListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetDictionaryListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/dictionary_admin/update_dictionary_admin_handler.go b/api/internal/handler/dictionary_admin/update_dictionary_admin_handler.go new file mode 100644 index 0000000..22c2f7c --- /dev/null +++ b/api/internal/handler/dictionary_admin/update_dictionary_admin_handler.go @@ -0,0 +1,42 @@ +package dictionary_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/dictionary_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/dictionary/update dictionary_admin UpdateDictionaryAdmin +// +// Update dictionary info | 更新字典信息 +// +// Update dictionary info | 更新字典信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: DictionaryInfo +// + +func UpdateDictionaryAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DictionaryInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := dictionary_admin.NewUpdateDictionaryAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateDictionaryAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/district/get_district_children_handler.go b/api/internal/handler/district/get_district_children_handler.go new file mode 100644 index 0000000..05e67ef --- /dev/null +++ b/api/internal/handler/district/get_district_children_handler.go @@ -0,0 +1,38 @@ +package district + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/district" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/district/children district GetDistrictChildren +// +// get district children | 获取子级地址列表 +// +// get district children | 获取子级地址列表 +// +// Responses: +// 200: []*DistrictInfo + +func GetDistrictChildrenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.GetDistrictChildrenReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := district.NewGetDistrictChildrenLogic(r, r.Context(), svcCtx) + resp, err := l.GetDistrictChildren(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/district/get_district_list_handler.go b/api/internal/handler/district/get_district_list_handler.go new file mode 100644 index 0000000..5cd3587 --- /dev/null +++ b/api/internal/handler/district/get_district_list_handler.go @@ -0,0 +1,38 @@ +package district + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/district" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/district/list district GetDistrictList +// +// get district list | 获取地址列表 +// +// get district list | 获取地址列表 +// +// Responses: +// 200: []*DistrictInfo + +func GetDistrictListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.GetDistrictListReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := district.NewGetDistrictListLogic(r, r.Context(), svcCtx) + resp, err := l.GetDistrictList(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/district/get_district_name_handler.go b/api/internal/handler/district/get_district_name_handler.go new file mode 100644 index 0000000..cb4d3aa --- /dev/null +++ b/api/internal/handler/district/get_district_name_handler.go @@ -0,0 +1,38 @@ +package district + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/district" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/district/name district GetDistrictName +// +// get district name list | 获取地址名 +// +// get district name list | 获取地址名 +// +// Responses: +// 200: GetDistrictNameResp + +func GetDistrictNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.GetDistrictNameReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := district.NewGetDistrictNameLogic(r, r.Context(), svcCtx) + resp, err := l.GetDistrictName(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/district/get_district_tree_handler.go b/api/internal/handler/district/get_district_tree_handler.go new file mode 100644 index 0000000..e11a17c --- /dev/null +++ b/api/internal/handler/district/get_district_tree_handler.go @@ -0,0 +1,38 @@ +package district + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/district" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/district/tree district GetDistrictTree +// +// get district tree | 获取地址树,整棵树 +// +// get district tree | 获取地址树,整棵树 +// +// Responses: +// 200: DistrictTree + +func GetDistrictTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.DistrictReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := district.NewGetDistrictTreeLogic(r, r.Context(), svcCtx) + resp, err := l.GetDistrictTree(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/oauthprovider_admin/create_oauth_provider_admin_handler.go b/api/internal/handler/oauthprovider_admin/create_oauth_provider_admin_handler.go new file mode 100644 index 0000000..1dddeeb --- /dev/null +++ b/api/internal/handler/oauthprovider_admin/create_oauth_provider_admin_handler.go @@ -0,0 +1,42 @@ +package oauthprovider_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/oauthprovider_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/oauth_provider/create oauthprovider_admin CreateOauthProviderAdmin +// +// Create oauth provider information | 创建第三方信息 +// +// Create oauth provider information | 创建第三方信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: OauthProviderInfo +// + +func CreateOauthProviderAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthProviderInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := oauthprovider_admin.NewCreateOauthProviderAdminLogic(r, r.Context(), svcCtx) + err := l.CreateOauthProviderAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/oauthprovider_admin/delete_oauth_provider_admin_handler.go b/api/internal/handler/oauthprovider_admin/delete_oauth_provider_admin_handler.go new file mode 100644 index 0000000..cba1760 --- /dev/null +++ b/api/internal/handler/oauthprovider_admin/delete_oauth_provider_admin_handler.go @@ -0,0 +1,42 @@ +package oauthprovider_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/oauthprovider_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/oauth_provider/delete oauthprovider_admin DeleteOauthProviderAdmin +// +// Delete oauth provider information | 删除第三方信息 +// +// Delete oauth provider information | 删除第三方信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseIDs +// + +func DeleteOauthProviderAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseIDs + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := oauthprovider_admin.NewDeleteOauthProviderAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteOauthProviderAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/oauthprovider_admin/get_oauth_provider_admin_handler.go b/api/internal/handler/oauthprovider_admin/get_oauth_provider_admin_handler.go new file mode 100644 index 0000000..5774338 --- /dev/null +++ b/api/internal/handler/oauthprovider_admin/get_oauth_provider_admin_handler.go @@ -0,0 +1,38 @@ +package oauthprovider_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/oauthprovider_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/oauth_provider oauthprovider_admin GetOauthProviderAdmin +// +// Get oauth provider by Params | 根据条件获取第三方信息 +// +// Get oauth provider by Params | 根据条件获取第三方信息 +// +// Responses: +// 200: OauthProviderInfo + +func GetOauthProviderAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthProviderReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := oauthprovider_admin.NewGetOauthProviderAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetOauthProviderAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/oauthprovider_admin/get_oauth_provider_list_admin_handler.go b/api/internal/handler/oauthprovider_admin/get_oauth_provider_list_admin_handler.go new file mode 100644 index 0000000..d48c99f --- /dev/null +++ b/api/internal/handler/oauthprovider_admin/get_oauth_provider_list_admin_handler.go @@ -0,0 +1,38 @@ +package oauthprovider_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/oauthprovider_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/oauth_provider/list oauthprovider_admin GetOauthProviderListAdmin +// +// Get oauth provider list | 获取第三方信息列表 +// +// Get oauth provider list | 获取第三方信息列表 +// +// Responses: +// 200: OauthProviderListResp + +func GetOauthProviderListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthProviderReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := oauthprovider_admin.NewGetOauthProviderListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetOauthProviderListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/oauthprovider_admin/update_oauth_provider_admin_handler.go b/api/internal/handler/oauthprovider_admin/update_oauth_provider_admin_handler.go new file mode 100644 index 0000000..9293f9f --- /dev/null +++ b/api/internal/handler/oauthprovider_admin/update_oauth_provider_admin_handler.go @@ -0,0 +1,42 @@ +package oauthprovider_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/oauthprovider_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/oauth_provider/update oauthprovider_admin UpdateOauthProviderAdmin +// +// Update oauth provider information | 更新第三方信息 +// +// Update oauth provider information | 更新第三方信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: OauthProviderInfo +// + +func UpdateOauthProviderAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.OauthProviderInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := oauthprovider_admin.NewUpdateOauthProviderAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateOauthProviderAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/role_admin/create_role_admin_handler.go b/api/internal/handler/role_admin/create_role_admin_handler.go new file mode 100644 index 0000000..6020fa0 --- /dev/null +++ b/api/internal/handler/role_admin/create_role_admin_handler.go @@ -0,0 +1,42 @@ +package role_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/role_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/role/create role_admin CreateRoleAdmin +// +// Create role information | 创建角色 +// +// Create role information | 创建角色 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: RoleInfo +// + +func CreateRoleAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.RoleInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := role_admin.NewCreateRoleAdminLogic(r, r.Context(), svcCtx) + err := l.CreateRoleAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/role_admin/delete_role_admin_handler.go b/api/internal/handler/role_admin/delete_role_admin_handler.go new file mode 100644 index 0000000..63c4b16 --- /dev/null +++ b/api/internal/handler/role_admin/delete_role_admin_handler.go @@ -0,0 +1,42 @@ +package role_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/role_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route delete /api/admin/role role_admin DeleteRoleAdmin +// +// Delete role information | 删除角色信息 +// +// Delete role information | 删除角色信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseIDs +// + +func DeleteRoleAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseIDs + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := role_admin.NewDeleteRoleAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteRoleAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/role_admin/get_role_admin_handler.go b/api/internal/handler/role_admin/get_role_admin_handler.go new file mode 100644 index 0000000..843c765 --- /dev/null +++ b/api/internal/handler/role_admin/get_role_admin_handler.go @@ -0,0 +1,38 @@ +package role_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/role_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/role role_admin GetRoleAdmin +// +// Get Role | 根据条件获取角色 +// +// Get Role | 根据条件获取角色 +// +// Responses: +// 200: RoleInfo + +func GetRoleAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.RoleReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := role_admin.NewGetRoleAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetRoleAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/role_admin/get_role_list_admin_handler.go b/api/internal/handler/role_admin/get_role_list_admin_handler.go new file mode 100644 index 0000000..e619671 --- /dev/null +++ b/api/internal/handler/role_admin/get_role_list_admin_handler.go @@ -0,0 +1,38 @@ +package role_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/role_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/role/list role_admin GetRoleListAdmin +// +// Get role list | 获取角色列表 +// +// Get role list | 获取角色列表 +// +// Responses: +// 200: RoleListResp + +func GetRoleListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.RoleReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := role_admin.NewGetRoleListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetRoleListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/role_admin/update_role_admin_handler.go b/api/internal/handler/role_admin/update_role_admin_handler.go new file mode 100644 index 0000000..ce1c66b --- /dev/null +++ b/api/internal/handler/role_admin/update_role_admin_handler.go @@ -0,0 +1,42 @@ +package role_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/role_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/role/update role_admin UpdateRoleAdmin +// +// Update role information | 更新角色 +// +// Update role information | 更新角色 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: RoleInfo +// + +func UpdateRoleAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.RoleInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := role_admin.NewUpdateRoleAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateRoleAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go new file mode 100644 index 0000000..f4c80fc --- /dev/null +++ b/api/internal/handler/routes.go @@ -0,0 +1,363 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + auth "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/auth" + base "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/base" + captcha "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/captcha" + department_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/department_admin" + dictionary_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/dictionary_admin" + dictionary_admindetail "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/dictionary_admin/detail" + district "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/district" + oauthprovider_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/oauthprovider_admin" + role_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/role_admin" + token_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/token_admin" + user "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/user" + user_admin "git.noahlan.cn/n-admin/n-admin-server/api/internal/handler/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/initDatabase", + Handler: base.InitDatabaseHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/base"), + ) + + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/oauth/login", + Handler: auth.OauthLoginHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/oauth/login/byCode", + Handler: auth.OauthLoginByCodeHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/oauth/login/byPhone", + Handler: auth.OauthLoginByPhoneHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/oauth/login/callback", + Handler: auth.OauthCallbackHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/login", + Handler: auth.LoginHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/login/byCode", + Handler: auth.LoginByCodeHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/register", + Handler: auth.RegisterHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/auth"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: user_admin.CreateUserAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: user_admin.UpdateUserAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: user_admin.GetUserListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: user_admin.GetUserAdminHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/", + Handler: user_admin.DeleteUserAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/user"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodGet, + Path: "/", + Handler: user.GetCurrentUserHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/user"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: role_admin.CreateRoleAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: role_admin.UpdateRoleAdminHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/", + Handler: role_admin.DeleteRoleAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: role_admin.GetRoleListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: role_admin.GetRoleAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/role"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodGet, + Path: "/list", + Handler: token_admin.GetTokenListAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/disable", + Handler: token_admin.DisableTokenAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/token"), + ) + + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/", + Handler: captcha.GetCaptchaHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/validate", + Handler: captcha.ValidateCaptchaHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/captcha"), + ) + + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/tree", + Handler: district.GetDistrictTreeHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: district.GetDistrictListHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/children", + Handler: district.GetDistrictChildrenHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/name", + Handler: district.GetDistrictNameHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/district"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: oauthprovider_admin.CreateOauthProviderAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: oauthprovider_admin.UpdateOauthProviderAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/delete", + Handler: oauthprovider_admin.DeleteOauthProviderAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: oauthprovider_admin.GetOauthProviderListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: oauthprovider_admin.GetOauthProviderAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/oauth_provider"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: department_admin.CreateDepartmentAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: department_admin.UpdateDepartmentAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: department_admin.GetDepartmentListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: department_admin.GetDepartmentAdminHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/", + Handler: department_admin.DeleteDepartmentAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/department"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: dictionary_admin.CreateDictionaryAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: dictionary_admin.UpdateDictionaryAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: dictionary_admin.GetDictionaryListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: dictionary_admin.GetDictionaryAdminHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/", + Handler: dictionary_admin.DeleteDictionaryAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/dictionary"), + ) + + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.Authority}, + []rest.Route{ + { + Method: http.MethodPost, + Path: "/create", + Handler: dictionary_admindetail.CreateDictionaryDetailAdminHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/update", + Handler: dictionary_admindetail.UpdateDictionaryDetailAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/list", + Handler: dictionary_admindetail.GetDictionaryDetailListAdminHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/", + Handler: dictionary_admindetail.GetDictionaryDetailAdminHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/", + Handler: dictionary_admindetail.DeleteDictionaryDetailAdminHandler(serverCtx), + }, + }..., + ), + rest.WithJwt(serverCtx.Config.Auth.AccessSecret), + rest.WithPrefix("/api/admin/dictionary/detail"), + ) +} diff --git a/api/internal/handler/token_admin/disable_token_admin_handler.go b/api/internal/handler/token_admin/disable_token_admin_handler.go new file mode 100644 index 0000000..a43e494 --- /dev/null +++ b/api/internal/handler/token_admin/disable_token_admin_handler.go @@ -0,0 +1,42 @@ +package token_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/token_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/token/disable token_admin DisableTokenAdmin +// +// Disable token | 禁用凭证(强制下线) +// +// Disable token | 禁用凭证(强制下线) +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseID +// + +func DisableTokenAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseID + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := token_admin.NewDisableTokenAdminLogic(r, r.Context(), svcCtx) + err := l.DisableTokenAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/token_admin/get_token_list_admin_handler.go b/api/internal/handler/token_admin/get_token_list_admin_handler.go new file mode 100644 index 0000000..9961ca1 --- /dev/null +++ b/api/internal/handler/token_admin/get_token_list_admin_handler.go @@ -0,0 +1,38 @@ +package token_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/token_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/token/list token_admin GetTokenListAdmin +// +// Get token list | 获取凭证列表 +// +// Get token list | 获取凭证列表 +// +// Responses: +// 200: TokenListResp + +func GetTokenListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.TokenReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := token_admin.NewGetTokenListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetTokenListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/user/get_current_user_handler.go b/api/internal/handler/user/get_current_user_handler.go new file mode 100644 index 0000000..bef886b --- /dev/null +++ b/api/internal/handler/user/get_current_user_handler.go @@ -0,0 +1,31 @@ +package user + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" +) + +// swagger:route get /api/user user GetCurrentUser +// +// Get Current User | 获取当前登录用户信息 +// +// Get Current User | 获取当前登录用户信息 +// +// Responses: +// 200: UserInfo + +func GetCurrentUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + + l := user.NewGetCurrentUserLogic(r, r.Context(), svcCtx) + resp, err := l.GetCurrentUser() + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/user_admin/create_user_admin_handler.go b/api/internal/handler/user_admin/create_user_admin_handler.go new file mode 100644 index 0000000..a32a524 --- /dev/null +++ b/api/internal/handler/user_admin/create_user_admin_handler.go @@ -0,0 +1,44 @@ +package user_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/user/create user_admin CreateUserAdmin +// +// Create user | 创建用户 +// +// Create user | 创建用户 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: UserInfo +// +// Responses: +// 200: BaseID + +func CreateUserAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.UserInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := user_admin.NewCreateUserAdminLogic(r, r.Context(), svcCtx) + resp, err := l.CreateUserAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/user_admin/delete_user_admin_handler.go b/api/internal/handler/user_admin/delete_user_admin_handler.go new file mode 100644 index 0000000..0724128 --- /dev/null +++ b/api/internal/handler/user_admin/delete_user_admin_handler.go @@ -0,0 +1,42 @@ +package user_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route delete /api/admin/user user_admin DeleteUserAdmin +// +// Delete user | 删除用户 +// +// Delete user | 删除用户 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: BaseIDs +// + +func DeleteUserAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.BaseIDs + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := user_admin.NewDeleteUserAdminLogic(r, r.Context(), svcCtx) + err := l.DeleteUserAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/handler/user_admin/get_user_admin_handler.go b/api/internal/handler/user_admin/get_user_admin_handler.go new file mode 100644 index 0000000..b5346fb --- /dev/null +++ b/api/internal/handler/user_admin/get_user_admin_handler.go @@ -0,0 +1,38 @@ +package user_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/user user_admin GetUserAdmin +// +// Get user | 获取用户 +// +// Get user | 获取用户 +// +// Responses: +// 200: UserInfo + +func GetUserAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.UserReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := user_admin.NewGetUserAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetUserAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/user_admin/get_user_list_admin_handler.go b/api/internal/handler/user_admin/get_user_list_admin_handler.go new file mode 100644 index 0000000..3c085bf --- /dev/null +++ b/api/internal/handler/user_admin/get_user_list_admin_handler.go @@ -0,0 +1,38 @@ +package user_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route get /api/admin/user/list user_admin GetUserListAdmin +// +// Get user list | 获取用户列表 +// +// Get user list | 获取用户列表 +// +// Responses: +// 200: UserListResp + +func GetUserListAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.UserReq + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := user_admin.NewGetUserListAdminLogic(r, r.Context(), svcCtx) + resp, err := l.GetUserListAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, resp, err) + + } +} diff --git a/api/internal/handler/user_admin/update_user_admin_handler.go b/api/internal/handler/user_admin/update_user_admin_handler.go new file mode 100644 index 0000000..c8bd376 --- /dev/null +++ b/api/internal/handler/user_admin/update_user_admin_handler.go @@ -0,0 +1,42 @@ +package user_admin + +import ( + "net/http" + + "git.noahlan.cn/noahlan/ntool-biz/zero/statusz" + "github.com/zeromicro/go-zero/rest/httpx" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/logic/user_admin" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" +) + +// swagger:route post /api/admin/user/update user_admin UpdateUserAdmin +// +// Update user | 更新用户信息 +// +// Update user | 更新用户信息 +// +// Parameters: +// + name: body +// require: true +// in: body +// type: UserInfo +// + +func UpdateUserAdminHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + const transErr = true + var req types.UserInfo + if err := httpx.Parse(r, &req); err != nil { + statusz.ResponseHandler(r, w, transErr, nil, err) + return + } + + l := user_admin.NewUpdateUserAdminLogic(r, r.Context(), svcCtx) + err := l.UpdateUserAdmin(&req) + + statusz.ResponseHandler(r, w, transErr, nil, err) + + } +} diff --git a/api/internal/logic/auth/auth.go b/api/internal/logic/auth/auth.go new file mode 100644 index 0000000..53b6924 --- /dev/null +++ b/api/internal/logic/auth/auth.go @@ -0,0 +1,89 @@ +package auth + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/dal" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/jwt" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool/ndef" + "git.noahlan.cn/noahlan/ntool/nlog" + "net/http" + "strings" +) + +// login 登录 +func login(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request, user *core.UserInfo) (*types.LoginResp, error) { + defer func() { + if err := loginRecord(ctx, svcCtx, r, user.ID); err != nil { + nlog.Errorw("记录登录次数失败", nlog.Field("err", err)) + } + }() + + rolesBuilder := new(strings.Builder) + for i, v := range user.Roles { + rolesBuilder.WriteString(v.Code) + if i != len(user.Roles)-1 { + rolesBuilder.WriteString(ndef.CommaStr) + } + } + + // TODO 检测账号,1是否开启两步验证(已配置) 2是否需要两步验证(异地登录之类) + // 生成 token + token, err := jwt.NewJwtToken( + svcCtx.Config.Auth.AccessSecret, + user.ID, + svcCtx.Config.Auth.AccessExpire, + jwt.WithRandID(), + jwt.WithOption(jwt.KeyRoles, rolesBuilder.String()), + ) + if err != nil { + return nil, nstatus.NewBizErrWithCode(errx.JwtTokenGenerateErr) + } + + // TODO 落地Token + return &types.LoginResp{ + TwoFactorType: "", + Token: types.LoginTokenInfo{ + UID: user.ID, + TokenType: "Bearer", + AccessToken: token.AccessToken, + ExpiresAt: token.ExpiresAt, + Scope: "", + }, + }, nil +} + +// loginRecord 记录登录 +func loginRecord(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request, uid int64) error { + // 记录登录次数 + _, err := svcCtx.CoreRpc.Record(ctx, &core.LoginRecordInfo{ + UserId: uid, + LastLoginIpv4: r.RemoteAddr, + LastLoginDevice: r.Header.Get(dal.UserDeviceKey), + LastLoginUa: r.UserAgent(), + }) + if err != nil { + return err + } + return nil +} + +// register 注册用户 +func register(ctx context.Context, svcCtx *svc.ServiceContext, user *core.UserInfo) (*core.UserInfo, error) { + // 自动注册 + rpcResp, err := svcCtx.CoreRpc.CreateUser(ctx, user) + if err != nil { + return nil, err + } + dbData, err := svcCtx.CoreRpc.GetUser(ctx, &core.UserReq{ + ID: rpcResp.ID, + }) + if err != nil { + return nil, err + } + return dbData, nil +} diff --git a/api/internal/logic/auth/login_by_code_logic.go b/api/internal/logic/auth/login_by_code_logic.go new file mode 100644 index 0000000..9d612cf --- /dev/null +++ b/api/internal/logic/auth/login_by_code_logic.go @@ -0,0 +1,116 @@ +package auth + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg" + "git.noahlan.cn/noahlan/ntool/nstd/tea" + "git.noahlan.cn/noahlan/ntool/nstr" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type LoginByCodeLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewLoginByCodeLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *LoginByCodeLogic { + return &LoginByCodeLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *LoginByCodeLogic) LoginByCode(req *types.LoginReq) (resp *types.LoginResp, err error) { + if err := l.svcCtx.Captcha.Verify(req.CaptchaId, req.Captcha, true); err != nil { + return nil, err + } + var user *core.UserInfo + if nstr.IsChineseMobile(req.Subject) { + // mobile + user, err = l.getUserByPhone(req.Subject, req.Credentials) + } else if nstr.IsEmpty(req.Subject) { + // email + user, err = l.getUserByEmail(req.Subject, req.Credentials) + } else { + return nil, nstatus.NewBizErrWithCode(errx.NeedPhoneOrEmail) + } + if err != nil { + return nil, err + } + + // 登录 + resp, err = login(l.ctx, l.svcCtx, l.r, user) + if err != nil { + return nil, err + } + return +} + +func (l *LoginByCodeLogic) getUserByPhone(phone, credentials string) (*core.UserInfo, error) { + // 验证 + code, _, err := l.svcCtx.CodeCache.GetCachedCode(phone, types.CodeSourceSms, types.SmsCodeTypeLogin) + if err != nil { + return nil, nstatus.NewApiInternalErr(msg.CacheError) + } + if credentials != code { + return nil, nstatus.NewBizErrWithCode(errx.WrongCode) + } + dbData, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ + PhoneNumber: phone, + }) + if err != nil { + if nstatus.IsNotFound(err) { + dbData, err = register(l.ctx, l.svcCtx, &core.UserInfo{ + Username: phone, + PhoneNumber: &phone, + Password: l.svcCtx.Config.RegisterConf.DefaultPassword, + Nickname: tea.String("手机用户" + phone), + }) + if err != nil { + return nil, err + } + } else { + return nil, err + } + } + return dbData, nil +} + +func (l *LoginByCodeLogic) getUserByEmail(subject, credentials string) (*core.UserInfo, error) { + // 验证 + code, _, err := l.svcCtx.CodeCache.GetCachedCode(subject, types.CodeSourceEmail, types.SmsCodeTypeLogin) + if err != nil { + return nil, nstatus.NewApiInternalErr(msg.CacheError) + } + if credentials != code { + return nil, nstatus.NewBizErrWithCode(errx.WrongCode) + } + dbData, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ + Email: subject, + }) + if err != nil { + if nstatus.IsNotFound(err) { + dbData, err = register(l.ctx, l.svcCtx, &core.UserInfo{ + Username: subject, + Email: &subject, + Password: l.svcCtx.Config.RegisterConf.DefaultPassword, + Nickname: tea.String("邮箱用户" + subject), + }) + if err != nil { + return nil, err + } + } else { + return nil, err + } + } + return dbData, nil +} diff --git a/api/internal/logic/auth/login_logic.go b/api/internal/logic/auth/login_logic.go new file mode 100644 index 0000000..b51d862 --- /dev/null +++ b/api/internal/logic/auth/login_logic.go @@ -0,0 +1,65 @@ +package auth + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg" + "git.noahlan.cn/noahlan/ntool/ncrypt" + "git.noahlan.cn/noahlan/ntool/nstr" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type LoginLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewLoginLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic { + return &LoginLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) { + if err := l.svcCtx.Captcha.Verify(req.CaptchaId, req.Captcha, true); err != nil { + return nil, err + } + var phone, email, username string + if nstr.IsChineseMobile(req.Subject) { + phone = req.Subject + } else if nstr.IsEmail(req.Subject) { + email = req.Subject + } else { + username = req.Subject + } + user, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ + Username: username, + PhoneNumber: phone, + Email: email, + }) + if err != nil { + nerr := nstatus.ConvertErr(err) + if nerr.Msg == msg.ObjectNotFound { + return nil, nstatus.NewBizErrWithCode(errx.UserNotFound) + } + return nil, err + } + if !ncrypt.BcryptCheck(req.Credentials, user.Password) { + return nil, nstatus.NewBizErrWithCode(errx.WrongPassword) + } + // 登录 + resp, err = login(l.ctx, l.svcCtx, l.r, user) + if err != nil { + return nil, err + } + return +} diff --git a/api/internal/logic/auth/oauth_callback_logic.go b/api/internal/logic/auth/oauth_callback_logic.go new file mode 100644 index 0000000..492a70c --- /dev/null +++ b/api/internal/logic/auth/oauth_callback_logic.go @@ -0,0 +1,30 @@ +package auth + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type OauthCallbackLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewOauthCallbackLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *OauthCallbackLogic { + return &OauthCallbackLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OauthCallbackLogic) OauthCallback() (resp *types.LoginResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/auth/oauth_login_by_code_logic.go b/api/internal/logic/auth/oauth_login_by_code_logic.go new file mode 100644 index 0000000..2ba81d0 --- /dev/null +++ b/api/internal/logic/auth/oauth_login_by_code_logic.go @@ -0,0 +1,30 @@ +package auth + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type OauthLoginByCodeLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewOauthLoginByCodeLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *OauthLoginByCodeLogic { + return &OauthLoginByCodeLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OauthLoginByCodeLogic) OauthLoginByCode(req *types.OauthLoginByCodeReq) (resp *types.LoginResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/auth/oauth_login_by_phone_logic.go b/api/internal/logic/auth/oauth_login_by_phone_logic.go new file mode 100644 index 0000000..f416a95 --- /dev/null +++ b/api/internal/logic/auth/oauth_login_by_phone_logic.go @@ -0,0 +1,49 @@ +package auth + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + + "net/http" +) + +type OauthLoginByPhoneLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewOauthLoginByPhoneLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *OauthLoginByPhoneLogic { + return &OauthLoginByPhoneLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OauthLoginByPhoneLogic) OauthLoginByPhone(req *types.OauthLoginByPhoneCodeReq) (resp *types.LoginResp, err error) { + var phoneNumber string + rpcProvider, err := l.svcCtx.CoreRpc.GetOauthProvider(l.ctx, &core.OauthProviderReq{ + Name: req.Provider, + }) + if err != nil { + return nil, err + } + if !rpcProvider.Init { + return nil, nstatus.NewBizErrWithCode(errx.ProviderNotInit) + } + // TODO Social Helper + user, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ + PhoneNumber: phoneNumber, + }) + // 登录 + resp, err = login(l.ctx, l.svcCtx, l.r, user) + if err != nil { + return nil, err + } + return +} diff --git a/api/internal/logic/auth/oauth_login_logic.go b/api/internal/logic/auth/oauth_login_logic.go new file mode 100644 index 0000000..5e08320 --- /dev/null +++ b/api/internal/logic/auth/oauth_login_logic.go @@ -0,0 +1,30 @@ +package auth + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type OauthLoginLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewOauthLoginLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *OauthLoginLogic { + return &OauthLoginLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OauthLoginLogic) OauthLogin(req *types.OauthLoginReq) (resp *types.OauthLoginResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/auth/register_logic.go b/api/internal/logic/auth/register_logic.go new file mode 100644 index 0000000..bd2b310 --- /dev/null +++ b/api/internal/logic/auth/register_logic.go @@ -0,0 +1,73 @@ +package auth + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg" + "git.noahlan.cn/noahlan/ntool/nrandom" + "git.noahlan.cn/noahlan/ntool/nstd/tea" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type RegisterLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewRegisterLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic { + return &RegisterLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.BaseID, err error) { + if err := l.svcCtx.Captcha.Verify(req.CaptchaId, req.Captcha, true); err != nil { + return nil, err + } + // verify code + if req.Code != nil { + if req.PhoneNumber != nil && *req.PhoneNumber != "" { + code, _, err := l.svcCtx.CodeCache.GetCachedCode(*req.PhoneNumber, types.CodeSourceSms, types.SmsCodeTypeRegister) + if err != nil { + return nil, nstatus.NewApiInternalErr(msg.CacheError) + } + if *req.Code != code { + return nil, nstatus.NewBizErrWithCode(errx.WrongCode) + } + } else if req.Email != nil && *req.Email != "" { + code, _, err := l.svcCtx.CodeCache.GetCachedCode(*req.PhoneNumber, types.CodeSourceEmail, types.SmsCodeTypeRegister) + if err != nil { + return nil, nstatus.NewApiInternalErr(msg.CacheError) + } + if *req.Code != code { + return nil, nstatus.NewBizErrWithCode(errx.WrongCode) + } + } + } + + // username not empty + if req.Username == nil { + req.Username = tea.String(nrandom.RandString(6)) + } + + user, err := register(l.ctx, l.svcCtx, &core.UserInfo{ + Username: *req.Username, + PhoneNumber: req.PhoneNumber, + Email: req.Email, + Password: req.Credentials, + }) + if err != nil { + return nil, err + } + resp = &types.BaseID{ID: user.ID} + return +} diff --git a/api/internal/logic/base/init_database_logic.go b/api/internal/logic/base/init_database_logic.go new file mode 100644 index 0000000..028dae0 --- /dev/null +++ b/api/internal/logic/base/init_database_logic.go @@ -0,0 +1,31 @@ +package base + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "net/http" +) + +type InitDatabaseLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewInitDatabaseLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *InitDatabaseLogic { + return &InitDatabaseLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *InitDatabaseLogic) InitDatabase() error { + _, err := l.svcCtx.CoreRpc.InitDatabase(l.ctx, &core.Empty{}) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/captcha/get_captcha_logic.go b/api/internal/logic/captcha/get_captcha_logic.go new file mode 100644 index 0000000..891b167 --- /dev/null +++ b/api/internal/logic/captcha/get_captcha_logic.go @@ -0,0 +1,35 @@ +package captcha + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetCaptchaLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetCaptchaLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetCaptchaLogic { + return &GetCaptchaLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaInfo, err error) { + id, b64s, err := l.svcCtx.Captcha.Generate() + if err != nil { + return nil, err + } + resp = &types.CaptchaInfo{ + CaptchaId: id, + Base64: b64s, + } + return +} diff --git a/api/internal/logic/captcha/validate_captcha_logic.go b/api/internal/logic/captcha/validate_captcha_logic.go new file mode 100644 index 0000000..af5bbee --- /dev/null +++ b/api/internal/logic/captcha/validate_captcha_logic.go @@ -0,0 +1,31 @@ +package captcha + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type ValidateCaptchaLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewValidateCaptchaLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *ValidateCaptchaLogic { + return &ValidateCaptchaLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ValidateCaptchaLogic) ValidateCaptcha(req *types.ValidateCaptchaReq) error { + if err := l.svcCtx.Captcha.Verify(req.CaptchaId, req.Captcha, req.Clear); err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/department_admin/create_department_admin_logic.go b/api/internal/logic/department_admin/create_department_admin_logic.go new file mode 100644 index 0000000..2c6700e --- /dev/null +++ b/api/internal/logic/department_admin/create_department_admin_logic.go @@ -0,0 +1,40 @@ +package department_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateDepartmentAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateDepartmentAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateDepartmentAdminLogic { + return &CreateDepartmentAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateDepartmentAdminLogic) CreateDepartmentAdmin(req *types.DepartmentInfo) (resp *types.BaseID, err error) { + rpcResp, err := l.svcCtx.CoreRpc.CreateDepartment(l.ctx, &core.DepartmentInfo{ + Status: req.Status, + Name: req.Name, + LeaderId: req.LeaderId, + Remark: req.Remark, + ParentId: req.ParentId, + }) + if err != nil { + return nil, err + } + resp = &types.BaseID{ID: rpcResp.ID} + return +} diff --git a/api/internal/logic/department_admin/delete_department_admin_logic.go b/api/internal/logic/department_admin/delete_department_admin_logic.go new file mode 100644 index 0000000..4d111a7 --- /dev/null +++ b/api/internal/logic/department_admin/delete_department_admin_logic.go @@ -0,0 +1,33 @@ +package department_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteDepartmentAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteDepartmentAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDepartmentAdminLogic { + return &DeleteDepartmentAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteDepartmentAdminLogic) DeleteDepartmentAdmin(req *types.BaseIDs) error { + _, err := l.svcCtx.CoreRpc.DeleteDepartment(l.ctx, &core.IDsReq{Ids: req.Ids}) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/department_admin/get_department_admin_logic.go b/api/internal/logic/department_admin/get_department_admin_logic.go new file mode 100644 index 0000000..deb661d --- /dev/null +++ b/api/internal/logic/department_admin/get_department_admin_logic.go @@ -0,0 +1,43 @@ +package department_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDepartmentAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDepartmentAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDepartmentAdminLogic { + return &GetDepartmentAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDepartmentAdminLogic) GetDepartmentAdmin(req *types.DepartmentReq) (resp *types.DepartmentInfo, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDepartment(l.ctx, &core.DepartmentReq{ + ID: req.ID, + Name: req.Name, + LeaderId: req.LeaderId, + ParentId: req.ParentId, + WithLeader: true, + WithUser: false, + WithChildren: true, + }) + if err != nil { + return nil, err + } + + resp = l.svcCtx.Convert.ConvertDepartment(l.ctx, rpcResp) + return +} diff --git a/api/internal/logic/department_admin/get_department_list_admin_logic.go b/api/internal/logic/department_admin/get_department_list_admin_logic.go new file mode 100644 index 0000000..c864b49 --- /dev/null +++ b/api/internal/logic/department_admin/get_department_list_admin_logic.go @@ -0,0 +1,46 @@ +package department_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDepartmentListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDepartmentListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDepartmentListAdminLogic { + return &GetDepartmentListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDepartmentListAdminLogic) GetDepartmentListAdmin(req *types.DepartmentReq) (resp *types.DepartmentListResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDepartmentList(l.ctx, &core.DepartmentReq{ + ID: req.ID, + Name: req.Name, + LeaderId: req.LeaderId, + ParentId: req.ParentId, + WithLeader: true, + WithUser: false, + WithChildren: true, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = &types.DepartmentListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.DepartmentInfo, len(rpcResp.Data)), + } + return +} diff --git a/api/internal/logic/department_admin/update_department_admin_logic.go b/api/internal/logic/department_admin/update_department_admin_logic.go new file mode 100644 index 0000000..d8298ef --- /dev/null +++ b/api/internal/logic/department_admin/update_department_admin_logic.go @@ -0,0 +1,37 @@ +package department_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateDepartmentAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateDepartmentAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDepartmentAdminLogic { + return &UpdateDepartmentAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateDepartmentAdminLogic) UpdateDepartmentAdmin(req *types.DepartmentInfo) error { + var updateModel core.DepartmentInfo + _ = copier.Copy(&updateModel, req) + + _, err := l.svcCtx.CoreRpc.UpdateDepartment(l.ctx, &updateModel) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/dictionary_admin/create_dictionary_admin_logic.go b/api/internal/logic/dictionary_admin/create_dictionary_admin_logic.go new file mode 100644 index 0000000..5dac2fa --- /dev/null +++ b/api/internal/logic/dictionary_admin/create_dictionary_admin_logic.go @@ -0,0 +1,38 @@ +package dictionary_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateDictionaryAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateDictionaryAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateDictionaryAdminLogic { + return &CreateDictionaryAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateDictionaryAdminLogic) CreateDictionaryAdmin(req *types.DictionaryInfo) (resp *types.BaseID, err error) { + var rpcReq core.DictionaryInfo + _ = copier.Copy(&rpcReq, req) + + rpcResp, err := l.svcCtx.CoreRpc.CreateDictionary(l.ctx, &rpcReq) + if err != nil { + return nil, err + } + resp = &types.BaseID{ID: rpcResp.ID} + return +} diff --git a/api/internal/logic/dictionary_admin/delete_dictionary_admin_logic.go b/api/internal/logic/dictionary_admin/delete_dictionary_admin_logic.go new file mode 100644 index 0000000..529bb35 --- /dev/null +++ b/api/internal/logic/dictionary_admin/delete_dictionary_admin_logic.go @@ -0,0 +1,34 @@ +package dictionary_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteDictionaryAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteDictionaryAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryAdminLogic { + return &DeleteDictionaryAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteDictionaryAdminLogic) DeleteDictionaryAdmin(req *types.BaseIDs) error { + _, err := l.svcCtx.CoreRpc.DeleteDictionary(l.ctx, &core.IDsReq{Ids: req.Ids}) + if err != nil { + return err + } + + return nil +} diff --git a/api/internal/logic/dictionary_admin/detail/create_dictionary_detail_admin_logic.go b/api/internal/logic/dictionary_admin/detail/create_dictionary_detail_admin_logic.go new file mode 100644 index 0000000..7332a2a --- /dev/null +++ b/api/internal/logic/dictionary_admin/detail/create_dictionary_detail_admin_logic.go @@ -0,0 +1,40 @@ +package detail + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateDictionaryDetailAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateDictionaryDetailAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateDictionaryDetailAdminLogic { + return &CreateDictionaryDetailAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateDictionaryDetailAdminLogic) CreateDictionaryDetailAdmin(req *types.DictionaryDetailInfo) (resp *types.BaseID, err error) { + var rpcReq core.DictionaryDetailInfo + _ = copier.Copy(&rpcReq, req) + + rpcResp, err := l.svcCtx.CoreRpc.CreateDictionaryDetail(l.ctx, &rpcReq) + if err != nil { + return nil, err + } + resp = &types.BaseID{ID: rpcResp.ID} + return + + return +} diff --git a/api/internal/logic/dictionary_admin/detail/delete_dictionary_detail_admin_logic.go b/api/internal/logic/dictionary_admin/detail/delete_dictionary_detail_admin_logic.go new file mode 100644 index 0000000..16c2ee2 --- /dev/null +++ b/api/internal/logic/dictionary_admin/detail/delete_dictionary_detail_admin_logic.go @@ -0,0 +1,37 @@ +package detail + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteDictionaryDetailAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteDictionaryDetailAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryDetailAdminLogic { + return &DeleteDictionaryDetailAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteDictionaryDetailAdminLogic) DeleteDictionaryDetailAdmin(req *types.DeleteDictionaryDetailReq) error { + _, err := l.svcCtx.CoreRpc.DeleteDictionaryDetail(l.ctx, &core.DeleteDictionaryDetailReq{ + Ids: req.Ids, + DictId: req.DictionaryID, + }) + if err != nil { + return err + } + + return nil +} diff --git a/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_admin_logic.go b/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_admin_logic.go new file mode 100644 index 0000000..1858cc2 --- /dev/null +++ b/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_admin_logic.go @@ -0,0 +1,48 @@ +package detail + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDictionaryDetailAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDictionaryDetailAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryDetailAdminLogic { + return &GetDictionaryDetailAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictionaryDetailAdminLogic) GetDictionaryDetailAdmin(req *types.DictionaryDetailReq) (resp *types.DictionaryDetailInfo, err error) { + if req.Keyword != "" { + if req.Title == "" { + req.Title = req.Keyword + } else if req.Key == "" { + req.Key = req.Keyword + } + } + rpcResp, err := l.svcCtx.CoreRpc.GetDictionaryDetail(l.ctx, &core.DictionaryDetailReq{ + ID: req.ID, + DictId: req.DictionaryID, + Title: req.Title, + Key: req.Key, + WithDictionary: false, + }) + if err != nil { + return nil, err + } + resp = l.svcCtx.Convert.ConvertDictionaryDetail(l.ctx, rpcResp) + + return +} diff --git a/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_list_admin_logic.go b/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_list_admin_logic.go new file mode 100644 index 0000000..6db4542 --- /dev/null +++ b/api/internal/logic/dictionary_admin/detail/get_dictionary_detail_list_admin_logic.go @@ -0,0 +1,55 @@ +package detail + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDictionaryDetailListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDictionaryDetailListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryDetailListAdminLogic { + return &GetDictionaryDetailListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictionaryDetailListAdminLogic) GetDictionaryDetailListAdmin(req *types.DictionaryDetailReq) (resp *types.DictionaryDetailListResp, err error) { + if req.Keyword != "" { + if req.Title == "" { + req.Title = req.Keyword + } else if req.Key == "" { + req.Key = req.Keyword + } + } + rpcResp, err := l.svcCtx.CoreRpc.GetDictionaryDetailList(l.ctx, &core.DictionaryDetailReq{ + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + ID: req.ID, + DictId: req.DictionaryID, + Title: req.Title, + Key: req.Key, + WithDictionary: false, + }) + if err != nil { + return nil, err + } + resp = &types.DictionaryDetailListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.DictionaryDetailInfo, len(rpcResp.Data)), + } + for i, item := range rpcResp.Data { + resp.List[i] = l.svcCtx.Convert.ConvertDictionaryDetail(l.ctx, item) + } + + return +} diff --git a/api/internal/logic/dictionary_admin/detail/update_dictionary_detail_admin_logic.go b/api/internal/logic/dictionary_admin/detail/update_dictionary_detail_admin_logic.go new file mode 100644 index 0000000..1a0e6fa --- /dev/null +++ b/api/internal/logic/dictionary_admin/detail/update_dictionary_detail_admin_logic.go @@ -0,0 +1,38 @@ +package detail + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateDictionaryDetailAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateDictionaryDetailAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictionaryDetailAdminLogic { + return &UpdateDictionaryDetailAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateDictionaryDetailAdminLogic) UpdateDictionaryDetailAdmin(req *types.DictionaryDetailInfo) error { + var rpcReq core.DictionaryDetailInfo + _ = copier.Copy(&rpcReq, req) + + _, err := l.svcCtx.CoreRpc.UpdateDictionaryDetail(l.ctx, &rpcReq) + if err != nil { + return err + } + + return nil +} diff --git a/api/internal/logic/dictionary_admin/get_dictionary_admin_logic.go b/api/internal/logic/dictionary_admin/get_dictionary_admin_logic.go new file mode 100644 index 0000000..575d488 --- /dev/null +++ b/api/internal/logic/dictionary_admin/get_dictionary_admin_logic.go @@ -0,0 +1,40 @@ +package dictionary_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDictionaryAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDictionaryAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryAdminLogic { + return &GetDictionaryAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictionaryAdminLogic) GetDictionaryAdmin(req *types.DictionaryReq) (resp *types.DictionaryInfo, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDictionary(l.ctx, &core.DictionaryReq{ + ID: req.ID, + Name: req.Name, + Title: req.Title, + WithDetails: false, + Page: nil, + }) + if err != nil { + return nil, err + } + resp = l.svcCtx.Convert.ConvertDictionary(l.ctx, rpcResp) + return +} diff --git a/api/internal/logic/dictionary_admin/get_dictionary_list_admin_logic.go b/api/internal/logic/dictionary_admin/get_dictionary_list_admin_logic.go new file mode 100644 index 0000000..49129a0 --- /dev/null +++ b/api/internal/logic/dictionary_admin/get_dictionary_list_admin_logic.go @@ -0,0 +1,47 @@ +package dictionary_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDictionaryListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDictionaryListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryListAdminLogic { + return &GetDictionaryListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDictionaryListAdminLogic) GetDictionaryListAdmin(req *types.DictionaryReq) (resp *types.DictionaryListResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDictionaryList(l.ctx, &core.DictionaryReq{ + ID: req.ID, + Name: req.Name, + Title: req.Title, + WithDetails: false, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = &types.DictionaryListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.DictionaryInfo, len(rpcResp.Data)), + } + for i, item := range rpcResp.Data { + resp.List[i] = l.svcCtx.Convert.ConvertDictionary(l.ctx, item) + } + + return +} diff --git a/api/internal/logic/dictionary_admin/update_dictionary_admin_logic.go b/api/internal/logic/dictionary_admin/update_dictionary_admin_logic.go new file mode 100644 index 0000000..ff80f6c --- /dev/null +++ b/api/internal/logic/dictionary_admin/update_dictionary_admin_logic.go @@ -0,0 +1,38 @@ +package dictionary_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateDictionaryAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateDictionaryAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictionaryAdminLogic { + return &UpdateDictionaryAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateDictionaryAdminLogic) UpdateDictionaryAdmin(req *types.DictionaryInfo) error { + var rpcReq core.DictionaryInfo + _ = copier.Copy(&rpcReq, req) + + _, err := l.svcCtx.CoreRpc.UpdateDictionary(l.ctx, &rpcReq) + if err != nil { + return err + } + + return nil +} diff --git a/api/internal/logic/district/get_district_children_logic.go b/api/internal/logic/district/get_district_children_logic.go new file mode 100644 index 0000000..e223d53 --- /dev/null +++ b/api/internal/logic/district/get_district_children_logic.go @@ -0,0 +1,41 @@ +package district + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "net/http" +) + +type GetDistrictChildrenLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDistrictChildrenLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictChildrenLogic { + return &GetDistrictChildrenLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDistrictChildrenLogic) GetDistrictChildren(req *types.GetDistrictChildrenReq) (resp []*types.DistrictInfo, err error) { + rpcReq := &core.DistrictReq{ParentCode: req.ParentCode, QueryType: core.DistrictQueryType_Children} + if req.ParentCode == "" { + rpcReq.Level = 1 + } + rpcResp, err := l.svcCtx.CoreRpc.GetDistrictList(l.ctx, rpcReq) + if err != nil { + return nil, err + } + resp = make([]*types.DistrictInfo, len(rpcResp.Data)) + + for i, item := range rpcResp.Data { + resp[i] = l.svcCtx.Convert.ConvertDistrict(l.ctx, item) + } + return +} diff --git a/api/internal/logic/district/get_district_list_logic.go b/api/internal/logic/district/get_district_list_logic.go new file mode 100644 index 0000000..77a2caf --- /dev/null +++ b/api/internal/logic/district/get_district_list_logic.go @@ -0,0 +1,46 @@ +package district + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "net/http" +) + +type GetDistrictListLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDistrictListLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictListLogic { + return &GetDistrictListLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDistrictListLogic) GetDistrictList(req *types.GetDistrictListReq) (resp []*types.DistrictInfo, err error) { + rpcReq := &core.DistrictReq{ + Province: req.Province, + City: req.City, + Area: req.Area, + Street: req.Street, + Level: req.Level, + Name: req.Name, + } + list, err := l.svcCtx.CoreRpc.GetDistrictList(l.ctx, rpcReq) + if err != nil { + return nil, err + } + resp = make([]*types.DistrictInfo, len(list.Data)) + + for i, item := range list.Data { + resp[i] = l.svcCtx.Convert.ConvertDistrict(l.ctx, item) + } + + return +} diff --git a/api/internal/logic/district/get_district_name_logic.go b/api/internal/logic/district/get_district_name_logic.go new file mode 100644 index 0000000..67a20e1 --- /dev/null +++ b/api/internal/logic/district/get_district_name_logic.go @@ -0,0 +1,41 @@ +package district + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDistrictNameLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDistrictNameLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictNameLogic { + return &GetDistrictNameLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDistrictNameLogic) GetDistrictName(req *types.GetDistrictNameReq) (resp *types.GetDistrictNameResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDistrictName(l.ctx, &core.GetDistrictNameReq{ + Code: req.Code, + Separator: req.Separator, + }) + if err != nil { + return nil, err + } + resp = &types.GetDistrictNameResp{ + Code: rpcResp.Code, + Name: rpcResp.Name, + NameList: rpcResp.NameList, + } + return +} diff --git a/api/internal/logic/district/get_district_tree_logic.go b/api/internal/logic/district/get_district_tree_logic.go new file mode 100644 index 0000000..0976e39 --- /dev/null +++ b/api/internal/logic/district/get_district_tree_logic.go @@ -0,0 +1,47 @@ +package district + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetDistrictTreeLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetDistrictTreeLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictTreeLogic { + return &GetDistrictTreeLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetDistrictTreeLogic) GetDistrictTree(req *types.DistrictReq) (resp *types.DistrictTree, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetDistrictTree(l.ctx, &core.DistrictCodeReq{Code: req.Code}) + if err != nil { + return nil, err + } + resp = &types.DistrictTree{ + Tree: make([]*types.DistrictInfo, len(rpcResp.Tree)), + } + l.transTree(resp.Tree, rpcResp.Tree) + return +} + +func (l *GetDistrictTreeLogic) transTree(tree []*types.DistrictInfo, data []*core.DistrictInfo) { + for i, info := range data { + tmpInfo := l.svcCtx.Convert.ConvertDistrict(l.ctx, info) + if len(info.Children) > 0 { + l.transTree(tmpInfo.Children, info.Children) + } + tree[i] = tmpInfo + } +} diff --git a/api/internal/logic/oauthprovider_admin/create_oauth_provider_admin_logic.go b/api/internal/logic/oauthprovider_admin/create_oauth_provider_admin_logic.go new file mode 100644 index 0000000..70f684b --- /dev/null +++ b/api/internal/logic/oauthprovider_admin/create_oauth_provider_admin_logic.go @@ -0,0 +1,39 @@ +package oauthprovider_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateOauthProviderAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateOauthProviderAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateOauthProviderAdminLogic { + return &CreateOauthProviderAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateOauthProviderAdminLogic) CreateOauthProviderAdmin(req *types.OauthProviderInfo) error { + var rpcReq core.OauthProviderInfo + _ = copier.Copy(&rpcReq, req) + rpcReq.System = false + rpcReq.Init = true + + _, err := l.svcCtx.CoreRpc.CreateOauthProvider(l.ctx, &rpcReq) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/oauthprovider_admin/delete_oauth_provider_admin_logic.go b/api/internal/logic/oauthprovider_admin/delete_oauth_provider_admin_logic.go new file mode 100644 index 0000000..0af2398 --- /dev/null +++ b/api/internal/logic/oauthprovider_admin/delete_oauth_provider_admin_logic.go @@ -0,0 +1,33 @@ +package oauthprovider_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteOauthProviderAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteOauthProviderAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOauthProviderAdminLogic { + return &DeleteOauthProviderAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteOauthProviderAdminLogic) DeleteOauthProviderAdmin(req *types.BaseIDs) error { + _, err := l.svcCtx.CoreRpc.DeleteOauthProvider(l.ctx, &core.IDsReq{Ids: req.Ids}) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/oauthprovider_admin/get_oauth_provider_admin_logic.go b/api/internal/logic/oauthprovider_admin/get_oauth_provider_admin_logic.go new file mode 100644 index 0000000..7f93b8b --- /dev/null +++ b/api/internal/logic/oauthprovider_admin/get_oauth_provider_admin_logic.go @@ -0,0 +1,40 @@ +package oauthprovider_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetOauthProviderAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetOauthProviderAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetOauthProviderAdminLogic { + return &GetOauthProviderAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetOauthProviderAdminLogic) GetOauthProviderAdmin(req *types.OauthProviderReq) (resp *types.OauthProviderInfo, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetOauthProvider(l.ctx, &core.OauthProviderReq{ + ID: req.ID, + Name: req.Name, + ClientId: req.ClientId, + System: req.System, + Init: req.Init, + }) + if err != nil { + return nil, err + } + resp = l.svcCtx.Convert.ConvertOAuthProvider(l.ctx, rpcResp) + return +} diff --git a/api/internal/logic/oauthprovider_admin/get_oauth_provider_list_admin_logic.go b/api/internal/logic/oauthprovider_admin/get_oauth_provider_list_admin_logic.go new file mode 100644 index 0000000..4c06409 --- /dev/null +++ b/api/internal/logic/oauthprovider_admin/get_oauth_provider_list_admin_logic.go @@ -0,0 +1,47 @@ +package oauthprovider_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetOauthProviderListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetOauthProviderListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetOauthProviderListAdminLogic { + return &GetOauthProviderListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetOauthProviderListAdminLogic) GetOauthProviderListAdmin(req *types.OauthProviderReq) (resp *types.OauthProviderListResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetOauthProviderList(l.ctx, &core.OauthProviderReq{ + ID: req.ID, + Name: req.Name, + ClientId: req.ClientId, + System: req.System, + Init: req.Init, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = &types.OauthProviderListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.OauthProviderInfo, len(rpcResp.Data)), + } + for i, item := range rpcResp.Data { + resp.List[i] = l.svcCtx.Convert.ConvertOAuthProvider(l.ctx, item) + } + return +} diff --git a/api/internal/logic/oauthprovider_admin/update_oauth_provider_admin_logic.go b/api/internal/logic/oauthprovider_admin/update_oauth_provider_admin_logic.go new file mode 100644 index 0000000..ee1ee76 --- /dev/null +++ b/api/internal/logic/oauthprovider_admin/update_oauth_provider_admin_logic.go @@ -0,0 +1,39 @@ +package oauthprovider_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateOauthProviderAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateOauthProviderAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOauthProviderAdminLogic { + return &UpdateOauthProviderAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateOauthProviderAdminLogic) UpdateOauthProviderAdmin(req *types.OauthProviderInfo) error { + var rpcReq core.OauthProviderInfo + _ = copier.Copy(&rpcReq, req) + rpcReq.Init = true + + _, err := l.svcCtx.CoreRpc.UpdateOauthProvider(l.ctx, &rpcReq) + if err != nil { + return err + } + + return nil +} diff --git a/api/internal/logic/role_admin/create_role_admin_logic.go b/api/internal/logic/role_admin/create_role_admin_logic.go new file mode 100644 index 0000000..aa0c5fe --- /dev/null +++ b/api/internal/logic/role_admin/create_role_admin_logic.go @@ -0,0 +1,37 @@ +package role_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateRoleAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateRoleAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleAdminLogic { + return &CreateRoleAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateRoleAdminLogic) CreateRoleAdmin(req *types.RoleInfo) error { + var rpcReq core.RoleInfo + _ = copier.Copy(&rpcReq, req) + + _, err := l.svcCtx.CoreRpc.CreateRole(l.ctx, &rpcReq) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/role_admin/delete_role_admin_logic.go b/api/internal/logic/role_admin/delete_role_admin_logic.go new file mode 100644 index 0000000..37eb21f --- /dev/null +++ b/api/internal/logic/role_admin/delete_role_admin_logic.go @@ -0,0 +1,33 @@ +package role_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteRoleAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteRoleAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleAdminLogic { + return &DeleteRoleAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteRoleAdminLogic) DeleteRoleAdmin(req *types.BaseIDs) error { + _, err := l.svcCtx.CoreRpc.DeleteRole(l.ctx, &core.IDsReq{Ids: req.Ids}) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/role_admin/get_role_admin_logic.go b/api/internal/logic/role_admin/get_role_admin_logic.go new file mode 100644 index 0000000..e1e0b0d --- /dev/null +++ b/api/internal/logic/role_admin/get_role_admin_logic.go @@ -0,0 +1,41 @@ +package role_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetRoleAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetRoleAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleAdminLogic { + return &GetRoleAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetRoleAdminLogic) GetRoleAdmin(req *types.RoleReq) (resp *types.RoleInfo, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetRole(l.ctx, &core.RoleReq{ + ID: req.ID, + Name: req.Name, + Code: req.Code, + WithUser: false, + Page: nil, + }) + if err != nil { + return nil, err + } + + resp = l.svcCtx.Convert.ConvertRole(l.ctx, rpcResp) + return +} diff --git a/api/internal/logic/role_admin/get_role_list_admin_logic.go b/api/internal/logic/role_admin/get_role_list_admin_logic.go new file mode 100644 index 0000000..96e0fd2 --- /dev/null +++ b/api/internal/logic/role_admin/get_role_list_admin_logic.go @@ -0,0 +1,44 @@ +package role_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "net/http" +) + +type GetRoleListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetRoleListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleListAdminLogic { + return &GetRoleListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetRoleListAdminLogic) GetRoleListAdmin(req *types.RoleReq) (resp *types.RoleListResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetRoleList(l.ctx, &core.RoleReq{ + ID: req.ID, + Name: req.Name, + Code: req.Code, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = &types.RoleListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.RoleInfo, len(rpcResp.Data)), + } + for i, item := range rpcResp.Data { + resp.List[i] = l.svcCtx.Convert.ConvertRole(l.ctx, item) + } + return +} diff --git a/api/internal/logic/role_admin/update_role_admin_logic.go b/api/internal/logic/role_admin/update_role_admin_logic.go new file mode 100644 index 0000000..7753b46 --- /dev/null +++ b/api/internal/logic/role_admin/update_role_admin_logic.go @@ -0,0 +1,37 @@ +package role_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateRoleAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateRoleAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleAdminLogic { + return &UpdateRoleAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateRoleAdminLogic) UpdateRoleAdmin(req *types.RoleInfo) error { + var rpcReq core.RoleInfo + _ = copier.Copy(&rpcReq, req) + + _, err := l.svcCtx.CoreRpc.UpdateRole(l.ctx, &rpcReq) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/token_admin/disable_token_admin_logic.go b/api/internal/logic/token_admin/disable_token_admin_logic.go new file mode 100644 index 0000000..612c7b7 --- /dev/null +++ b/api/internal/logic/token_admin/disable_token_admin_logic.go @@ -0,0 +1,30 @@ +package token_admin + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DisableTokenAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDisableTokenAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DisableTokenAdminLogic { + return &DisableTokenAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DisableTokenAdminLogic) DisableTokenAdmin(req *types.BaseID) error { + // todo: add your logic here and delete this line + + return nil +} diff --git a/api/internal/logic/token_admin/get_token_list_admin_logic.go b/api/internal/logic/token_admin/get_token_list_admin_logic.go new file mode 100644 index 0000000..50b668a --- /dev/null +++ b/api/internal/logic/token_admin/get_token_list_admin_logic.go @@ -0,0 +1,30 @@ +package token_admin + +import ( + "context" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetTokenListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetTokenListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetTokenListAdminLogic { + return &GetTokenListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetTokenListAdminLogic) GetTokenListAdmin(req *types.TokenReq) (resp *types.TokenListResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user/get_current_user_logic.go b/api/internal/logic/user/get_current_user_logic.go new file mode 100644 index 0000000..74c1af8 --- /dev/null +++ b/api/internal/logic/user/get_current_user_logic.go @@ -0,0 +1,42 @@ +package user + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "git.noahlan.cn/noahlan/ntool-biz/core/jwt" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg" + + "net/http" +) + +type GetCurrentUserLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetCurrentUserLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetCurrentUserLogic { + return &GetCurrentUserLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetCurrentUserLogic) GetCurrentUser() (resp *types.UserInfo, err error) { + uid := jwt.GetCurrentUserId(l.ctx) + if uid == 0 { + return nil, nstatus.NewApiUnauthorizedErr(msg.Msg(errx.StatusUnauthorized)) + } + rpcResp, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ID: uid}) + if err != nil { + return nil, err + } + resp = l.svcCtx.Convert.ConvertUser(l.ctx, rpcResp) + + return +} diff --git a/api/internal/logic/user_admin/create_user_admin_logic.go b/api/internal/logic/user_admin/create_user_admin_logic.go new file mode 100644 index 0000000..697e9f9 --- /dev/null +++ b/api/internal/logic/user_admin/create_user_admin_logic.go @@ -0,0 +1,43 @@ +package user_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type CreateUserAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewCreateUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserAdminLogic { + return &CreateUserAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateUserAdminLogic) CreateUserAdmin(req *types.UserInfo) (resp *types.BaseID, err error) { + var rpcReq core.UserInfo + _ = copier.Copy(&rpcReq, req) + rpcReq.ID = 0 + rpcReq.CreatedAt = "" + rpcReq.UpdatedAt = "" + rpcReq.Status = "" + + rpcResp, err := l.svcCtx.CoreRpc.CreateUser(l.ctx, &rpcReq) + if err != nil { + return nil, err + } + + resp = &types.BaseID{ID: rpcResp.ID} + return +} diff --git a/api/internal/logic/user_admin/delete_user_admin_logic.go b/api/internal/logic/user_admin/delete_user_admin_logic.go new file mode 100644 index 0000000..f55ad40 --- /dev/null +++ b/api/internal/logic/user_admin/delete_user_admin_logic.go @@ -0,0 +1,33 @@ +package user_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type DeleteUserAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewDeleteUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserAdminLogic { + return &DeleteUserAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteUserAdminLogic) DeleteUserAdmin(req *types.BaseIDs) error { + _, err := l.svcCtx.CoreRpc.DeleteUser(l.ctx, &core.IDsReq{Ids: req.Ids}) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/logic/user_admin/get_user_admin_logic.go b/api/internal/logic/user_admin/get_user_admin_logic.go new file mode 100644 index 0000000..f178eba --- /dev/null +++ b/api/internal/logic/user_admin/get_user_admin_logic.go @@ -0,0 +1,46 @@ +package user_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type GetUserAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetUserAdminLogic { + return &GetUserAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetUserAdminLogic) GetUserAdmin(req *types.UserReq) (resp *types.UserInfo, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetUser(l.ctx, &core.UserReq{ + ID: req.ID, + Username: req.Username, + PhoneNumber: req.PhoneNumber, + Email: req.Email, + WithRole: false, + WithSocial: false, + WithDepartment: false, + WithToken: false, + WithLoginRecord: true, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = l.svcCtx.Convert.ConvertUser(l.ctx, rpcResp) + + return +} diff --git a/api/internal/logic/user_admin/get_user_list_admin_logic.go b/api/internal/logic/user_admin/get_user_list_admin_logic.go new file mode 100644 index 0000000..60e3b77 --- /dev/null +++ b/api/internal/logic/user_admin/get_user_list_admin_logic.go @@ -0,0 +1,50 @@ +package user_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "net/http" +) + +type GetUserListAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewGetUserListAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListAdminLogic { + return &GetUserListAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetUserListAdminLogic) GetUserListAdmin(req *types.UserReq) (resp *types.UserListResp, err error) { + rpcResp, err := l.svcCtx.CoreRpc.GetUserList(l.ctx, &core.UserReq{ + ID: req.ID, + Username: req.Username, + PhoneNumber: req.PhoneNumber, + Email: req.Email, + WithRole: false, + WithSocial: false, + WithDepartment: false, + WithToken: false, + WithLoginRecord: true, + Page: l.svcCtx.Convert.ConvertPaginationRpc(req.Pagination), + }) + if err != nil { + return nil, err + } + resp = &types.UserListResp{ + Page: l.svcCtx.Convert.ConvertPaginationApi(rpcResp.Page), + List: make([]*types.UserInfo, len(rpcResp.Data)), + } + for i, item := range rpcResp.Data { + resp.List[i] = l.svcCtx.Convert.ConvertUser(l.ctx, item) + } + return +} diff --git a/api/internal/logic/user_admin/update_user_admin_logic.go b/api/internal/logic/user_admin/update_user_admin_logic.go new file mode 100644 index 0000000..01f23cf --- /dev/null +++ b/api/internal/logic/user_admin/update_user_admin_logic.go @@ -0,0 +1,37 @@ +package user_admin + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + + "net/http" +) + +type UpdateUserAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + r *http.Request +} + +func NewUpdateUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserAdminLogic { + return &UpdateUserAdminLogic{ + r: r, + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateUserAdminLogic) UpdateUserAdmin(req *types.UserInfo) error { + _, err := l.svcCtx.CoreRpc.UpdateUser(l.ctx, &core.UserInfo{ + ID: req.ID, + Nickname: req.Nickname, + Metas: req.Metas, + }) + if err != nil { + return err + } + return nil +} diff --git a/api/internal/middleware/authority_middleware.go b/api/internal/middleware/authority_middleware.go new file mode 100644 index 0000000..48c4ca2 --- /dev/null +++ b/api/internal/middleware/authority_middleware.go @@ -0,0 +1,47 @@ +package middleware + +import ( + "github.com/casbin/casbin/v2" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/stores/redis" + "net/http" + "strings" +) + +type AuthorityMiddleware struct { + Cbn *casbin.Enforcer + Rds *redis.Redis +} + +func NewAuthorityMiddleware() *AuthorityMiddleware { + return &AuthorityMiddleware{} +} + +func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + //obj := r.URL.Path + //act := r.Method + next(w, r) + } +} + +func (m *AuthorityMiddleware) batchCheck(cbn *casbin.Enforcer, roles, act, obj string) bool { + var checkReq [][]any + for _, v := range strings.Split(roles, ",") { + checkReq = append(checkReq, []any{v, obj, act}) + } + + result, err := cbn.BatchEnforce(checkReq) + if err != nil { + logx.Errorw("Casbin enforce error", logx.Field("detail", err.Error())) + return false + } + + for _, v := range result { + if v { + return true + } + } + + return false +} diff --git a/api/internal/svc/cache/code_cache.go b/api/internal/svc/cache/code_cache.go new file mode 100644 index 0000000..8c521f6 --- /dev/null +++ b/api/internal/svc/cache/code_cache.go @@ -0,0 +1,65 @@ +package cache + +import ( + "errors" + "fmt" + "git.noahlan.cn/n-admin/n-admin-server/dal" + "git.noahlan.cn/noahlan/ntool/nlog" + "github.com/zeromicro/go-zero/core/stores/cache" + "github.com/zeromicro/go-zero/core/stores/redis" + "time" +) + +type ( + CodeCache interface { + // GetCachedCode 获取缓存的Code和ttl + // subject: 主体 + // source: 来源 + // typ: 类型 + GetCachedCode(subject, source, typ string) (string, int, error) + // CacheCode 缓存Code + CacheCode(code, subject, source, typ string, expiresIn int) error + // DelCode 移除subject与用途对应的code + DelCode(subject, source, typ string) error + } + codeCacheMgr struct { + cache cache.Cache + redis *redis.Redis + } +) + +func NewCodeCacheMgr(cache cache.Cache, rds *redis.Redis) CodeCache { + return &codeCacheMgr{cache: cache, redis: rds} +} + +func (m *codeCacheMgr) GetCachedCode(subject, source, typ string) (string, int, error) { + var code string + key := fmt.Sprintf("%s_CODE:%s:%s", source, typ, subject) + err := m.cache.Get(key, &code) + if err != nil && !errors.Is(err, dal.ErrCacheNotFound) { + nlog.Errorw("[CodeCache] get code err", nlog.Field("err", err.Error())) + return "", 0, err + } + ttl, _ := m.redis.Ttl(key) + return code, ttl, nil +} + +func (m *codeCacheMgr) CacheCode(code, subject, usage, typ string, expiresIn int) error { + key := fmt.Sprintf("%s_CODE:%s:%s", usage, typ, subject) + err := m.cache.SetWithExpire(key, code, time.Second*time.Duration(expiresIn)) + if err != nil { + nlog.Errorw("[CodeCache] caching err", nlog.Field("err", err.Error())) + return err + } + return nil +} + +func (m *codeCacheMgr) DelCode(subject, usage, typ string) error { + key := fmt.Sprintf("%s_CODE:%s:%s", usage, typ, subject) + err := m.cache.Del(key) + if err != nil { + nlog.Errorw("[CodeCache] delete key err", nlog.Field("err", err.Error())) + return err + } + return nil +} diff --git a/api/internal/svc/captcha/captcha.go b/api/internal/svc/captcha/captcha.go new file mode 100644 index 0000000..2e7c22c --- /dev/null +++ b/api/internal/svc/captcha/captcha.go @@ -0,0 +1,37 @@ +package captcha + +import ( + "git.noahlan.cn/n-admin/n-admin-server/dal/errx" + "git.noahlan.cn/noahlan/ntool-biz/core/captcha" + "git.noahlan.cn/noahlan/ntool-biz/core/config" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "github.com/mojocn/base64Captcha" + "strings" +) + +type CaptchaMgr struct { + Captcha *base64Captcha.Captcha +} + +func NewCaptchaManager(config captcha.Config, redisConf config.RedisConf) *CaptchaMgr { + return &CaptchaMgr{ + Captcha: captcha.MustNewRedisCaptcha(config, redisConf), + } +} + +func (c *CaptchaMgr) Verify(captchaId, captchaStr string, clear bool) error { + if captchaId != "" && captchaStr != "" { + if ok := c.Captcha.Verify("CAPTCHA_"+captchaId, strings.ToLower(captchaStr), clear); !ok { + return nstatus.NewBizErrWithCode(errx.InvalidCaptchaErr) + } + } + return nil +} + +func (c *CaptchaMgr) Generate() (id, b64s string, err error) { + id, b64s, err = c.Captcha.Generate() + if err != nil { + return "", "", nstatus.NewBizErrWithCode(errx.CaptchaGenerateErr) + } + return id, b64s, nil +} diff --git a/api/internal/svc/convert.go b/api/internal/svc/convert.go new file mode 100644 index 0000000..c0c34a4 --- /dev/null +++ b/api/internal/svc/convert.go @@ -0,0 +1,219 @@ +package svc + +import ( + "context" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/types" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" + "github.com/jinzhu/copier" +) + +type Convert struct { + svcCtx *ServiceContext +} + +func NewConvert(svcCtx *ServiceContext) *Convert { + return &Convert{ + svcCtx: svcCtx, + } +} + +func (c *Convert) ConvertPaginationRpc(page *types.Pagination) *core.Pagination { + if page == nil { + return nil + } + return &core.Pagination{ + Size: page.Size, + Total: page.Total, + Current: page.Current, + } +} + +func (c *Convert) ConvertPaginationApi(page *core.Pagination) *types.Pagination { + if page == nil { + return nil + } + return &types.Pagination{ + Size: page.Size, + Current: page.Current, + Total: page.Total, + } +} + +func (c *Convert) ConvertRole(_ context.Context, v *core.RoleInfo) *types.RoleInfo { + if v == nil { + return nil + } + var tmp types.RoleInfo + _ = copier.Copy(&tmp, v) + return &tmp +} + +func (c *Convert) ConvertUser(ctx context.Context, v *core.UserInfo) *types.UserInfo { + if v == nil { + return nil + } + var tmp types.UserInfo + _ = copier.Copy(&tmp, v) + tmp.Password = "***" + + // Metadata + if len(v.Metas) > 0 { + // 导出meta数据 + metaMap := make(map[string]string) + for key, val := range v.Metas { + metaMap[key] = val + } + tmp.Metas = metaMap + } + + // Relationship + if len(v.Roles) > 0 { + tmp.Roles = make([]string, len(v.Roles)) + for i, item := range v.Roles { + tmp.Roles[i] = item.Code + } + } + if v.LoginRecord != nil { + tmp.LoginRecord = c.ConvertLoginRecord(ctx, v.LoginRecord) + } + + //if len(v.Departments) > 0 { + // tmp.Departments = make([]*core.DepartmentInfo, len(v.Edges.Departments)) + // for i, item := range v.Edges.Departments { + // tmp.Departments[i] = c.ConvertDepartment(ctx, item) + // } + //} + //if len(v.Token) > 0 { + // tmp.Tokens = make([]*core.TokenInfo, len(v.Edges.Token)) + // for i, item := range v.Edges.Token { + // tmp.Tokens[i] = c.ConvertToken(ctx, item) + // } + //} + //if len(v.Socials) > 0 { + // tmp.Socials = make([]*core.UserSocialInfo, len(v.Edges.Socials)) + // for i, item := range v.Edges.Socials { + // tmp.Socials[i] = c.ConvertUserSocial(ctx, item) + // } + //} + + return &tmp +} + +func (c *Convert) ConvertToken(_ context.Context, v *core.TokenInfo) *types.TokenInfo { + if v == nil { + return nil + } + var tmp types.TokenInfo + _ = copier.Copy(&tmp, v) + + //if v.User != nil { + // tmp.User = c.ConvertUser(ctx, v.Edges.User) + //} + + return &tmp +} + +func (c *Convert) ConvertUserSocial(_ context.Context, v *core.UserSocialInfo) *types.UserSocialInfo { + if v == nil { + return nil + } + var tmp types.UserSocialInfo + _ = copier.Copy(&tmp, v) + + //if v.User != nil { + // tmp.User = c.ConvertUser(ctx, v.Edges.User) + //} + + return &tmp +} + +func (c *Convert) ConvertLoginRecord(_ context.Context, v *core.LoginRecordInfo) *types.UserLoginRecordInfo { + if v == nil { + return nil + } + var tmp types.UserLoginRecordInfo + _ = copier.Copy(&tmp, v) + + return &tmp +} + +func (c *Convert) ConvertDepartment(ctx context.Context, v *core.DepartmentInfo) *types.DepartmentInfo { + if v == nil { + return nil + } + var tmp types.DepartmentInfo + _ = copier.Copy(&tmp, v) + + // relationship + if v.Parent != nil { + tmp.Parent = c.ConvertDepartment(ctx, v.Parent) + } + if len(v.Children) > 0 { + tmp.Children = make([]*types.DepartmentInfo, len(v.Children)) + for i, item := range v.Children { + tmp.Children[i] = c.ConvertDepartment(ctx, item) + } + } + //if len(v.Edges.Users) > 0 { + // tmp.Users = make([]*core.UserInfo, len(v.Edges.Users)) + // for i, item := range v.Edges.Users { + // tmp.Users[i] = c.ConvertUser(ctx, item) + // } + //} + if v.Leader != nil { + tmp.Leader = c.ConvertUser(ctx, v.Leader) + } + + return &tmp +} + +func (c *Convert) ConvertOAuthProvider(_ context.Context, v *core.OauthProviderInfo) *types.OauthProviderInfo { + if v == nil { + return nil + } + var tmp types.OauthProviderInfo + _ = copier.Copy(&tmp, v) + + return &tmp +} + +func (c *Convert) ConvertDistrict(_ context.Context, v *core.DistrictInfo) *types.DistrictInfo { + if v == nil { + return nil + } + var tmp types.DistrictInfo + _ = copier.Copy(&tmp, v) + tmp.Children = make([]*types.DistrictInfo, len(v.Children)) + + return &tmp +} + +func (c *Convert) ConvertDictionary(ctx context.Context, v *core.DictionaryInfo) *types.DictionaryInfo { + if v == nil { + return nil + } + var tmp types.DictionaryInfo + _ = copier.Copy(&tmp, v) + + if len(v.Details) > 0 { + tmp.Details = make([]*types.DictionaryDetailInfo, len(v.Details)) + for i, item := range v.Details { + tmp.Details[i] = c.ConvertDictionaryDetail(ctx, item) + } + } + return &tmp +} + +func (c *Convert) ConvertDictionaryDetail(ctx context.Context, v *core.DictionaryDetailInfo) *types.DictionaryDetailInfo { + if v == nil { + return nil + } + var tmp types.DictionaryDetailInfo + _ = copier.Copy(&tmp, v) + + // relationship + if v.Dictionary != nil { + tmp.Dictionary = c.ConvertDictionary(ctx, v.Dictionary) + } + return &tmp +} diff --git a/api/internal/svc/service_context.go b/api/internal/svc/service_context.go new file mode 100644 index 0000000..5cde7dd --- /dev/null +++ b/api/internal/svc/service_context.go @@ -0,0 +1,81 @@ +package svc + +import ( + "git.noahlan.cn/n-admin/n-admin-server/api/internal/config" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/middleware" + cache2 "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc/cache" + "git.noahlan.cn/n-admin/n-admin-server/api/internal/svc/captcha" + "git.noahlan.cn/n-admin/n-admin-server/dal" + "git.noahlan.cn/n-admin/n-admin-server/rpc/core/coreclient" + "git.noahlan.cn/noahlan/ntool-biz/core/i18n" + "git.noahlan.cn/noahlan/ntool-biz/core/nstatus" + "git.noahlan.cn/noahlan/ntool-biz/zero/logz" + "git.noahlan.cn/noahlan/ntool/nlog" + "git.noahlan.cn/noahlan/ntool/nmapper" + "git.noahlan.cn/noahlan/ntool/nmapper/wrapper" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/stores/cache" + "github.com/zeromicro/go-zero/core/stores/redis" + "github.com/zeromicro/go-zero/core/syncx" + "github.com/zeromicro/go-zero/rest" + "github.com/zeromicro/go-zero/zrpc" +) + +type ServiceContext struct { + Config config.Config + Authority rest.Middleware + Mapper *nmapper.MapperObject + Convert *Convert + + Redis *redis.Redis + Cache cache.Cache + + Captcha *captcha.CaptchaMgr + CodeCache cache2.CodeCache + + CoreRpc coreclient.Core +} + +func NewServiceContext(c config.Config) *ServiceContext { + // 配置nlog-logx适配器 + nlog.MustSetup(logz.WrapConf(c.Log)) + logx.SetWriter(logz.NewWriter()) + // 配置多语言 + i18n.InitWithConfig(c.I18n) + + // redis + rds := redis.MustNewRedis(redis.RedisConf{ + Host: c.RedisConf.Addr, + Type: c.RedisConf.Type, + Pass: c.RedisConf.Password, + Tls: c.RedisConf.Tls, + }) + che := cache.New(cache.ClusterConf{{ + RedisConf: redis.RedisConf{ + Host: c.RedisConf.Addr, + Type: c.RedisConf.Type, + Pass: c.RedisConf.Password, + Tls: c.RedisConf.Tls, + }, + Weight: 100, + }}, syncx.NewSingleFlight(), cache.NewStat("vc"), dal.ErrCacheNotFound) + + //ctx := context.Background() + tmp := &ServiceContext{ + Config: c, + Mapper: nmapper.NewMapper(nmapper.WithTypeWrapper(wrapper.StrWrapper()...)), + Authority: middleware.NewAuthorityMiddleware().Handle, + Redis: rds, + Cache: che, + CodeCache: cache2.NewCodeCacheMgr(che, rds), + Captcha: captcha.NewCaptchaManager(c.Captcha, c.RedisConf), + CoreRpc: coreclient.NewCore(zrpc.MustNewClient(c.CoreRpc, + zrpc.WithUnaryClientInterceptor(i18n.UnaryClientInterceptor()), + zrpc.WithUnaryClientInterceptor(nstatus.UnaryClientInterceptor()), + )), + } + + tmp.Convert = NewConvert(tmp) + + return tmp +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go new file mode 100644 index 0000000..cbef460 --- /dev/null +++ b/api/internal/types/types.go @@ -0,0 +1,671 @@ +// Code generated by goctl. DO NOT EDIT. +package types + +// Pagination | 分页模型 +// swagger:model Pagination +// swagger:allOf +type Pagination struct { + // Page Size | 每页大小 + // + // Minimum: 0 + // Maximum: 9999 + // Required: false + // Example: 10 + Size uint64 `json:"size,optional" form:"size,optional" validate:"number,max=9999"` + // Current Page | 当前页 + // + // Minimum: 1 + // Maximum: 100000 + // Required: false + // Example: 1 + Current uint64 `json:"current,optional" form:"current,optional" validate:"number,max=100000"` + // Total Number | 数据总数 + // + // Required: false + Total uint64 `json:"total,optional" form:"total,optional" validate:"number"` +} + +// TimeInfo | 时间结构 +// swagger:model TimeInfo +type TimeInfo struct { + // Create Time | 创建时间 + CreatedAt string `json:"createdAt,optional"` + // Update Time | 更新时间 + UpdatedAt string `json:"updatedAt,optional"` +} + +// Basic ID Request | 基础ID结构 +type BaseID struct { + // Id | 序号 + ID int64 `json:"id,string,optional" form:"id,string,optional"` +} + +// Basic ID request (path) | 基础ID结构,地址参数 +type PathID struct { + // ID | 序号 + // + // In: path + ID int64 `json:"id,optional,string" path:"id,optional,string"` +} + +// Basic ID List request | 基础ID列表结构,用于Post +// swagger:model BaseIDs +type BaseIDs struct { + // 主键列表 + Ids []int64 `json:"ids,optional" form:"ids,optional"` +} + +// OAuth log in request | OAuth 登录请求 +// swagger:parameters OauthLogin +type OauthLoginReq struct { + // Provider name | 服务提供商名称 + // + // In: query + // Required: true + // Max Length: 40 + // Example: [google, github, facebook] + Provider string `form:"provider" validate:"max=40"` +} + +// OAuth login return auth url | OAuth登录返回提供商登录页地址 +// swagger:model OauthLoginResp +type OauthLoginResp struct { + // Auth URL | 提供商登录地址 + AuthUrl string `json:"authUrl"` +} + +// OAuth log in by code request | OAuth 直接登录请求 +// swagger:model OauthLoginByCodeReq +type OauthLoginByCodeReq struct { + // Code | 一次性code + Code string `json:"code"` + // Provider name | 服务提供商名称 + // + // Example: [wechat,google] + // max length : 40 + Provider string `json:"provider" validate:"max=40"` +} + +// OAuth log in by phone code request | OAuth 手机号码登录请求 +// swagger:model OauthLoginByPhoneCodeReq +type OauthLoginByPhoneCodeReq struct { + // AuthCode | 登录Code,非必填,为了平台兼容性 + AuthCode string `json:"authCode,optional"` + // Code | 一次性code + Code string `json:"code"` + // Provider name | 服务提供商名称 + // + // Example: [wechat,google] + // max length : 40 + Provider string `json:"provider" validate:"max=40"` +} + +// Log in request | 普通登录请求 +// swagger:model LoginReq +type LoginReq struct { + // Log in subject | 登录主体(用户名/邮箱/手机号码)| 作用于验证码时,不支持用户名 + Subject string `json:"subject"` + // Credentials | 登录凭证 + Credentials string `json:"credentials"` + // Platform | 当前登录平台 + Platform string `json:"platform"` + // Captcha ID which store in redis | 图形验证码编号, 存在redis中 + // + // Required: true + // Max length: 32 + CaptchaId string `json:"captchaId,optional" validate:"len=32"` + // The Captcha which users input | 用户输入的验证码 + // + // Required: true + // Max length: 4 + Captcha string `json:"captcha,optional" validate:"len=4"` +} + +// LoginResp | 登录返回数据 +// swagger:model LoginResp +type LoginResp struct { + // TwoFactorType | 两步验证类型,空字符串表示无需两步验证 + TwoFactorType string `json:"twoFactorType"` + // Token | Token信息 + Token LoginTokenInfo `json:"token,optional"` +} + +// LoginTokenInfo | Token数据 +// swagger:model LoginTokenInfo +type LoginTokenInfo struct { + // User ID | 用户ID + UID int64 `json:"uid,string"` + // Token Type | Token类型 Authorization: {token_type} {access_token} + // + // Example: [Bearer] + TokenType string `json:"token_type"` + // Access Token | Jwt-Token + AccessToken string `json:"access_token"` + // Expires At | 过期具体时间,时间戳格式 + ExpiresAt int64 `json:"expires_at"` + // Scope | 授权范围,逗号分割 + Scope string `json:"scope,omitempty,optional"` +} + +// Register request | 注册请求 +// swagger:model RegisterReq +type RegisterReq struct { + // Username | 用户名 + Username *string `json:"username,optional"` + // Email | 邮箱 + Email *string `json:"email,optional"` + // PhoneNumber | 手机号码 + PhoneNumber *string `json:"phoneNumber,optional"` + // Credentials | 凭证 + Credentials string `json:"credentials"` + // Code | 验证码 + Code *string `json:"code,optional"` + // Captcha ID which store in redis | 图形验证码编号, 存在redis中 + // + // Required: true + // Max length: 32 + CaptchaId string `json:"captchaId,optional" validate:"len=32"` + // The Captcha which users input | 用户输入的验证码 + // + // Required: true + // Max length: 6 + Captcha string `json:"captcha,optional" validate:"len=4"` +} + +// swagger:model UserInfo +type UserInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // Username | 用户名 + Username string `json:"username,optional"` + // Phone number | 手机号码 + PhoneNumber *string `json:"phoneNumber,optional"` + // Email | 邮箱 + Email *string `json:"email,optional"` + // Password | 密码 + Password string `json:"password,optional,omitempty"` + // Nickname | 昵称 + Nickname *string `json:"nickname,optional"` + // Roles | 角色代码列表 + Roles []string `json:"roles,optional"` + // LoginRecord | 用户登录记录 + LoginRecord *UserLoginRecordInfo `json:"loginRecord,optional"` + // Meta | 元数据 + Metas map[string]string `json:"metadata"` +} + +// 用户登录记录 +// swagger:model UserLoginRecordInfo +type UserLoginRecordInfo struct { + BaseID + TimeInfo + // 用户ID + UserId int64 `json:"userId,string,optional"` + // 最近一次登录时间 + LastLoginAt string `json:"lastLoginAt,optional"` + // 最近一次登录IPv4 + LastLoginIpv4 string `json:"lastLoginIpv4,optional"` + // 最近一次登录设备 + LastLoginDevice string `json:"lastLoginDevice,optional"` + // 最近一次登录浏览器Ua + LastLoginUa string `json:"lastLoginUa,optional"` + // 总登录次数 + LoginCount uint64 `json:"loginCount,optional"` +} + +// Token信息 +// swagger:model TokenInfo +type TokenInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // User's Id | 用户ID + UserId int64 `json:"userId,string,optional"` + // AccessToken | AccessToken 字符串 + AccessToken string `json:"accessToken,optional"` + // RefreshToken | RefreshToken 字符串 + RefreshToken string `json:"refreshYoken,optional"` + // Source | Token来源,PCWeb/WechatMini/AlipayMini + Source string `json:"source,optional"` + // Expire Time | 过期时间 + ExpiredAt int64 `json:"expiredAt,optional"` +} + +// 用户社交平台信息 +// swagger:model UserSocialInfo +type UserSocialInfo struct { + BaseID + TimeInfo + // 系统用户ID + UserId int64 `json:"userId,string,optional"` + // OAuth Provider | 服务提供商 + Provider string `json:"provider,optional"` + // Access Token | 用户在提供商最近一次登录的访问凭证 + AccessToken string `json:"accessToken,optional"` + // Refresh Token | 用户在提供商最近一次登录的刷新凭证 + RefreshToken string `json:"refreshToken,optional"` + // User's ID | 提供商用户ID,不一定存在 + Uid string `json:"uid,optional"` + // OpenId | 用户在提供商的OpenID + OpenId string `json:"openId,optional"` + // UnionId | 用户在提供商的UnionID + UnionId string `json:"unionId,optional"` + // Key | 用户在提供商的用于解密的key + Key string `json:"key,optional"` + // Expires in | 访问凭证过期时长,单位:秒 + ExpiresIn uint64 `json:"expiresIn,optional"` + // User Profile | 提供商用户信息,不一定存在 + UserProfile string `json:"userProfile,optional"` +} + +// 角色信息 +// swagger:model RoleInfo +type RoleInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // Role Code | 角色编码,可用于权限控制 + Code string `json:"code,optional"` + // Role Name | 角色名 + Name string `json:"name,optional"` + // Description | 角色描述 + Description string `json:"description,optional"` +} + +// swagger:model DepartmentInfo +type DepartmentInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // Department name | 部门名称 + Name string `json:"name,optional"` + // Department leader | 部门负责人 + LeaderId int64 `json:"leaderId,string,optional"` + // Remark | 备注 + Remark string `json:"remark,optional"` + // Parent ID | 直接父级ID + ParentId int64 `json:"parentId,string,optional"` + // Leader | 部门负责人信息 + Leader *UserInfo `json:"leader,optional"` + // Parent | 直接父级 + Parent *DepartmentInfo `json:"parent,optional"` + // Children | 孩子列表 + Children []*DepartmentInfo `json:"children,optional"` +} + +// swagger:model OauthProviderInfo +type OauthProviderInfo struct { + BaseID + TimeInfo + // The provider's name | 提供商名称 + Name string `json:"name,optional"` + // The client id | 客户端 id + ClientId string `json:"clientId,optional"` + // The client secret | 客户端密钥 + ClientSecret string `json:"clientSecret,optional"` + // The redirect url | 跳转地址 + RedirectUrl string `json:"redirectUrl,optional"` + // The scopes | 权限范围 + Scopes string `json:"scopes,optional"` + // The auth url of the provider | 认证地址 + AuthUrl string `json:"authUrl,optional"` + // The token url of the provider | 获取 Token 地址 + TokenUrl string `json:"tokenUrl,optional"` + // The URL to request user information by token | 用户信息请求地址 + InfoUrl string `json:"infoUrl,optional"` + // The description of the provider | 提供商描述 + Description string `json:"description,optional"` + // The system internal oauth provider | 系统内置提供商 + System bool `json:"system,optional"` + // The oauth provider init status | 提供商初始化状态 + Init bool `json:"init,optional"` +} + +// District info | 地址信息 +// swagger:model DistrictInfo +type DistrictInfo struct { + BaseID + TimeInfo + // Name | 地区名称 + Name string `json:"name"` + // Short name | 地区缩写,省级 + ShortName string `json:"shortName"` + // Code | 地址编码 + Code string `json:"code"` + // Province code | 省级行政编号,表示该地区归属 + Province string `json:"province"` + // City | 地级行政编号,表示该地区归属 + City string `json:"city"` + // Area | 县级行政编号,表示该地区归属 + Area string `json:"area"` + // Street or Town | 乡级行政编号,表示该地区归属 + Street string `json:"street"` + // Level | 地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县 4-乡镇 + Level uint32 `json:"level"` + // Latitude | 纬度 + Latitude float64 `json:"latitude"` + // Longitude | 经度 + Longitude float64 `json:"longitude"` + // Children | 子级 + Children []*DistrictInfo `json:"children,optional"` +} + +// CaptchaInfo | 验证码信息 +// swagger:model CaptchaInfo +type CaptchaInfo struct { + // CaptchaId | 验证码ID + CaptchaId string `json:"captchaId"` + // Base64 | 验证码图片 Base64 + Base64 string `json:"base64"` +} + +// 字典信息 +// swagger:model DictionaryInfo +type DictionaryInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // The title shown in the ui | 展示名称 (建议配合i18n) + Title string `json:"title,optional"` + // The name of dictionary for search | 字典搜索名称 + Name string `json:"name,optional"` + // The description of dictionary | 字典的描述 + Description string `json:"description,optional"` + // Details | 字典项 + Details []*DictionaryDetailInfo `json:"details,optional"` +} + +// 字典项信息 +// swagger:model DictionaryDetailInfo +type DictionaryDetailInfo struct { + BaseID + TimeInfo + // Status | 状态 + Status string `json:"status,optional"` + // Sort number | 排序号 + Sort uint32 `json:"sort,optional"` + // The title shown in the ui | 展示名称 (建议配合i18n) + Title string `json:"title,optional"` + // key | 键 + Key string `json:"key,optional"` + // value | 值 + Value string `json:"value,optional"` + // Dictionary Id | 字典ID + DictionaryId int64 `json:"dictionaryId,string,optional"` + // Dictionary | 字典信息 + Dictionary *DictionaryInfo `json:"dictionary,optional"` +} + +// User request | 用户查询参数 +// swagger:parameters GetUserAdmin GetUserListAdmin +type UserReq struct { + BaseID + *Pagination + // Username | 用户名 + Username string `json:"username,optional" form:"username,optional"` + // PhoneNumber | 手机号码 + PhoneNumber string `json:"phoneNumber,optional" form:"phoneNumber,optional"` + // Email | 邮箱 + Email string `json:"email,optional" form:"email,optional"` + // Nickname | 昵称 + Nickname string `json:"nickname,optional" form:"nickname,optional"` +} + +// User list response | 用户列表返回 +// swagger:model UserListResp +type UserListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []*UserInfo `json:"list"` +} + +// Role request | 角色查询请求 +// swagger:parameters GetRoleAdmin GetRoleListAdmin +type RoleReq struct { + BaseID + *Pagination + // Name | 角色名称 + // + // Required: false + // Example: wechat + Name string `form:"name,optional"` + // Code | 角色编码(Like) + // + // Required: false + // Example: Admin + Code string `form:"code,optional"` +} + +// Role list response | 角色列表查询返回 +// swagger:model RoleListResp +type RoleListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []*RoleInfo `json:"list"` +} + +// Token request | 查询凭证请求 +// swagger:parameters GetTokenListAdmin +type TokenReq struct { + BaseID + *Pagination + // User id | 用户ID + UserID int64 `json:"userId,string,optional" form:"userId,string,optional"` + // Token status | Token状态 + Status string `json:"status,optional" form:"status,optional"` + // Provider source | 提供商来源 + Source string `json:"source,optional" form:"source,optional"` + // Token type | 凭证类型 [Bearer] + // + // Example: Bearer + TokenType string `json:"tokenType,optional" form:"tokenType,optional"` +} + +// Token list response | 凭证列表返回 +// swagger:model TokenListResp +type TokenListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []TokenInfo `json:"list"` +} + +// Validating captcha request | 验证验证码请求 +// swagger:model ValidateCaptchaReq +type ValidateCaptchaReq struct { + // Captcha ID which store in redis | 图形验证码编号, 存在redis中 + // + // Required: true + // Max length: 32 + CaptchaId string `json:"captchaId" validate:"len=32"` + // The Captcha which users input | 用户输入的验证码 + // + // Required: true + // Max length: 4 + Captcha string `json:"captcha" validate:"len=4"` + // Auto remove captcha | 自动删除被验证的验证码 + // + // Required: false + Clear bool `json:"clear,optional"` +} + +// District tree | 地址树,层级结构 +// swagger:model DistrictTree +type DistrictTree struct { + // Tree | 树 + Tree []*DistrictInfo `json:"tree"` +} + +// District request | 地址请求参数 +// swagger:parameters GetDistrictTree +type DistrictReq struct { + BaseID + // Code | 地址编码 + Code string `json:"code,optional" form:"code,optional"` +} + +// Get District List | 获取地址列表,单级机构,children为空 +// swagger:parameters GetDistrictList +type GetDistrictListReq struct { + BaseID + *Pagination + // Name | 地区名称模糊匹配 (like) + Name string `json:"name,optional" form:"name,optional"` + // Province code | 省级行政编号,表示该地区归属 + Province string `json:"province,optional" form:"province,optional"` + // City | 地级行政编号,表示该地区归属 + City string `json:"city,optional" form:"city,optional"` + // Area | 县级行政编号,表示该地区归属 + Area string `json:"area,optional" form:"area,optional"` + // Street or Town | 乡级行政编号,表示该地区归属 + Street string `json:"street,optional" form:"street,optional"` + // Level | 地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县 4-乡镇 + Level uint32 `json:"level,optional" form:"level,optional"` +} + +// Get District Children | 获取子级地址列表,单级机构,children为空 +// swagger:parameters GetDistrictChildren +type GetDistrictChildrenReq struct { + // Parent Code | 父级Code,若为空,则查询level为1的列表 + ParentCode string `json:"parentCode,optional" form:"parentCode,optional"` +} + +// District name request | 地址名称请求参数 +// swagger:parameters GetDistrictName +type GetDistrictNameReq struct { + // Code | 地址编码 + Code string `json:"code,optional" form:"code,optional"` + // Separator | 分隔符,默认为空字符串 + Separator string `json:"sep,optional" form:"sep,optional"` +} + +// District name response | 地址名称回复 +// swagger:model GetDistrictNameResp +type GetDistrictNameResp struct { + // Code | 地址编码 + Code string `json:"code"` + // Name | 地址名称(拼接后) + Name string `json:"name"` + // Name List | 地址名称列表,逐级,不拼接 + NameList []string `json:"nameList"` +} + +// OAuth provider request | OAuth提供商查询请求 +// swagger:parameters GetOauthProviderAdmin GetOauthProviderListAdmin +type OauthProviderReq struct { + BaseID + *Pagination + // Name | 第三方提供商名称 + // + // Required: false + // Example: wechat + Name string `form:"name,optional"` + // ClientId | 第三方客户端ID (like) + // + // Required: false + // Example: wx21k2j193j2ksdfaak291l + ClientId string `form:"clientId,optional"` + // 是否系统内置 + // + // Required: false + System *bool `form:"system,optional"` + // 是否已初始化 + // + // Required: false + Init *bool `form:"init,optional"` +} + +// OAuth provider list response | OAuth提供商查询返回 +// swagger:model OauthProviderListResp +type OauthProviderListResp struct { + Page *Pagination `json:"page,optional"` + List []*OauthProviderInfo `json:"list"` +} + +// Department request | 部门查询请求 +// swagger:parameters GetDepartmentListAdmin GetDepartmentAdmin +type DepartmentReq struct { + BaseID + *Pagination + // 部门名称 + Name string `json:"name,optional" form:"name,optional"` + // Leader ID | 负责人ID + LeaderId int64 `json:"leaderId,string,optional" form:"leaderId,optional"` + // Parent ID | 父节点ID + ParentId int64 `json:"parentId,string,optional" form:"parentId,optional"` +} + +// Department list response | 部门列表返回 +// swagger:model DepartmentListResp +type DepartmentListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []*DepartmentInfo `json:"list"` +} + +// Dictionary request | 字典查询请求 +// swagger:parameters GetDictionaryListAdmin GetDictionaryAdmin +type DictionaryReq struct { + BaseID + *Pagination + // 展示名称 + Title string `json:"title,optional" form:"title,optional"` + // 搜索名称 + Name string `json:"name,optional" form:"name,optional"` + // Status | 状态 + Status string `json:"status,optional" form:"status,optional"` + // Keyword | 综合搜索关键字 + Keyword string `json:"keyword,optional" form:"keyword,optional"` +} + +// Dictionary list response | 字典列表返回 +// swagger:model DictionaryListResp +type DictionaryListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []*DictionaryInfo `json:"list"` +} + +// Dictionary detail request | 字典项查询请求 +// swagger:parameters GetDictionaryDetailListAdmin GetDictionaryDetailAdmin +type DictionaryDetailReq struct { + BaseID + *Pagination + // 字典ID + DictionaryID int64 `json:"dictionaryId,string,optional" form:"dictionaryId,optional"` + // Status | 状态 + Status string `json:"status,optional" form:"status,optional"` + // 展示名称 + Title string `json:"title,optional" form:"title,optional"` + // Key + Key string `json:"key,optional" form:"key,optional"` + // Keyword | 综合搜索关键字 + Keyword string `json:"keyword,optional" form:"keyword,optional"` +} + +// Dictionary Detail list response | 字典项列表返回 +// swagger:model DictionaryDetailListResp +type DictionaryDetailListResp struct { + // Page | 分页数据 + Page *Pagination `json:"page,optional"` + // List | 数据列表 + List []*DictionaryDetailInfo `json:"list"` +} + +// Dictionary Detail request | 字典项删除请求 +// swagger:parameters DeleteDictionaryDetailAdmin +type DeleteDictionaryDetailReq struct { + BaseIDs + // 字典ID + DictionaryID int64 `json:"dictionaryId,string,optional" form:"dictionaryId,optional"` +} diff --git a/api/internal/types/vars.go b/api/internal/types/vars.go new file mode 100644 index 0000000..da2ea29 --- /dev/null +++ b/api/internal/types/vars.go @@ -0,0 +1,13 @@ +package types + +const ( + CodeSourceSms = "SMS" + CodeSourceEmail = "EMAIL" +) + +const ( + SmsCodeTypeLogin string = "Login" // 登录验证码 + SmsCodeTypeRegister = "Register" // 注册验证码 + SmsCodeTypeBind = "Bind" // 绑定手机验证码 + SmsCodeTypeUnBind = "Unbind" // 解绑手机验证码 +) diff --git a/dal/errx/errx.go b/dal/errx/errx.go index 3fcaff4..31cc205 100644 --- a/dal/errx/errx.go +++ b/dal/errx/errx.go @@ -3,16 +3,23 @@ package errx import ( "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code" "git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg" + "net/http" ) // Common +const ( + StatusUnauthorized code.Code = http.StatusUnauthorized +) + +// Auth const ( WrongCode code.Code = iota + 1000 // 验证码错误 - WrongCaptcha // 验证码错误 WrongPassword // 密码错误 UserNotFound // 用户不存在 NeedPhoneOrEmail // 请输入正确的手机号或邮箱 UnsupportedLoginType // 暂未支持此类型登录方式 + JwtTokenGenerateErr // JwtToken生成失败 + ProviderNotInit // 服务提供商未进行初始化 ) // User register @@ -61,14 +68,23 @@ const ( DictionaryDetailIdNotEmpty ) +// Captcha +const ( + InvalidCaptchaErr code.Code = iota + 1800 + CaptchaGenerateErr +) + func init() { // Common + msg.Add(StatusUnauthorized, "unauthorized") + // Auth msg.Add(WrongCode, "auth.wrongCode") - msg.Add(WrongCaptcha, "auth.wrongCaptcha") msg.Add(WrongPassword, "auth.wrongPassword") msg.Add(UserNotFound, "auth.userNotFound") msg.Add(NeedPhoneOrEmail, "auth.needPhoneOrEmail") msg.Add(UnsupportedLoginType, "auth.unsupportedLoginType") + msg.Add(JwtTokenGenerateErr, "auth.jwtTokenGenerateErr") + msg.Add(ProviderNotInit, "auth.providerNotInit") // User Register msg.Add(UsernameAlreadyExists, "register.user.usernameExists") @@ -101,4 +117,8 @@ func init() { msg.Add(DictionaryDetailKeyNotEmpty, "dictionary.detail.keyNotEmpty") msg.Add(DictionaryDetailExists, "dictionary.detail.exists") msg.Add(DictionaryDetailIdNotEmpty, "dictionary.detail.idNotEmpty") + + // Captcha + msg.Add(InvalidCaptchaErr, "captcha.invalid") + msg.Add(CaptchaGenerateErr, "captcha.generateErr") } diff --git a/dal/i18n/locale/zh.json b/dal/i18n/locale/zh.json index 39ef572..dc89145 100644 --- a/dal/i18n/locale/zh.json +++ b/dal/i18n/locale/zh.json @@ -14,7 +14,8 @@ "constraintError": "操作失败: 数据冲突", "validationError": "操作失败: 校验失败", "notSingularError": "操作失败: 数据不唯一", - "permissionDeny": "用户无权限访问此接口" + "permissionDeny": "用户无权限访问此接口", + "unauthorized": "未登录,请先登录" }, "init": { "alreadyInit": "已初始化,请勿重复进行此操作", @@ -22,10 +23,11 @@ }, "auth": { "wrongCode": "验证码错误", - "wrongCaptcha": "验证码错误", "wrongPassword": "密码错误", "userNotFound": "用户不存在", - "needPhoneOrEmail": "请输入正确的手机号码或邮箱" + "needPhoneOrEmail": "请输入正确的手机号码或邮箱", + "jwtTokenGenerateErr": "Token生成失败", + "providerNotInit": "服务提供商未初始化,请联系开发商" }, "register": { "user": { @@ -60,5 +62,9 @@ "exists": "字典已存在", "idNotEmpty": "主键(ID)不能为空" } + }, + "captcha": { + "invalid": "验证码错误", + "generateErr": "生成验证码时发生错误" } } \ No newline at end of file diff --git a/dal/vars.go b/dal/vars.go new file mode 100644 index 0000000..018eaa7 --- /dev/null +++ b/dal/vars.go @@ -0,0 +1,21 @@ +package dal + +// Social类型 +const ( + SocialNone string = "none" // 无 + SocialWechat = "wechat" // 微信-公众平台 + SocialWechatMini = "wechat-mini" // 微信-小程序 + SocialPhone = "phone" // 手机号码 + SocialEmail = "email" // 邮箱 + SocialQQ = "qq" // QQ + SocialWeibo = "weibo" // 微博 +) + +var SocialNameMap = map[string]string{ + SocialWechat: "微信", + SocialWechatMini: "微信小程序", + SocialQQ: "腾讯QQ", + SocialWeibo: "微博", +} + +const UserDeviceKey = "User-Device" diff --git a/go.mod b/go.mod index 7cb79c6..5a64964 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,11 @@ go 1.20 require ( entgo.io/ent v0.12.3 git.noahlan.cn/noahlan/ntool v1.1.10 - git.noahlan.cn/noahlan/ntool-biz v1.2.4 + git.noahlan.cn/noahlan/ntool-biz v1.2.6 + github.com/casbin/casbin/v2 v2.71.0 + github.com/dgraph-io/ristretto v0.1.1 github.com/jinzhu/copier v0.4.0 + github.com/mojocn/base64Captcha v1.3.5 github.com/zeromicro/go-zero v1.5.4 google.golang.org/grpc v1.56.2 google.golang.org/protobuf v1.31.0 @@ -16,6 +19,7 @@ require ( ariga.io/atlas v0.12.0 // indirect ariga.io/entcache v0.1.0 // indirect github.com/BurntSushi/toml v1.3.2 // indirect + github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -24,7 +28,6 @@ require ( github.com/coreos/go-semver v0.3.1 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dustin/go-humanize v1.0.0 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect @@ -39,6 +42,9 @@ require ( github.com/go-sql-driver/mysql v1.7.1 // indirect github.com/gofrs/uuid/v5 v5.0.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-jwt/jwt/v5 v5.0.0 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/glog v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect @@ -71,6 +77,7 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/radovskyb/watcher v1.0.7 // indirect + github.com/redis/go-redis/v9 v9.0.5 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/zclconf/go-cty v1.13.2 // indirect @@ -93,6 +100,7 @@ require ( go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect + golang.org/x/image v0.8.0 // indirect golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.7.0 // indirect diff --git a/go.sum b/go.sum index 35a0ad6..2a1e7ee 100644 --- a/go.sum +++ b/go.sum @@ -39,26 +39,31 @@ entgo.io/ent v0.12.3 h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk= entgo.io/ent v0.12.3/go.mod h1:AigGGx+tbrBBYHAzGOg8ND661E5cxx1Uiu5o/otJ6Yg= git.noahlan.cn/noahlan/ntool v1.1.10 h1:78ntTd71v+25ejEAxHHb0NrZCIwLISo9aLoZIbB3Cj8= git.noahlan.cn/noahlan/ntool v1.1.10/go.mod h1:pzoXErnQDLaHhvEHOGDoINf5VP1MDiU8NAcnaMEhxa4= -git.noahlan.cn/noahlan/ntool-biz v1.2.4 h1:rYIg1sgKO/3gDMqqZN+IS1x1OPEoxvV0P/QfaH8OPKs= -git.noahlan.cn/noahlan/ntool-biz v1.2.4/go.mod h1:aND1S4nxgIkqCKvkEDlZ91Eb38t+5jsIfEhXZTNlIL0= +git.noahlan.cn/noahlan/ntool-biz v1.2.6 h1:hA5wZEyHfTzuw/m0ezy80WA/Zxj9gadZ2BudNhHneA0= +git.noahlan.cn/noahlan/ntool-biz v1.2.6/go.mod h1:tDLQI3abZTFl5dqfO/d1aUMi8nY0rcKZ2qK9qvSVFdE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/miniredis/v2 v2.30.4 h1:8S4/o1/KoUArAGbGwPxcwf0krlzceva2XVOSchFS7Eo= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= +github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= +github.com/casbin/casbin/v2 v2.71.0 h1:pVzHKXkGgOXIjksEwnrOjNu5CE4xy6aAVzdR8td2gSc= +github.com/casbin/casbin/v2 v2.71.0/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -87,6 +92,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8= github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= @@ -105,12 +111,10 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -131,12 +135,17 @@ github.com/go-redis/redismock/v8 v8.0.6 h1:rtuijPgGynsRB2Y7KDACm09WvjHWS4RaG44Nm github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= -github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M= github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= @@ -218,18 +227,14 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/hcl/v2 v2.17.0 h1:z1XvSUyXd1HP10U4lrLg5e0JMVz6CPaJvAgxM0KNZVY= github.com/hashicorp/hcl/v2 v2.17.0/go.mod h1:gJyW2PTShkJqQBKpAmPO3yxMxIuoXkOF2TpqXzrQyx4= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -241,7 +246,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= -github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -251,8 +255,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -265,15 +267,13 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0= +github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nicksnyder/go-i18n/v2 v2.2.1 h1:aOzRCdwsJuoExfZhoiXHy4bjruwCMdt5otbYojM/PaA= github.com/nicksnyder/go-i18n/v2 v2.2.1/go.mod h1:fF2++lPHlo+/kPaj3nB0uxtPwzlPm+BlgwGX7MkeGj0= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.7.0 h1:/XxtEV3I3Eif/HobnVx9YmJgk8ENdRsuUmM+fLCFNow= github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= @@ -297,20 +297,16 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE= github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o= +github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -336,7 +332,6 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE= github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= github.com/zeromicro/go-zero v1.5.4 h1:kRvcYuxcHOkUZvg7887KQl77Qv4klGL7MqGkTBgkpS8= github.com/zeromicro/go-zero v1.5.4/go.mod h1:x/aUyLmSwRECvOyjOf+lhwThBOilJIY+s3slmPAeboA= go.etcd.io/etcd/api/v3 v3.5.9 h1:4wSsluwyTbGGmyjJktOf3wFQoTBIURXHnq9n/G/JQHs= @@ -402,7 +397,10 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg= +golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -423,6 +421,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -455,6 +454,7 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -476,6 +476,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -510,11 +511,13 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -525,6 +528,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -576,8 +581,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= -golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -683,7 +687,6 @@ gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/n-admin-server.yml b/n-admin-server.yml index 20ed5f3..eae7c09 100644 --- a/n-admin-server.yml +++ b/n-admin-server.yml @@ -24,6 +24,475 @@ definitions: x-go-name: Ids type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + CaptchaInfo: + description: CaptchaInfo | 验证码信息 + properties: + base64: + description: Base64 | 验证码图片 Base64 + type: string + x-go-name: Base64 + captchaId: + description: CaptchaId | 验证码ID + type: string + x-go-name: CaptchaId + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DepartmentInfo: + properties: + children: + description: Children | 孩子列表 + items: + $ref: '#/definitions/DepartmentInfo' + type: array + x-go-name: Children + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + leader: + $ref: '#/definitions/UserInfo' + leaderId: + description: Department leader | 部门负责人 + format: int64 + type: string + x-go-name: LeaderId + name: + description: Department name | 部门名称 + type: string + x-go-name: Name + parent: + $ref: '#/definitions/DepartmentInfo' + parentId: + description: Parent ID | 直接父级ID + format: int64 + type: string + x-go-name: ParentId + remark: + description: Remark | 备注 + type: string + x-go-name: Remark + status: + description: Status | 状态 + type: string + x-go-name: Status + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DepartmentListResp: + description: Department list response | 部门列表返回 + properties: + list: + description: List | 数据列表 + items: + $ref: '#/definitions/DepartmentInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DictionaryDetailInfo: + description: 字典项信息 + properties: + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + dictionary: + $ref: '#/definitions/DictionaryInfo' + dictionaryId: + description: Dictionary Id | 字典ID + format: int64 + type: string + x-go-name: DictionaryId + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + key: + description: key | 键 + type: string + x-go-name: Key + sort: + description: Sort number | 排序号 + format: uint32 + type: integer + x-go-name: Sort + status: + description: Status | 状态 + type: string + x-go-name: Status + title: + description: The title shown in the ui | 展示名称 (建议配合i18n) + type: string + x-go-name: Title + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + value: + description: value | 值 + type: string + x-go-name: Value + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DictionaryDetailListResp: + description: Dictionary Detail list response | 字典项列表返回 + properties: + list: + description: List | 数据列表 + items: + $ref: '#/definitions/DictionaryDetailInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DictionaryInfo: + description: 字典信息 + properties: + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + description: + description: The description of dictionary | 字典的描述 + type: string + x-go-name: Description + details: + description: Details | 字典项 + items: + $ref: '#/definitions/DictionaryDetailInfo' + type: array + x-go-name: Details + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + name: + description: The name of dictionary for search | 字典搜索名称 + type: string + x-go-name: Name + status: + description: Status | 状态 + type: string + x-go-name: Status + title: + description: The title shown in the ui | 展示名称 (建议配合i18n) + type: string + x-go-name: Title + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DictionaryListResp: + description: Dictionary list response | 字典列表返回 + properties: + list: + description: List | 数据列表 + items: + $ref: '#/definitions/DictionaryInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DistrictInfo: + description: District info | 地址信息 + properties: + area: + description: Area | 县级行政编号,表示该地区归属 + type: string + x-go-name: Area + children: + description: Children | 子级 + items: + $ref: '#/definitions/DistrictInfo' + type: array + x-go-name: Children + city: + description: City | 地级行政编号,表示该地区归属 + type: string + x-go-name: City + code: + description: Code | 地址编码 + type: string + x-go-name: Code + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + latitude: + description: Latitude | 纬度 + format: double + type: number + x-go-name: Latitude + level: + description: Level | 地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县 4-乡镇 + format: uint32 + type: integer + x-go-name: Level + longitude: + description: Longitude | 经度 + format: double + type: number + x-go-name: Longitude + name: + description: Name | 地区名称 + type: string + x-go-name: Name + province: + description: Province code | 省级行政编号,表示该地区归属 + type: string + x-go-name: Province + shortName: + description: Short name | 地区缩写,省级 + type: string + x-go-name: ShortName + street: + description: Street or Town | 乡级行政编号,表示该地区归属 + type: string + x-go-name: Street + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + DistrictTree: + description: District tree | 地址树,层级结构 + properties: + tree: + description: Tree | 树 + items: + $ref: '#/definitions/DistrictInfo' + type: array + x-go-name: Tree + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + GetDistrictNameResp: + description: District name response | 地址名称回复 + properties: + code: + description: Code | 地址编码 + type: string + x-go-name: Code + name: + description: Name | 地址名称(拼接后) + type: string + x-go-name: Name + nameList: + description: Name List | 地址名称列表,逐级,不拼接 + items: + type: string + type: array + x-go-name: NameList + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + LoginReq: + description: Log in request | 普通登录请求 + properties: + captcha: + description: The Captcha which users input | 用户输入的验证码 + maxLength: 4 + type: string + x-go-name: Captcha + captchaId: + description: Captcha ID which store in redis | 图形验证码编号, 存在redis中 + maxLength: 32 + type: string + x-go-name: CaptchaId + credentials: + description: Credentials | 登录凭证 + type: string + x-go-name: Credentials + platform: + description: Platform | 当前登录平台 + type: string + x-go-name: Platform + subject: + description: Log in subject | 登录主体(用户名/邮箱/手机号码)| 作用于验证码时,不支持用户名 + type: string + x-go-name: Subject + required: + - captchaId + - captcha + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + LoginResp: + description: LoginResp | 登录返回数据 + properties: + token: + $ref: '#/definitions/LoginTokenInfo' + twoFactorType: + description: TwoFactorType | 两步验证类型,空字符串表示无需两步验证 + type: string + x-go-name: TwoFactorType + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + LoginTokenInfo: + description: LoginTokenInfo | Token数据 + properties: + access_token: + description: Access Token | Jwt-Token + type: string + x-go-name: AccessToken + expires_at: + description: Expires At | 过期具体时间,时间戳格式 + format: int64 + type: integer + x-go-name: ExpiresAt + scope: + description: Scope | 授权范围,逗号分割 + type: string + x-go-name: Scope + token_type: + description: 'Token Type | Token类型 Authorization: {token_type} {access_token}' + example: '[Bearer]' + type: string + x-go-name: TokenType + uid: + description: User ID | 用户ID + format: int64 + type: string + x-go-name: UID + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + OauthLoginByCodeReq: + description: OAuth log in by code request | OAuth 直接登录请求 + properties: + code: + description: Code | 一次性code + type: string + x-go-name: Code + provider: + description: Provider name | 服务提供商名称 + example: '[wechat,google]' + maxLength: 40 + type: string + x-go-name: Provider + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + OauthLoginByPhoneCodeReq: + description: OAuth log in by phone code request | OAuth 手机号码登录请求 + properties: + authCode: + description: AuthCode | 登录Code,非必填,为了平台兼容性 + type: string + x-go-name: AuthCode + code: + description: Code | 一次性code + type: string + x-go-name: Code + provider: + description: Provider name | 服务提供商名称 + example: '[wechat,google]' + maxLength: 40 + type: string + x-go-name: Provider + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + OauthLoginResp: + description: OAuth login return auth url | OAuth登录返回提供商登录页地址 + properties: + authUrl: + description: Auth URL | 提供商登录地址 + type: string + x-go-name: AuthUrl + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + OauthProviderInfo: + properties: + authUrl: + description: The auth url of the provider | 认证地址 + type: string + x-go-name: AuthUrl + clientId: + description: The client id | 客户端 id + type: string + x-go-name: ClientId + clientSecret: + description: The client secret | 客户端密钥 + type: string + x-go-name: ClientSecret + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + description: + description: The description of the provider | 提供商描述 + type: string + x-go-name: Description + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + infoUrl: + description: The URL to request user information by token | 用户信息请求地址 + type: string + x-go-name: InfoUrl + init: + description: The oauth provider init status | 提供商初始化状态 + type: boolean + x-go-name: Init + name: + description: The provider's name | 提供商名称 + type: string + x-go-name: Name + redirectUrl: + description: The redirect url | 跳转地址 + type: string + x-go-name: RedirectUrl + scopes: + description: The scopes | 权限范围 + type: string + x-go-name: Scopes + system: + description: The system internal oauth provider | 系统内置提供商 + type: boolean + x-go-name: System + tokenUrl: + description: The token url of the provider | 获取 Token 地址 + type: string + x-go-name: TokenUrl + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + OauthProviderListResp: + description: OAuth provider list response | OAuth提供商查询返回 + properties: + list: + items: + $ref: '#/definitions/OauthProviderInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types Pagination: description: Pagination | 分页模型 properties: @@ -50,6 +519,91 @@ definitions: x-go-name: Total type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + RegisterReq: + description: Register request | 注册请求 + properties: + captcha: + description: The Captcha which users input | 用户输入的验证码 + maxLength: 6 + type: string + x-go-name: Captcha + captchaId: + description: Captcha ID which store in redis | 图形验证码编号, 存在redis中 + maxLength: 32 + type: string + x-go-name: CaptchaId + code: + description: Code | 验证码 + type: string + x-go-name: Code + credentials: + description: Credentials | 凭证 + type: string + x-go-name: Credentials + email: + description: Email | 邮箱 + type: string + x-go-name: Email + phoneNumber: + description: PhoneNumber | 手机号码 + type: string + x-go-name: PhoneNumber + username: + description: Username | 用户名 + type: string + x-go-name: Username + required: + - captchaId + - captcha + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + RoleInfo: + description: 角色信息 + properties: + code: + description: Role Code | 角色编码,可用于权限控制 + type: string + x-go-name: Code + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + description: + description: Description | 角色描述 + type: string + x-go-name: Description + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + name: + description: Role Name | 角色名 + type: string + x-go-name: Name + status: + description: Status | 状态 + type: string + x-go-name: Status + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + RoleListResp: + description: Role list response | 角色列表查询返回 + properties: + list: + description: List | 数据列表 + items: + $ref: '#/definitions/RoleInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types TimeInfo: description: TimeInfo | 时间结构 properties: @@ -63,51 +617,255 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types - UserInfo: + TokenInfo: + description: Token信息 properties: + accessToken: + description: AccessToken | AccessToken 字符串 + type: string + x-go-name: AccessToken createdAt: description: Create Time | 创建时间 type: string x-go-name: CreatedAt + expiredAt: + description: Expire Time | 过期时间 + format: int64 + type: integer + x-go-name: ExpiredAt id: description: Id | 序号 format: int64 type: string x-go-name: ID + refreshYoken: + description: RefreshToken | RefreshToken 字符串 + type: string + x-go-name: RefreshToken + source: + description: Source | Token来源,PCWeb/WechatMini/AlipayMini + type: string + x-go-name: Source + status: + description: Status | 状态 + type: string + x-go-name: Status updatedAt: description: Update Time | 更新时间 type: string x-go-name: UpdatedAt + userId: + description: User's Id | 用户ID + format: int64 + type: string + x-go-name: UserId type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types - UserReq: + TokenListResp: + description: Token list response | 凭证列表返回 properties: - current: - description: Current Page | 当前页 - example: 1 - format: uint64 - maximum: 100000 - minimum: 1 - type: integer - x-go-name: Current - id: - description: Id | 序号 - format: int64 - type: string - x-go-name: ID - size: - description: Page Size | 每页大小 - example: 10 - format: uint64 - maximum: 9999 - minimum: 0 + list: + description: List | 数据列表 + items: + $ref: '#/definitions/TokenInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserInfo: + properties: + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + email: + description: Email | 邮箱 + type: string + x-go-name: Email + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + loginRecord: + $ref: '#/definitions/UserLoginRecordInfo' + metadata: + additionalProperties: + type: string + description: Meta | 元数据 + type: object + x-go-name: Metas + nickname: + description: Nickname | 昵称 + type: string + x-go-name: Nickname + password: + description: Password | 密码 + type: string + x-go-name: Password + phoneNumber: + description: Phone number | 手机号码 + type: string + x-go-name: PhoneNumber + roles: + description: Roles | 角色代码列表 + items: + type: string + type: array + x-go-name: Roles + status: + description: Status | 状态 + type: string + x-go-name: Status + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + username: + description: Username | 用户名 + type: string + x-go-name: Username + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserListResp: + description: User list response | 用户列表返回 + properties: + list: + description: List | 数据列表 + items: + $ref: '#/definitions/UserInfo' + type: array + x-go-name: List + page: + $ref: '#/definitions/Pagination' + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserLoginRecordInfo: + description: 用户登录记录 + properties: + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + lastLoginAt: + description: 最近一次登录时间 + type: string + x-go-name: LastLoginAt + lastLoginDevice: + description: 最近一次登录设备 + type: string + x-go-name: LastLoginDevice + lastLoginIpv4: + description: 最近一次登录IPv4 + type: string + x-go-name: LastLoginIpv4 + lastLoginUa: + description: 最近一次登录浏览器Ua + type: string + x-go-name: LastLoginUa + loginCount: + description: 总登录次数 + format: uint64 type: integer - x-go-name: Size - total: - description: Total Number | 数据总数 + x-go-name: LoginCount + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + userId: + description: 用户ID + format: int64 + type: string + x-go-name: UserId + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserSocialInfo: + description: 用户社交平台信息 + properties: + accessToken: + description: Access Token | 用户在提供商最近一次登录的访问凭证 + type: string + x-go-name: AccessToken + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + expiresIn: + description: Expires in | 访问凭证过期时长,单位:秒 format: uint64 type: integer - x-go-name: Total + x-go-name: ExpiresIn + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + key: + description: Key | 用户在提供商的用于解密的key + type: string + x-go-name: Key + openId: + description: OpenId | 用户在提供商的OpenID + type: string + x-go-name: OpenId + provider: + description: OAuth Provider | 服务提供商 + type: string + x-go-name: Provider + refreshToken: + description: Refresh Token | 用户在提供商最近一次登录的刷新凭证 + type: string + x-go-name: RefreshToken + uid: + description: User's ID | 提供商用户ID,不一定存在 + type: string + x-go-name: Uid + unionId: + description: UnionId | 用户在提供商的UnionID + type: string + x-go-name: UnionId + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + userId: + description: 系统用户ID + format: int64 + type: string + x-go-name: UserId + userProfile: + description: User Profile | 提供商用户信息,不一定存在 + type: string + x-go-name: UserProfile + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + ValidateCaptchaReq: + description: Validating captcha request | 验证验证码请求 + properties: + captcha: + description: The Captcha which users input | 用户输入的验证码 + maxLength: 4 + type: string + x-go-name: Captcha + captchaId: + description: Captcha ID which store in redis | 图形验证码编号, 存在redis中 + maxLength: 32 + type: string + x-go-name: CaptchaId + clear: + description: Auto remove captcha | 自动删除被验证的验证码 + type: boolean + x-go-name: Clear + required: + - captchaId + - captcha type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types host: localhost:0 @@ -116,36 +874,796 @@ info: title: api version: 0.0.1 paths: - /api/admin/user: + /api/admin/department: + delete: + description: Delete department | 删除部门 + operationId: DeleteDepartmentAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseIDs' + type: object + summary: Delete department | 删除部门 + tags: + - department_admin get: - description: Get user | 获取用户 - operationId: GetUserAdmin + description: Get department | 获取部门 + operationId: GetDepartmentAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: 部门名称 + in: query + name: name + type: string + x-go-name: Name + - description: Leader ID | 负责人ID + format: int64 + in: query + name: leaderId + type: integer + x-go-name: LeaderId + - description: Parent ID | 父节点ID + format: int64 + in: query + name: parentId + type: integer + x-go-name: ParentId + responses: + "200": + description: DepartmentInfo + schema: + $ref: '#/definitions/DepartmentInfo' + summary: Get department | 获取部门 + tags: + - department_admin + /api/admin/department/create: + post: + description: Create department | 创建部门 + operationId: CreateDepartmentAdmin parameters: - in: body name: body schema: - $ref: '#/definitions/UserReq' + $ref: '#/definitions/DepartmentInfo' type: object responses: "200": - description: UserInfo + description: BaseID schema: - $ref: '#/definitions/UserInfo' - summary: Get user | 获取用户 + $ref: '#/definitions/BaseID' + summary: Create department | 创建部门 tags: - - user_admin + - department_admin + /api/admin/department/list: + get: + description: Get department list | 获取部门列表 + operationId: GetDepartmentListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: 部门名称 + in: query + name: name + type: string + x-go-name: Name + - description: Leader ID | 负责人ID + format: int64 + in: query + name: leaderId + type: integer + x-go-name: LeaderId + - description: Parent ID | 父节点ID + format: int64 + in: query + name: parentId + type: integer + x-go-name: ParentId + responses: + "200": + description: DepartmentListResp + schema: + $ref: '#/definitions/DepartmentListResp' + summary: Get department list | 获取部门列表 + tags: + - department_admin + /api/admin/department/update: + post: + description: Update department info | 更新部门信息 + operationId: UpdateDepartmentAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/DepartmentInfo' + type: object + summary: Update department info | 更新部门信息 + tags: + - department_admin + /api/admin/dictionary: + delete: + description: Delete dictionary | 删除字典 + operationId: DeleteDictionaryAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseIDs' + type: object + summary: Delete dictionary | 删除字典 + tags: + - dictionary_admin + get: + description: Get dictionary | 获取字典 + operationId: GetDictionaryAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: 展示名称 + in: query + name: title + type: string + x-go-name: Title + - description: 搜索名称 + in: query + name: name + type: string + x-go-name: Name + - description: Status | 状态 + in: query + name: status + type: string + x-go-name: Status + - description: Keyword | 综合搜索关键字 + in: query + name: keyword + type: string + x-go-name: Keyword + responses: + "200": + description: DictionaryInfo + schema: + $ref: '#/definitions/DictionaryInfo' + summary: Get dictionary | 获取字典 + tags: + - dictionary_admin + /api/admin/dictionary/create: + post: + description: Create dictionary | 创建字典 + operationId: CreateDictionaryAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/DictionaryInfo' + type: object + responses: + "200": + description: BaseID + schema: + $ref: '#/definitions/BaseID' + summary: Create dictionary | 创建字典 + tags: + - dictionary_admin + /api/admin/dictionary/list: + get: + description: Get dictionary list | 获取字典列表 + operationId: GetDictionaryListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: 展示名称 + in: query + name: title + type: string + x-go-name: Title + - description: 搜索名称 + in: query + name: name + type: string + x-go-name: Name + - description: Status | 状态 + in: query + name: status + type: string + x-go-name: Status + - description: Keyword | 综合搜索关键字 + in: query + name: keyword + type: string + x-go-name: Keyword + responses: + "200": + description: DictionaryListResp + schema: + $ref: '#/definitions/DictionaryListResp' + summary: Get dictionary list | 获取字典列表 + tags: + - dictionary_admin + /api/admin/dictionary/update: + post: + description: Update dictionary info | 更新字典信息 + operationId: UpdateDictionaryAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/DictionaryInfo' + type: object + summary: Update dictionary info | 更新字典信息 + tags: + - dictionary_admin + /api/admin/oauth_provider: + get: + description: Get oauth provider by Params | 根据条件获取第三方信息 + operationId: GetOauthProviderAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Name | 第三方提供商名称 + example: wechat + in: query + name: Name + type: string + - description: ClientId | 第三方客户端ID (like) + example: wx21k2j193j2ksdfaak291l + in: query + name: ClientId + type: string + - description: 是否系统内置 + in: query + name: System + type: boolean + - description: 是否已初始化 + in: query + name: Init + type: boolean + responses: + "200": + description: OauthProviderInfo + schema: + $ref: '#/definitions/OauthProviderInfo' + summary: Get oauth provider by Params | 根据条件获取第三方信息 + tags: + - oauthprovider_admin + /api/admin/oauth_provider/create: + post: + description: Create oauth provider information | 创建第三方信息 + operationId: CreateOauthProviderAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/OauthProviderInfo' + type: object + summary: Create oauth provider information | 创建第三方信息 + tags: + - oauthprovider_admin + /api/admin/oauth_provider/delete: + post: + description: Delete oauth provider information | 删除第三方信息 + operationId: DeleteOauthProviderAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseIDs' + type: object + summary: Delete oauth provider information | 删除第三方信息 + tags: + - oauthprovider_admin + /api/admin/oauth_provider/list: + get: + description: Get oauth provider list | 获取第三方信息列表 + operationId: GetOauthProviderListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Name | 第三方提供商名称 + example: wechat + in: query + name: Name + type: string + - description: ClientId | 第三方客户端ID (like) + example: wx21k2j193j2ksdfaak291l + in: query + name: ClientId + type: string + - description: 是否系统内置 + in: query + name: System + type: boolean + - description: 是否已初始化 + in: query + name: Init + type: boolean + responses: + "200": + description: OauthProviderListResp + schema: + $ref: '#/definitions/OauthProviderListResp' + summary: Get oauth provider list | 获取第三方信息列表 + tags: + - oauthprovider_admin + /api/admin/oauth_provider/update: + post: + description: Update oauth provider information | 更新第三方信息 + operationId: UpdateOauthProviderAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/OauthProviderInfo' + type: object + summary: Update oauth provider information | 更新第三方信息 + tags: + - oauthprovider_admin + /api/admin/role: + delete: + description: Delete role information | 删除角色信息 + operationId: DeleteRoleAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseIDs' + type: object + summary: Delete role information | 删除角色信息 + tags: + - role_admin + get: + description: Get Role | 根据条件获取角色 + operationId: GetRoleAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Name | 角色名称 + example: wechat + in: query + name: Name + type: string + - description: Code | 角色编码(Like) + example: Admin + in: query + name: Code + type: string + responses: + "200": + description: RoleInfo + schema: + $ref: '#/definitions/RoleInfo' + summary: Get Role | 根据条件获取角色 + tags: + - role_admin + /api/admin/role/create: post: + description: Create role information | 创建角色 + operationId: CreateRoleAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/RoleInfo' + type: object + summary: Create role information | 创建角色 + tags: + - role_admin + /api/admin/role/list: + get: + description: Get role list | 获取角色列表 + operationId: GetRoleListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Name | 角色名称 + example: wechat + in: query + name: Name + type: string + - description: Code | 角色编码(Like) + example: Admin + in: query + name: Code + type: string + responses: + "200": + description: RoleListResp + schema: + $ref: '#/definitions/RoleListResp' + summary: Get role list | 获取角色列表 + tags: + - role_admin + /api/admin/role/update: + post: + description: Update role information | 更新角色 + operationId: UpdateRoleAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/RoleInfo' + type: object + summary: Update role information | 更新角色 + tags: + - role_admin + /api/admin/token/disable: + post: + description: Disable token | 禁用凭证(强制下线) + operationId: DisableTokenAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseID' + type: object + summary: Disable token | 禁用凭证(强制下线) + tags: + - token_admin + /api/admin/token/list: + get: + description: Get token list | 获取凭证列表 + operationId: GetTokenListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: User id | 用户ID + format: int64 + in: query + name: userId + type: integer + x-go-name: UserID + - description: Token status | Token状态 + in: query + name: status + type: string + x-go-name: Status + - description: Provider source | 提供商来源 + in: query + name: source + type: string + x-go-name: Source + - description: Token type | 凭证类型 [Bearer] + example: Bearer + in: query + name: tokenType + type: string + x-go-name: TokenType + responses: + "200": + description: TokenListResp + schema: + $ref: '#/definitions/TokenListResp' + summary: Get token list | 获取凭证列表 + tags: + - token_admin + /api/admin/user: + delete: description: Delete user | 删除用户 operationId: DeleteUserAdmin parameters: - in: body name: body schema: - $ref: '#/definitions/BaseID' + $ref: '#/definitions/BaseIDs' type: object summary: Delete user | 删除用户 tags: - user_admin + get: + description: Get user | 获取用户 + operationId: GetUserAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Username | 用户名 + in: query + name: username + type: string + x-go-name: Username + - description: PhoneNumber | 手机号码 + in: query + name: phoneNumber + type: string + x-go-name: PhoneNumber + - description: Email | 邮箱 + in: query + name: email + type: string + x-go-name: Email + - description: Nickname | 昵称 + in: query + name: nickname + type: string + x-go-name: Nickname + responses: + "200": + description: UserInfo + schema: + $ref: '#/definitions/UserInfo' + summary: Get user | 获取用户 + tags: + - user_admin /api/admin/user/create: post: description: Create user | 创建用户 @@ -164,6 +1682,204 @@ paths: summary: Create user | 创建用户 tags: - user_admin + /api/admin/user/list: + get: + description: Get user list | 获取用户列表 + operationId: GetUserListAdmin + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Username | 用户名 + in: query + name: username + type: string + x-go-name: Username + - description: PhoneNumber | 手机号码 + in: query + name: phoneNumber + type: string + x-go-name: PhoneNumber + - description: Email | 邮箱 + in: query + name: email + type: string + x-go-name: Email + - description: Nickname | 昵称 + in: query + name: nickname + type: string + x-go-name: Nickname + responses: + "200": + description: UserListResp + schema: + $ref: '#/definitions/UserListResp' + summary: Get user list | 获取用户列表 + tags: + - user_admin + /api/admin/user/update: + post: + description: Update user | 更新用户信息 + operationId: UpdateUserAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/UserInfo' + type: object + summary: Update user | 更新用户信息 + tags: + - user_admin + /api/auth/login: + post: + description: Log in | 密码登录 + operationId: Login + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/LoginReq' + type: object + responses: + "200": + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' + summary: Log in | 密码登录 + tags: + - auth + /api/auth/login/byCode: + post: + description: Log in by code | 验证码登录,手机x邮箱 + operationId: LoginByCode + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/LoginReq' + type: object + responses: + "200": + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' + summary: Log in by code | 验证码登录,手机x邮箱 + tags: + - auth + /api/auth/oauth/login: + get: + description: Oauth log in | Oauth 第三方登录,获取登录地址(通常针对PC网页登录,APP端自行获取code) + operationId: OauthLogin + parameters: + - description: Provider name | 服务提供商名称 + example: '[google, github, facebook]' + in: query + maxLength: 40 + name: Provider + required: true + type: string + responses: + "200": + description: OauthLoginResp + schema: + $ref: '#/definitions/OauthLoginResp' + summary: Oauth log in | Oauth 第三方登录,获取登录地址(通常针对PC网页登录,APP端自行获取code) + tags: + - auth + /api/auth/oauth/login/byCode: + post: + description: Oauth log in by code | Oauth 第三方登录,客户端自行获取code进行登录 + operationId: OauthLoginByCode + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/OauthLoginByCodeReq' + type: object + responses: + "200": + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' + summary: Oauth log in by code | Oauth 第三方登录,客户端自行获取code进行登录 + tags: + - auth + /api/auth/oauth/login/byPhone: + post: + description: Oauth log in by phone code | Oauth 第三方登录,客户端获取换取手机号的code进行登录 + operationId: OauthLoginByPhone + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/OauthLoginByPhoneCodeReq' + type: object + responses: + "200": + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' + summary: Oauth log in by phone code | Oauth 第三方登录,客户端获取换取手机号的code进行登录 + tags: + - auth + /api/auth/oauth/login/callback: + get: + description: Oauth log in callback route | Oauth 登录返回调接口,即redirect_uri + operationId: OauthCallback + responses: + "200": + description: LoginResp + schema: + $ref: '#/definitions/LoginResp' + summary: Oauth log in callback route | Oauth 登录返回调接口,即redirect_uri + tags: + - auth + /api/auth/register: + post: + description: Register | 注册 + operationId: Register + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/RegisterReq' + type: object + responses: + "200": + description: BaseID + schema: + $ref: '#/definitions/BaseID' + summary: Register | 注册 + tags: + - auth /api/base/initDatabase: get: description: Initialize database | 初始化数据库 @@ -171,6 +1887,178 @@ paths: summary: Initialize database | 初始化数据库 tags: - base + /api/captcha: + get: + description: Get Captcha | 获取验证码 + operationId: GetCaptcha + responses: + "200": + description: CaptchaInfo + schema: + $ref: '#/definitions/CaptchaInfo' + summary: Get Captcha | 获取验证码 + tags: + - captcha + /api/captcha/validate: + post: + description: Validating captcha | 验证验证码正确性 + operationId: ValidateCaptcha + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/ValidateCaptchaReq' + type: object + summary: Validating captcha | 验证验证码正确性 + tags: + - captcha + /api/district/children: + get: + description: get district children | 获取子级地址列表 + operationId: GetDistrictChildren + parameters: + - description: Parent Code | 父级Code,若为空,则查询level为1的列表 + in: query + name: parentCode + type: string + x-go-name: ParentCode + responses: + "200": + $ref: '#/responses/*DistrictInfo' + summary: get district children | 获取子级地址列表 + tags: + - district + /api/district/list: + get: + description: get district list | 获取地址列表 + operationId: GetDistrictList + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Page Size | 每页大小 + example: "10" + format: uint64 + in: query + maximum: 9999 + minimum: 0 + name: size + type: integer + x-go-name: Size + - description: Current Page | 当前页 + example: "1" + format: uint64 + in: query + maximum: 100000 + minimum: 1 + name: current + type: integer + x-go-name: Current + - description: Total Number | 数据总数 + format: uint64 + in: query + name: total + type: integer + x-go-name: Total + - description: Name | 地区名称模糊匹配 (like) + in: query + name: name + type: string + x-go-name: Name + - description: Province code | 省级行政编号,表示该地区归属 + in: query + name: province + type: string + x-go-name: Province + - description: City | 地级行政编号,表示该地区归属 + in: query + name: city + type: string + x-go-name: City + - description: Area | 县级行政编号,表示该地区归属 + in: query + name: area + type: string + x-go-name: Area + - description: Street or Town | 乡级行政编号,表示该地区归属 + in: query + name: street + type: string + x-go-name: Street + - description: Level | 地区级别 1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县 4-乡镇 + format: uint32 + in: query + name: level + type: integer + x-go-name: Level + responses: + "200": + $ref: '#/responses/*DistrictInfo' + summary: get district list | 获取地址列表 + tags: + - district + /api/district/name: + get: + description: get district name list | 获取地址名 + operationId: GetDistrictName + parameters: + - description: Code | 地址编码 + in: query + name: code + type: string + x-go-name: Code + - description: Separator | 分隔符,默认为空字符串 + in: query + name: sep + type: string + x-go-name: Separator + responses: + "200": + description: GetDistrictNameResp + schema: + $ref: '#/definitions/GetDistrictNameResp' + summary: get district name list | 获取地址名 + tags: + - district + /api/district/tree: + get: + description: get district tree | 获取地址树,整棵树 + operationId: GetDistrictTree + parameters: + - description: Id | 序号 + format: int64 + in: query + name: id + type: integer + x-go-name: ID + - description: Code | 地址编码 + in: query + name: code + type: string + x-go-name: Code + responses: + "200": + description: DistrictTree + schema: + $ref: '#/definitions/DistrictTree' + summary: get district tree | 获取地址树,整棵树 + tags: + - district + /api/user: + get: + description: Get Current User | 获取当前登录用户信息 + operationId: GetCurrentUser + responses: + "200": + description: UserInfo + schema: + $ref: '#/definitions/UserInfo' + summary: Get Current User | 获取当前登录用户信息 + tags: + - user produces: - application/json schemes: diff --git a/rpc/core/etc/core.yaml b/rpc/core/etc/core.yaml index 4e73a17..2218fa8 100644 --- a/rpc/core/etc/core.yaml +++ b/rpc/core/etc/core.yaml @@ -1,8 +1,13 @@ -Name: core.rpc +Name: n-admin.core.rpc ListenOn: 0.0.0.0:18888 Timeout: 0 Mode: dev +Etcd: + Hosts: + - 192.168.1.155:2379 + Key: n-admin.core.rpc + Log: ServiceName: coreRpcLogger Mode: console