From 3aa2b2d19374dc7e6d4b8b4c5caaf7c52634d0ff Mon Sep 17 00:00:00 2001 From: setiadijoe Date: Wed, 23 Jun 2021 13:04:48 +0700 Subject: [PATCH] #57 using boolean and rename function --- endpoint/endpoint.go | 2 +- endpoint/request.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 4218b52..436c2d6 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -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 diff --git a/endpoint/request.go b/endpoint/request.go index 2e3ff74..0e711e8 100644 --- a/endpoint/request.go +++ b/endpoint/request.go @@ -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 }