mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
fix: Fix order by sorting rule not taking effect issue (#11871)
This commit is contained in:
+6
-10
@@ -62,16 +62,12 @@ func WithByNode(node string) global.DBOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithOrderBy(orderStr string) global.DBOption {
|
||||
if orderStr == "createdAt" {
|
||||
orderStr = "created_at"
|
||||
}
|
||||
if !re.GetRegex(re.OrderByValidationPattern).MatchString(orderStr) {
|
||||
orderStr = "created_at"
|
||||
}
|
||||
return func(g *gorm.DB) *gorm.DB {
|
||||
return g.Order(orderStr)
|
||||
}
|
||||
func WithOrderDesc(orderBy string) global.DBOption {
|
||||
return WithOrderRuleBy(orderBy, constant.OrderDesc)
|
||||
}
|
||||
|
||||
func WithOrderAsc(orderBy string) global.DBOption {
|
||||
return WithOrderRuleBy(orderBy, constant.OrderAsc)
|
||||
}
|
||||
|
||||
func WithOrderRuleBy(orderBy, order string) global.DBOption {
|
||||
|
||||
@@ -33,7 +33,7 @@ func NewICommandService() ICommandService {
|
||||
}
|
||||
|
||||
func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error) {
|
||||
commands, err := commandRepo.List(repo.WithOrderBy("name"), repo.WithByType(req.Type))
|
||||
commands, err := commandRepo.List(repo.WithOrderAsc("name"), repo.WithByType(req.Type))
|
||||
if err != nil {
|
||||
return nil, buserr.New("ErrRecordNotFound")
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error)
|
||||
}
|
||||
|
||||
func (u *CommandService) SearchForTree(req dto.OperateByType) ([]dto.CommandTree, error) {
|
||||
cmdList, err := commandRepo.List(repo.WithOrderBy("name"), repo.WithByType(req.Type))
|
||||
cmdList, err := commandRepo.List(repo.WithOrderAsc("name"), repo.WithByType(req.Type))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ func NewIGroupService() IGroupService {
|
||||
|
||||
func (u *GroupService) List(req dto.OperateByType) ([]dto.GroupInfo, error) {
|
||||
options := []global.DBOption{
|
||||
repo.WithOrderBy("is_default desc"),
|
||||
repo.WithOrderBy("created_at desc"),
|
||||
repo.WithOrderDesc("is_default"),
|
||||
repo.WithOrderDesc("created_at"),
|
||||
}
|
||||
if len(req.Type) != 0 {
|
||||
options = append(options, repo.WithByType(req.Type))
|
||||
|
||||
@@ -38,7 +38,7 @@ func (u *LogService) CreateLoginLog(operation model.LoginLog) error {
|
||||
|
||||
func (u *LogService) PageLoginLog(ctx *gin.Context, req dto.SearchLgLogWithPage) (int64, interface{}, error) {
|
||||
options := []global.DBOption{
|
||||
repo.WithOrderBy("created_at desc"),
|
||||
repo.WithOrderDesc("created_at"),
|
||||
}
|
||||
if len(req.IP) != 0 {
|
||||
options = append(options, logRepo.WithByIP(req.IP))
|
||||
@@ -72,7 +72,7 @@ func (u *LogService) CreateOperationLog(operation *model.OperationLog) error {
|
||||
|
||||
func (u *LogService) PageOperationLog(req dto.SearchOpLogWithPage) (int64, interface{}, error) {
|
||||
options := []global.DBOption{
|
||||
repo.WithOrderBy("created_at desc"),
|
||||
repo.WithOrderDesc("created_at"),
|
||||
logRepo.WithByLikeOperation(req.Operation),
|
||||
}
|
||||
if len(req.Source) != 0 {
|
||||
|
||||
@@ -43,7 +43,7 @@ func NewIScriptService() IScriptService {
|
||||
}
|
||||
|
||||
func (u *ScriptService) Search(ctx *gin.Context, req dto.SearchPageWithGroup) (int64, interface{}, error) {
|
||||
options := []global.DBOption{repo.WithOrderBy("created_at desc")}
|
||||
options := []global.DBOption{repo.WithOrderDesc("created_at")}
|
||||
if len(req.Info) != 0 {
|
||||
options = append(options, scriptRepo.WithByInfo(req.Info))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user