[MISC] Minor Cleanup in `types` + `enum` Package (#186)

jobatzil/rename
Johannes Batzill 2023-01-11 23:16:07 -08:00 committed by GitHub
parent 5b55f48772
commit 155563615b
9 changed files with 22 additions and 42 deletions

View File

@ -35,7 +35,7 @@ type listCommand struct {
func (c *listCommand) run(*kingpin.ParseContext) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
list, err := c.client.UserList(ctx, types.Params{
list, err := c.client.UserList(ctx, types.UserFilter{
Size: c.size,
Page: c.page,
})

View File

@ -112,7 +112,7 @@ func (c *HTTPClient) User(ctx context.Context, key string) (*types.User, error)
}
// UserList returns a list of all registered users.
func (c *HTTPClient) UserList(ctx context.Context, params types.Params) ([]types.User, error) {
func (c *HTTPClient) UserList(ctx context.Context, params types.UserFilter) ([]types.User, error) {
out := []types.User{}
uri := fmt.Sprintf("%s/api/v1/users?page=%d&limit=%d", c.base, params.Page, params.Size)
err := c.get(ctx, uri, &out)

View File

@ -26,7 +26,7 @@ type Client interface {
User(ctx context.Context, key string) (*types.User, error)
// UserList returns a list of all registered users.
UserList(ctx context.Context, params types.Params) ([]types.User, error)
UserList(ctx context.Context, params types.UserFilter) ([]types.User, error)
// UserCreate creates a new user account.
UserCreate(ctx context.Context, user *types.User) (*types.User, error)

View File

@ -142,7 +142,7 @@ func (mr *MockClientMockRecorder) UserDelete(arg0, arg1 interface{}) *gomock.Cal
}
// UserList mocks base method.
func (m *MockClient) UserList(arg0 context.Context, arg1 types.Params) ([]types.User, error) {
func (m *MockClient) UserList(arg0 context.Context, arg1 types.UserFilter) ([]types.User, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserList", arg0, arg1)
ret0, _ := ret[0].([]types.User)

View File

@ -11,6 +11,8 @@ const (
uid = "uid"
path = "path"
name = "name"
email = "email"
admin = "admin"
number = "number"
created = "created"
createdAt = "created_at"
@ -24,6 +26,10 @@ const (
system = "system"
comment = "comment"
code = "code"
asc = "asc"
ascending = "ascending"
desc = "desc"
descending = "descending"
)
func existsInSortedSlice(strs []string, s string) bool {

View File

@ -1,6 +0,0 @@
// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
// Package enum defines common enumerations.
package enum

View File

@ -22,13 +22,13 @@ const (
func (e Order) String() string {
switch e {
case OrderDesc:
return "desc"
return desc
case OrderAsc:
return "asc"
return asc
case OrderDefault:
return "default"
return defaultString
default:
return "unknown"
return undefined
}
}
@ -36,9 +36,9 @@ func (e Order) String() string {
// an order enumeration.
func ParseOrder(s string) Order {
switch strings.ToLower(s) {
case "asc", "ascending":
case asc, ascending:
return OrderAsc
case "desc", "descending":
case desc, descending:
return OrderDesc
default:
return OrderDefault

View File

@ -25,17 +25,17 @@ const (
// and returns the equivalent enumeration.
func ParseUserAttr(s string) UserAttr {
switch strings.ToLower(s) {
case "id":
case uid:
return UserAttrUID
case "name":
case name:
return UserAttrName
case "email":
case email:
return UserAttrEmail
case "admin":
case admin:
return UserAttrAdmin
case "created", "created_at":
case created, createdAt:
return UserAttrCreated
case "updated", "updated_at":
case updated, updatedAt:
return UserAttrUpdated
default:
return UserAttrNone

View File

@ -1,20 +0,0 @@
// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
// Package types defines common data structures.
package types
import (
"github.com/harness/gitness/types/enum"
)
type (
// Params stores query parameters.
Params struct {
Page int `json:"page"`
Size int `json:"size"`
Sort string `json:"sort"`
Order enum.Order `json:"order"`
}
)