Skip to content

Commit 3270675

Browse files
authored
Update SortOrder type alias and make ListParams JSON serializable (#288)
1 parent 9d92981 commit 3270675

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

pkg/authz/warrant/list.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323
)
2424

2525
type FilterParams struct {
26-
ObjectType []string
27-
ObjectId []string
28-
Relation []string
29-
SubjectType []string
30-
SubjectId []string
31-
SubjectRelation []string
32-
Policy Policy
26+
ObjectType []string `json:"objectType,omitempty"`
27+
ObjectId []string `json:"objectId,omitempty"`
28+
Relation []string `json:"relation,omitempty"`
29+
SubjectType []string `json:"subjectType,omitempty"`
30+
SubjectId []string `json:"subjectId,omitempty"`
31+
SubjectRelation []string `json:"subjectRelation,omitempty"`
32+
Policy Policy `json:"policy,omitempty"`
3333
}
3434

3535
func (fp FilterParams) String() string {

pkg/object/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
type FilterOptions struct {
25-
ObjectType string
25+
ObjectType string `json:"objectType,omitempty"`
2626
}
2727

2828
type ObjectSpec struct {

pkg/service/list.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ const (
4242
defaultPage = 1
4343
contextKeyListParams key = iota
4444

45-
SortOrderAsc SortOrder = iota
46-
SortOrderDesc SortOrder = iota
45+
SortOrderAsc SortOrder = "ASC"
46+
SortOrderDesc SortOrder = "DESC"
4747
)
4848

49-
type SortOrder int
49+
type SortOrder string
5050

5151
func (so SortOrder) String() string {
52-
if so == SortOrderAsc {
53-
return "ASC"
54-
}
55-
56-
if so == SortOrderDesc {
57-
return "DESC"
52+
if so == SortOrderAsc || so == SortOrderDesc {
53+
return string(so)
5854
}
5955

6056
return ""
@@ -155,18 +151,18 @@ type ListParamParser interface {
155151
}
156152

157153
type ListParams struct {
158-
Page int
159-
Limit int
160-
Query *string
161-
SortBy string
162-
SortOrder SortOrder
163-
NextCursor *Cursor
164-
PrevCursor *Cursor
154+
Page int `json:"-"`
155+
Limit int `json:"limit,omitempty"`
156+
Query *string `json:"q,omitempty"`
157+
SortBy string `json:"sortBy,omitempty"`
158+
SortOrder SortOrder `json:"sortOrder,omitempty"`
159+
PrevCursor *Cursor `json:"prevCursor,omitempty"`
160+
NextCursor *Cursor `json:"nextCursor,omitempty"`
165161
defaultSortBy string
166162
}
167163

168164
func (lp ListParams) String() string {
169-
s := fmt.Sprintf("page=%d&limit=%d&sortBy=%s&sortOrder=%d&defaultSortBy=%s",
165+
s := fmt.Sprintf("page=%d&limit=%d&sortBy=%s&sortOrder=%s&defaultSortBy=%s",
170166
lp.Page,
171167
lp.Limit,
172168
lp.SortBy,

0 commit comments

Comments
 (0)