Commit 5232ac11 authored by shajiaiming's avatar shajiaiming

入参验证

parent 371d62e7
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bwallet/validate_service" "bwallet/validate_service"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strconv"
"strings" "strings"
) )
...@@ -90,41 +91,67 @@ func AddWalletCoinRelationCoinRelation(c *gin.Context) { ...@@ -90,41 +91,67 @@ func AddWalletCoinRelationCoinRelation(c *gin.Context) {
} }
} }
coinService := coin_service.Coin{ for _, id := range strings.Split(coin_relation.CoinId, ",") {
Id: coin_relation.CoinId, if id == "" {
} continue
exists, err := coinService.ExistById() }
if err != nil { coin_id, err := strconv.Atoi(id)
handler.SendResponse(c, errno.ErrCoinNotFound, nil) if (nil != err) {
return continue
} }
if !exists { coinService := coin_service.Coin{
handler.SendResponse(c, errno.ErrCoinNotFound, nil) Id: coin_id,
return }
exists, err := coinService.ExistById()
if err != nil || !exists {
continue
}
relationService := wallet_coin_relation_service.WalletCoinRelation{
PlatformId: coin_relation.PlatformId,
CoinId: coin_id,
}
relationService.Delete()
relationService.Add()
} }
relationService := wallet_coin_relation_service.WalletCoinRelation{ handler.SendResponse(c, nil, nil)
CoinId: coin_relation.CoinId, /*
PlatformId: coin_relation.PlatformId, coinService := coin_service.Coin{
PageNum: util.GetPage(c), Id: coin_relation.CoinId,
PageSize: util.GetLimit(c), }
} exists, err := coinService.ExistById()
if err != nil {
handler.SendResponse(c, errno.ErrCoinNotFound, nil)
return
}
if !exists {
handler.SendResponse(c, errno.ErrCoinNotFound, nil)
return
}
coins, err := relationService.GetAll() relationService := wallet_coin_relation_service.WalletCoinRelation{
if err != nil { CoinId: coin_relation.CoinId,
handler.SendResponse(c, errno.InternalServerError, nil) PlatformId: coin_relation.PlatformId,
return PageNum: util.GetPage(c),
} PageSize: util.GetLimit(c),
if 0 != len(coins) { }
handler.SendResponse(c, errno.ErrExistCoin, nil)
return
}
if err := relationService.Add(); err != nil { coins, err := relationService.GetAll()
handler.SendResponse(c, errno.ErrAddCoin, nil) if err != nil {
return handler.SendResponse(c, errno.InternalServerError, nil)
} return
handler.SendResponse(c, nil, nil) }
if 0 != len(coins) {
handler.SendResponse(c, errno.ErrExistCoin, nil)
return
}
if err := relationService.Add(); err != nil {
handler.SendResponse(c, errno.ErrAddCoin, nil)
return
}
handler.SendResponse(c, nil, nil)
*/
} }
/** /**
......
...@@ -3,8 +3,6 @@ package coin_service ...@@ -3,8 +3,6 @@ package coin_service
import ( import (
"bwallet/models" "bwallet/models"
"encoding/json" "encoding/json"
//"encoding/json"
) )
type Coin struct { type Coin struct {
......
...@@ -5,20 +5,20 @@ import "encoding/json" ...@@ -5,20 +5,20 @@ import "encoding/json"
type Coin struct { type Coin struct {
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
Nickname json.RawMessage `json:"nickname" validate:"required"` Nickname json.RawMessage `json:"nickname" validate:"required"`
Icon string `json:"icon" validate:"required"` Icon string `json:"icon" validate:"omitempty"` //
Introduce json.RawMessage `json:"introduce" validate:"required"` Introduce json.RawMessage `json:"introduce" validate:"omitempty"` //
Official string `json:"official" validate:"required"` Official string `json:"official" validate:"omitempty"` //
Paper string `json:"paper" validate:"required"` Paper string `json:"paper" validate:"omitempty"` //
Platform string `json:"platform" validate:"required"` Platform string `json:"platform" validate:"required"`
Chain string `json:"chain" validate:"required"` Chain string `json:"chain" validate:"required"`
Release string `json:"release" validate:"required"` Release string `json:"release" validate:"omitempty"` //
AreaSearch string `json:"area_search" validate:"required"` AreaSearch string `json:"area_search" validate:"omitempty"` //
PublishCount float64 `json:"publish_count" validate:"required"` PublishCount float64 `json:"publish_count" validate:"omitempty"` //
CirculateCount float64 `json:"circulate_count" validate:"required"` CirculateCount float64 `json:"circulate_count" validate:"omitempty"` //
Decimals int `json:"decimals" validate:"required"` Decimals int `json:"decimals" validate:"required"`
Address string `json:"address" validate:"required"` Address string `json:"address" validate:"omitempty"` //
Treaty int `json:"treaty" validate:"required"` Treaty int `json:"treaty" validate:"required"`
PlatformId int `json:"platform_id" validate:"required"` PlatformId int `json:"platform_id" validate:"required"`
......
package validate_service package validate_service
type WalletCoinRelateion struct { type WalletCoinRelateion struct {
CoinId int `json:"coin_id" validate:"required"` CoinId string `json:"coin_id" validate:"required"`
PlatformId int `json:"platform_id" validate:"required"` PlatformId int `json:"platform_id" validate:"required"`
} }
type DeleteWalletCoinRelateion struct { type DeleteWalletCoinRelateion 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