Skip to content

Commit

Permalink
Update SortOrder type alias and make ListParams JSON serializable (
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Jan 19, 2024
1 parent 9d92981 commit 3270675
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
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

0 comments on commit 3270675

Please sign in to comment.