Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions core/app/repo/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions core/app/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions core/app/service/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions core/app/service/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/app/service/script_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Loading