mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user