diff --git a/backend/core/models/common/string_int64.go b/backend/core/models/common/string_int64.go new file mode 100644 index 00000000000..479996d40a0 --- /dev/null +++ b/backend/core/models/common/string_int64.go @@ -0,0 +1,78 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "database/sql/driver" + "encoding/json" + "fmt" + "github.com/spf13/cast" +) + +type StringInt64 struct { + v int64 +} + +func NewStringInt64FromAny(f interface{}) *StringInt64 { + return &StringInt64{ + v: cast.ToInt64(f), + } +} + +func (f *StringInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(f.v) +} + +func (f *StringInt64) String() string { + return fmt.Sprintf("%v", f.v) +} + +func (f *StringInt64) UnmarshalJSON(data []byte) error { + var i interface{} + if err := json.Unmarshal(data, &i); err != nil { + return err + } + if v, ok := i.(string); ok && v == "" { + return nil + } + value, err := cast.ToInt64E(i) + if err != nil { + return err + } + f.v = value + return nil +} + +func (f *StringInt64) Value() (driver.Value, error) { + if f == nil { + return nil, nil + } + return f.v, nil +} + +func (f *StringInt64) Scan(v interface{}) error { + int64value, err := cast.ToInt64E(v) + if err != nil { + return err + + } + *f = StringInt64{ + v: int64value, + } + return nil +} diff --git a/backend/helpers/pluginhelper/api/graphql_collector.go b/backend/helpers/pluginhelper/api/graphql_collector.go index a41eef950e6..d0adbbabb54 100644 --- a/backend/helpers/pluginhelper/api/graphql_collector.go +++ b/backend/helpers/pluginhelper/api/graphql_collector.go @@ -90,7 +90,7 @@ type GraphqlCollector struct { workerErrors []error } -// ErrFinishCollect is a error which will finish this collector +// ErrFinishCollect is an error which will finish this collector var ErrFinishCollect = errors.Default.New("finish collect") // NewGraphqlCollector allocates a new GraphqlCollector with the given args. diff --git a/backend/plugins/zentao/models/task.go b/backend/plugins/zentao/models/task.go index 494d64aa910..e5d9d14fed2 100644 --- a/backend/plugins/zentao/models/task.go +++ b/backend/plugins/zentao/models/task.go @@ -75,7 +75,7 @@ type ZentaoTaskRes struct { V1 string `json:"v1"` V2 string `json:"v2"` Vision string `json:"vision"` - StoryID int64 `json:"storyID"` + StoryID *common.StringInt64 `json:"storyID"` StoryTitle string `json:"storyTitle"` Branch interface { } `json:"branch"`