-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eng 2735 Add order by and limit parameters for V2 workflow results (#…
…1240) Co-authored-by: Eunice Chan <[email protected]>
- Loading branch information
1 parent
e739720
commit f7e889e
Showing
13 changed files
with
234 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package parser | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/dropbox/godropbox/errors" | ||
) | ||
|
||
type LimitQueryParser struct{} | ||
|
||
func (LimitQueryParser) Parse(r *http.Request) (int, error) { | ||
query := r.URL.Query() | ||
|
||
var err error | ||
limit := -1 | ||
if limitVal := query.Get("limit"); len(limitVal) > 0 { | ||
limit, err = strconv.Atoi(limitVal) | ||
if err != nil { | ||
return -1, errors.Wrap(err, "Invalid limit parameter.") | ||
} | ||
} | ||
|
||
return limit, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package parser | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/dropbox/godropbox/errors" | ||
) | ||
|
||
type OrderByQueryParser struct{} | ||
|
||
func (OrderByQueryParser) Parse(r *http.Request, tableColumns []string) (string, error) { | ||
query := r.URL.Query() | ||
|
||
var err error | ||
var orderBy string | ||
if orderByVal := query.Get("order_by"); len(orderByVal) > 0 { | ||
// Check is a field in table | ||
isColumn := false | ||
for _, column := range tableColumns { | ||
if column == orderByVal { | ||
isColumn = true | ||
break | ||
} | ||
} | ||
if !isColumn { | ||
return "", errors.Wrap(err, "Invalid order_by value.") | ||
} | ||
orderBy = orderByVal | ||
} | ||
|
||
return orderBy, nil | ||
} |
31 changes: 31 additions & 0 deletions
31
src/golang/cmd/server/request/parser/query_order_descending.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package parser | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/dropbox/godropbox/errors" | ||
) | ||
|
||
type OrderDescendingQueryParser struct{} | ||
|
||
func (OrderDescendingQueryParser) Parse(r *http.Request) (bool, error) { | ||
query := r.URL.Query() | ||
|
||
var err error | ||
orderDescending := true | ||
if orderDescendingVal := query.Get("order_descending"); len(orderDescendingVal) > 0 { | ||
orderDescendingVal = strings.ToLower(orderDescendingVal) | ||
if orderDescendingVal == "true" { | ||
return true, nil | ||
} | ||
|
||
if orderDescendingVal == "false" { | ||
return false, nil | ||
} | ||
|
||
return true, errors.Wrap(err, "Invalid order_descending value.") | ||
} | ||
|
||
return orderDescending, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters