feat: 添加api接口,几乎完善。

main
NoahLan 1 year ago
parent 53ee858140
commit 1173086e2f

@ -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"
@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"

@ -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()
}

@ -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"

@ -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)
}

@ -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)
}

@ -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"`

@ -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提供商查询返回

@ -52,7 +52,7 @@ service api {
// Delete user | 删除用户
@handler deleteUserAdmin
delete / (BaseID)
delete / (BaseIDs)
}
@server(

@ -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: "此用户很懒,什么都没留下。"

@ -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

@ -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"`
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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"),
)
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save