Skip to content

Commit

Permalink
♻️ Refactor(paginate.go): update no offeset query id
Browse files Browse the repository at this point in the history
  • Loading branch information
booscaaa committed Nov 10, 2023
1 parent 43a51ae commit 23473a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions v2/paginate/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func GenerateSQL(params *paginQueryParams) (string, []interface{}) {
if columnName != "" {
argNum := nextArg()
argNumNext := nextArg()
sortClauses = append(sortClauses, fmt.Sprintf("((%s = $%d) OR (%s %s $%d AND id %s $%d))",
sortClauses = append(sortClauses, fmt.Sprintf("(((%s = $%d) OR (%s %s $%d)) AND id %s $%d)",
columnName, argNum, columnName, getComparisonOperator(params.SortDirections[i]), argNum, getComparisonOperator(params.SortDirections[i]), argNumNext))
args[len(args)-2] = params.mapArgs[column]
args[len(args)-1] = params.mapArgs["id"]
Expand Down Expand Up @@ -352,9 +352,9 @@ func GenerateSQL(params *paginQueryParams) (string, []interface{}) {

func getComparisonOperator(direction string) string {
if direction == "true" {
return ">"
return "<"
}
return "<"
return ">"
}

func GenerateCountQuery(params *paginQueryParams) (string, []interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions v2/paginate/paginate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ func TestGenerateCountQuery(t *testing.T) {
func TestGetComparisonOperator(t *testing.T) {
// Test case 1: Sorting direction is true (descending)
operator := getComparisonOperator("true")
expectedOperator := ">"
expectedOperator := "<"
if operator != expectedOperator {
t.Errorf("Expected operator: %s, Got: %s", expectedOperator, operator)
}

// Test case 2: Sorting direction is false (ascending)
operator = getComparisonOperator("false")
expectedOperator = "<"
expectedOperator = ">"
if operator != expectedOperator {
t.Errorf("Expected operator: %s, Got: %s", expectedOperator, operator)
}
Expand Down

0 comments on commit 23473a9

Please sign in to comment.