Commit d4fc50ed authored by shajiaiming's avatar shajiaiming

添加平台时唯一验证

parent 1e906084
......@@ -97,6 +97,7 @@ var (
ErrAddChain = &Errno{Code: 20101, Message: "The chain add error."}
ErrUpdateChain = &Errno{Code: 20102, Message: "The chain update error."}
ErrDeleteChain = &Errno{Code: 20102, Message: "The chain delete error."}
ErrExistChain = &Errno{Code: 20103, Message: "The chain already exists."}
// supported currency errors
ErrSupportedCurrencyNotFound = &Errno{Code: 20101, Message: "The supported currency was not found."}
......
......@@ -147,6 +147,12 @@ func AddChain(c *gin.Context) {
Lock: chain.Lock,
}
count, err := chainService.Count()
if err != nil || count > 0 {
handler.SendResponse(c, errno.ErrExistChain, nil)
return
}
if err := chainService.Add(); err != nil {
handler.SendResponse(c, errno.ErrAddChain, nil)
return
......
......@@ -99,5 +99,9 @@ func (c *Chain) getMaps() (map[string]interface{}) {
maps["id"] = c.ID
}
if c.Platform != "" {
maps["platform"] = c.Platform
}
return maps
}
......@@ -8,7 +8,7 @@ type Chain struct {
Token string `json:"token" validate:"omitempty"`
Fee float32 `json:"fee" validate:"omitempty"`
BrowerUrl string `json:"brower_url" validate:"omitempty,url"`
Lock int `json:"lock" validate:"omitempty"`
Lock int `json:"lock" validate:"min=1,max=2"`
}
type EditChain struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment