From af819e61a0b677c4ce723eec069e8ca928d66d62 Mon Sep 17 00:00:00 2001 From: Alexander Karl Date: Tue, 30 Nov 2021 10:22:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20ChangeOrderRequest:=20Allow=20ze?= =?UTF-8?q?ro=20as=20targetIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- policy/policy_test.go | 6 ++++-- policy/request.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/policy/policy_test.go b/policy/policy_test.go index 7ad333d..9a3e7b8 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -359,16 +359,18 @@ func TestDeletePolicy_Validate(t *testing.T) { } func TestChangeOrder_Validate(t *testing.T) { + targetIndex := -1 request := &ChangeOrderRequest{ Id: "asd", TeamId: "asd", Type: NotificationPolicy, - TargetIndex: -1, + TargetIndex: &targetIndex, } err := request.Validate() assert.Equal(t, "target index should be at least 0", err.Error()) - request.TargetIndex = 0 + targetIndex = 0 + request.TargetIndex = &targetIndex err = request.Validate() assert.Nil(t, err) } diff --git a/policy/request.go b/policy/request.go index fc66efc..00aed2a 100644 --- a/policy/request.go +++ b/policy/request.go @@ -440,7 +440,7 @@ type ChangeOrderRequest struct { Id string `json:"id,omitempty"` TeamId string Type PolicyType - TargetIndex int `json:"targetIndex,omitempty"` + TargetIndex *int `json:"targetIndex,omitempty"` } func (r *ChangeOrderRequest) Validate() error { @@ -451,7 +451,7 @@ func (r *ChangeOrderRequest) Validate() error { if err != nil { return err } - if r.TargetIndex < 0 { + if *r.TargetIndex < 0 { return errors.New("target index should be at least 0") } return nil