refactor: 包名变更ctx -> req

This commit is contained in:
meilin.huang
2023-01-14 16:29:52 +08:00
parent 2a91cdb67a
commit 594ca43505
46 changed files with 395 additions and 401 deletions

View File

@@ -8,9 +8,9 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/captcha"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
"regexp"
"strconv"
@@ -29,7 +29,7 @@ type Account struct {
/** 登录者个人相关操作 **/
// @router /accounts/login [post]
func (a *Account) Login(rc *ctx.ReqCtx) {
func (a *Account) Login(rc *req.Ctx) {
loginForm := &form.LoginForm{}
ginx.BindJsonAndValid(rc.GinCtx, loginForm)
@@ -65,7 +65,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
}
}
// 保存该账号的权限codes
ctx.SavePermissionCodes(account.Id, permissions)
req.SavePermissionCodes(account.Id, permissions)
clientIp := rc.GinCtx.ClientIP()
// 保存登录消息
@@ -76,7 +76,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username}
rc.ResData = map[string]interface{}{
"token": ctx.CreateToken(account.Id, account.Username),
"token": req.CreateToken(account.Id, account.Username),
"name": account.Name,
"username": account.Username,
"lastLoginTime": account.LastLoginTime,
@@ -86,7 +86,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
}
}
func (a *Account) ChangePassword(rc *ctx.ReqCtx) {
func (a *Account) ChangePassword(rc *req.Ctx) {
form := new(form.AccountChangePasswordForm)
ginx.BindJsonAndValid(rc.GinCtx, form)
@@ -153,7 +153,7 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
}
// 获取个人账号信息
func (a *Account) AccountInfo(rc *ctx.ReqCtx) {
func (a *Account) AccountInfo(rc *req.Ctx) {
ap := new(vo.AccountPersonVO)
// 角色信息
roles := new([]vo.AccountRoleVO)
@@ -164,7 +164,7 @@ func (a *Account) AccountInfo(rc *ctx.ReqCtx) {
}
// 更新个人账号信息
func (a *Account) UpdateAccount(rc *ctx.ReqCtx) {
func (a *Account) UpdateAccount(rc *req.Ctx) {
updateForm := &form.AccountUpdateForm{}
ginx.BindJsonAndValid(rc.GinCtx, updateForm)
@@ -181,7 +181,7 @@ func (a *Account) UpdateAccount(rc *ctx.ReqCtx) {
}
// 获取账号接收的消息列表
func (a *Account) GetMsgs(rc *ctx.ReqCtx) {
func (a *Account) GetMsgs(rc *req.Ctx) {
condition := &entity.Msg{
RecipientId: int64(rc.LoginAccount.Id),
}
@@ -191,14 +191,14 @@ func (a *Account) GetMsgs(rc *ctx.ReqCtx) {
/** 后台账号操作 **/
// @router /accounts [get]
func (a *Account) Accounts(rc *ctx.ReqCtx) {
func (a *Account) Accounts(rc *req.Ctx) {
condition := &entity.Account{}
condition.Username = rc.GinCtx.Query("username")
rc.ResData = a.AccountApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.AccountManageVO))
}
// @router /accounts
func (a *Account) SaveAccount(rc *ctx.ReqCtx) {
func (a *Account) SaveAccount(rc *req.Ctx) {
form := &form.AccountCreateForm{}
ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form
@@ -218,7 +218,7 @@ func (a *Account) SaveAccount(rc *ctx.ReqCtx) {
}
}
func (a *Account) ChangeStatus(rc *ctx.ReqCtx) {
func (a *Account) ChangeStatus(rc *req.Ctx) {
g := rc.GinCtx
account := &entity.Account{}
@@ -228,25 +228,25 @@ func (a *Account) ChangeStatus(rc *ctx.ReqCtx) {
a.AccountApp.Update(account)
}
func (a *Account) DeleteAccount(rc *ctx.ReqCtx) {
func (a *Account) DeleteAccount(rc *req.Ctx) {
id := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
rc.ReqParam = id
a.AccountApp.Delete(id)
}
// 获取账号角色id列表用户回显角色分配
func (a *Account) AccountRoleIds(rc *ctx.ReqCtx) {
func (a *Account) AccountRoleIds(rc *req.Ctx) {
rc.ResData = a.RoleApp.GetAccountRoleIds(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
}
// 获取账号角色id列表用户回显角色分配
func (a *Account) AccountRoles(rc *ctx.ReqCtx) {
func (a *Account) AccountRoles(rc *req.Ctx) {
vos := new([]vo.AccountRoleVO)
a.RoleApp.GetAccountRoles(uint64(ginx.PathParamInt(rc.GinCtx, "id")), vos)
rc.ResData = vos
}
func (a *Account) AccountResources(rc *ctx.ReqCtx) {
func (a *Account) AccountResources(rc *req.Ctx) {
var resources vo.ResourceManageVOList
// 获取账号菜单资源
a.ResourceApp.GetAccountResources(uint64(ginx.PathParamInt(rc.GinCtx, "id")), &resources)
@@ -254,7 +254,7 @@ func (a *Account) AccountResources(rc *ctx.ReqCtx) {
}
// 保存账号角色信息
func (a *Account) SaveRoles(rc *ctx.ReqCtx) {
func (a *Account) SaveRoles(rc *req.Ctx) {
g := rc.GinCtx
var form form.AccountRoleForm

View File

@@ -2,10 +2,10 @@ package api
import (
"mayfly-go/pkg/captcha"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/req"
)
func GenerateCaptcha(rc *ctx.ReqCtx) {
func GenerateCaptcha(rc *req.Ctx) {
id, image := captcha.Generate()
rc.ResData = map[string]interface{}{"base64Captcha": image, "cid": id}
}

View File

@@ -5,8 +5,8 @@ import (
"mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
)
@@ -14,19 +14,19 @@ type Config struct {
ConfigApp application.Config
}
func (c *Config) Configs(rc *ctx.ReqCtx) {
func (c *Config) Configs(rc *req.Ctx) {
g := rc.GinCtx
condition := &entity.Config{Key: g.Query("key")}
rc.ResData = c.ConfigApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Config))
}
func (c *Config) GetConfigValueByKey(rc *ctx.ReqCtx) {
func (c *Config) GetConfigValueByKey(rc *req.Ctx) {
key := rc.GinCtx.Query("key")
biz.NotEmpty(key, "key不能为空")
rc.ResData = c.ConfigApp.GetConfig(key).Value
}
func (c *Config) SaveConfig(rc *ctx.ReqCtx) {
func (c *Config) SaveConfig(rc *req.Ctx) {
g := rc.GinCtx
form := &form.ConfigForm{}
ginx.BindJsonAndValid(g, form)

View File

@@ -6,8 +6,8 @@ import (
"mayfly-go/internal/sys/api/vo"
"mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
)
@@ -15,17 +15,17 @@ type Resource struct {
ResourceApp application.Resource
}
func (r *Resource) GetAllResourceTree(rc *ctx.ReqCtx) {
func (r *Resource) GetAllResourceTree(rc *req.Ctx) {
var resources vo.ResourceManageVOList
r.ResourceApp.GetResourceList(new(entity.Resource), &resources, "weight asc")
rc.ResData = resources.ToTrees(0)
}
func (r *Resource) GetById(rc *ctx.ReqCtx) {
func (r *Resource) GetById(rc *req.Ctx) {
rc.ResData = r.ResourceApp.GetById(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
}
func (r *Resource) SaveResource(rc *ctx.ReqCtx) {
func (r *Resource) SaveResource(rc *req.Ctx) {
g := rc.GinCtx
form := new(form.ResourceForm)
ginx.BindJsonAndValid(g, form)
@@ -41,11 +41,11 @@ func (r *Resource) SaveResource(rc *ctx.ReqCtx) {
r.ResourceApp.Save(entity)
}
func (r *Resource) DelResource(rc *ctx.ReqCtx) {
func (r *Resource) DelResource(rc *req.Ctx) {
r.ResourceApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
}
func (r *Resource) ChangeStatus(rc *ctx.ReqCtx) {
func (r *Resource) ChangeStatus(rc *req.Ctx) {
re := &entity.Resource{}
re.Id = uint64(ginx.PathParamInt(rc.GinCtx, "id"))
re.Status = int8(ginx.PathParamInt(rc.GinCtx, "status"))

View File

@@ -5,8 +5,8 @@ import (
"mayfly-go/internal/sys/api/vo"
"mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
"strconv"
"strings"
@@ -18,14 +18,14 @@ type Role struct {
ResourceApp application.Resource
}
func (r *Role) Roles(rc *ctx.ReqCtx) {
func (r *Role) Roles(rc *req.Ctx) {
g := rc.GinCtx
condition := &entity.Role{}
rc.ResData = r.RoleApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Role))
}
// 保存角色信息
func (r *Role) SaveRole(rc *ctx.ReqCtx) {
func (r *Role) SaveRole(rc *req.Ctx) {
g := rc.GinCtx
form := &form.RoleForm{}
ginx.BindJsonAndValid(g, form)
@@ -39,17 +39,17 @@ func (r *Role) SaveRole(rc *ctx.ReqCtx) {
}
// 删除角色及其资源关联关系
func (r *Role) DelRole(rc *ctx.ReqCtx) {
func (r *Role) DelRole(rc *req.Ctx) {
r.RoleApp.DeleteRole(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
}
// 获取角色关联的资源id数组用于分配资源时回显已拥有的资源
func (r *Role) RoleResourceIds(rc *ctx.ReqCtx) {
func (r *Role) RoleResourceIds(rc *req.Ctx) {
rc.ResData = r.RoleApp.GetRoleResourceIds(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
}
// 查看角色关联的资源树信息
func (r *Role) RoleResource(rc *ctx.ReqCtx) {
func (r *Role) RoleResource(rc *req.Ctx) {
g := rc.GinCtx
var resources vo.ResourceManageVOList
@@ -59,7 +59,7 @@ func (r *Role) RoleResource(rc *ctx.ReqCtx) {
}
// 保存角色资源
func (r *Role) SaveResource(rc *ctx.ReqCtx) {
func (r *Role) SaveResource(rc *req.Ctx) {
g := rc.GinCtx
var form form.RoleResourceForm

View File

@@ -3,15 +3,15 @@ package api
import (
"mayfly-go/internal/sys/application"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
)
type Syslog struct {
SyslogApp application.Syslog
}
func (r *Syslog) Syslogs(rc *ctx.ReqCtx) {
func (r *Syslog) Syslogs(rc *req.Ctx) {
g := rc.GinCtx
condition := &entity.Syslog{
Type: int8(ginx.QueryInt(g, "type", 0)),

View File

@@ -2,8 +2,8 @@ package api
import (
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ctx"
"mayfly-go/pkg/global"
"mayfly-go/pkg/req"
"mayfly-go/pkg/ws"
"github.com/gin-gonic/gin"
@@ -30,8 +30,8 @@ func (s *System) ConnectWs(g *gin.Context) {
panic(biz.NewBizErr("升级websocket失败"))
}
// 权限校验
rc := ctx.NewReqCtxWithGin(g)
if err = ctx.PermissionHandler(rc); err != nil {
rc := req.NewCtxWithGin(g)
if err = req.PermissionHandler(rc); err != nil {
panic(biz.NewBizErr("没有权限"))
}