Skip to content

Commit

Permalink
#57 using boolean and rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
setiadijoe committed Jun 23, 2021
1 parent 0fa6465 commit 3aa2b2d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func MakeGetListUserPost(ctx context.Context, usecase usecase.UsecaseI) endpoint
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
req := request.(*GetListUserPostRequest)
orderBy := helper.GetStringFromPointer(req.OrderBy)
if req.OrderBy != nil && isOrder(orderBy) == -1 {
if req.OrderBy != nil && !isOrderValid(orderBy) {
return nil, errors.New("order_must_between_ASC_DESC")
}
// TODO: for get metadata from headers grpc needs to update when using authorization
Expand Down
6 changes: 3 additions & 3 deletions endpoint/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ var ordering = map[int]string{
1: "DESC",
}

func isOrder(val string) int {
func isOrderValid(val string) bool {
for i := range ordering {
if ordering[i] == val {
return i
return true
}
}

return -1
return false
}

0 comments on commit 3aa2b2d

Please sign in to comment.