Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SortOrder type alias and make ListParams JSON serializable #288

Merged
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
14 changes: 7 additions & 7 deletions pkg/authz/warrant/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
)

type FilterParams struct {
ObjectType []string
ObjectId []string
Relation []string
SubjectType []string
SubjectId []string
SubjectRelation []string
Policy Policy
ObjectType []string `json:"objectType,omitempty"`
ObjectId []string `json:"objectId,omitempty"`
Relation []string `json:"relation,omitempty"`
SubjectType []string `json:"subjectType,omitempty"`
SubjectId []string `json:"subjectId,omitempty"`
SubjectRelation []string `json:"subjectRelation,omitempty"`
Policy Policy `json:"policy,omitempty"`
}

func (fp FilterParams) String() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

type FilterOptions struct {
ObjectType string
ObjectType string `json:"objectType,omitempty"`
}

type ObjectSpec struct {
Expand Down
30 changes: 13 additions & 17 deletions pkg/service/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ const (
defaultPage = 1
contextKeyListParams key = iota

SortOrderAsc SortOrder = iota
SortOrderDesc SortOrder = iota
SortOrderAsc SortOrder = "ASC"
SortOrderDesc SortOrder = "DESC"
)

type SortOrder int
type SortOrder string

func (so SortOrder) String() string {
if so == SortOrderAsc {
return "ASC"
}

if so == SortOrderDesc {
return "DESC"
if so == SortOrderAsc || so == SortOrderDesc {
return string(so)
}

return ""
Expand Down Expand Up @@ -155,18 +151,18 @@ type ListParamParser interface {
}

type ListParams struct {
Page int
Limit int
Query *string
SortBy string
SortOrder SortOrder
NextCursor *Cursor
PrevCursor *Cursor
Page int `json:"-"`
Limit int `json:"limit,omitempty"`
Query *string `json:"q,omitempty"`
SortBy string `json:"sortBy,omitempty"`
SortOrder SortOrder `json:"sortOrder,omitempty"`
PrevCursor *Cursor `json:"prevCursor,omitempty"`
NextCursor *Cursor `json:"nextCursor,omitempty"`
defaultSortBy string
}

func (lp ListParams) String() string {
s := fmt.Sprintf("page=%d&limit=%d&sortBy=%s&sortOrder=%d&defaultSortBy=%s",
s := fmt.Sprintf("page=%d&limit=%d&sortBy=%s&sortOrder=%s&defaultSortBy=%s",
lp.Page,
lp.Limit,
lp.SortBy,
Expand Down
Loading