From 631f6f96b24c7c2cc3162af4c2d435134ae10fb2 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Thu, 10 Apr 2025 23:25:29 +0800 Subject: [PATCH] refactor: simplify sorting logic in GetSortsFromString function - Adjusted the handling of sorting direction by directly checking for descending and ascending prefixes. - Removed redundant code for handling ascending sorting, streamlining the function's logic. - Enhanced code clarity and maintainability by simplifying the sorting parameter processing. --- core/controllers/utils.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/controllers/utils.go b/core/controllers/utils.go index 0b77feaf..4930fe09 100644 --- a/core/controllers/utils.go +++ b/core/controllers/utils.go @@ -200,20 +200,14 @@ func GetSortsFromString(sortStr string) (sorts []entity.Sort, err error) { if trimmed == "" { continue } - if !strings.HasPrefix(trimmed, "-") { - key := strings.TrimLeft(trimmed, "+") + if strings.HasPrefix(trimmed, "-") { + key := strings.TrimLeft(trimmed, "-") sorts = append(sorts, entity.Sort{ Key: key, Direction: constants.DESCENDING, }) - } else if strings.HasPrefix(trimmed, "+") { - key := strings.TrimLeft(trimmed, "+") - sorts = append(sorts, entity.Sort{ - Key: key, - Direction: constants.ASCENDING, - }) } else { - key := strings.TrimLeft(trimmed, "-") + key := strings.TrimLeft(trimmed, "+") sorts = append(sorts, entity.Sort{ Key: key, Direction: constants.ASCENDING,