Commit 2f53a119 authored by shajiaming's avatar shajiaming

fix

parent 81c137f5
......@@ -74,6 +74,7 @@ var (
ErrDeleteCoin = &Errno{Code: 20102, Message: "The coin delete error."}
ErrExistCoin = &Errno{Code: 20103, Message: "The coin already exists."}
ErrNotExistCoin = &Errno{Code: 20104, Message: "The coin not exists."}
ErrAuthCoin = &Errno{Code: 20105, Message: "The coin auth error."}
// recommend coin errors
ErrRecommendCoinNotFound = &Errno{Code: 20101, Message: "The recommend coin was not found."}
......
......@@ -51,6 +51,17 @@ func GetCoin(c *gin.Context) {
}
func GetCoins(c *gin.Context) {
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
valid := validation.Validation{}
name := ""
......@@ -68,19 +79,12 @@ func GetCoins(c *gin.Context) {
chain = c.Query("chain")
}
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
var platform_id int
platform_id = auth.PlatformId
if ("administrator" == group) {
if arg := c.Query("platform_id"); arg != "" {
platform_id = com.StrTo(c.Query("platform_id")).MustInt()
}
if arg := c.Query("platform_id"); arg != "" {
platform_id = com.StrTo(c.DefaultQuery("platform_id", "1")).MustInt()
}
if valid.HasErrors() {
handler.SendResponse(c, errno.ErrValidation, nil)
return
......@@ -115,6 +119,16 @@ func GetCoins(c *gin.Context) {
}
func AddCoin(c *gin.Context) {
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
coin := validate_service.Coin{}
c.ShouldBindJSON(&coin)
//方法一
......@@ -125,19 +139,6 @@ func AddCoin(c *gin.Context) {
}
}
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
var platform_id int
platform_id = auth.PlatformId
if ("administrator" == group) {
if coin.PlatformId != 0 {
platform_id = coin.PlatformId
}
}
coinService := coin_service.Coin{
Sid: coin.Sid,
Name: coin.Name,
......@@ -155,7 +156,7 @@ func AddCoin(c *gin.Context) {
Decimals: coin.Decimals,
Address: coin.Address,
Treaty: coin.Treaty,
PlatformId: platform_id,
PlatformId: coin.PlatformId,
}
if err := coinService.Add(); err != nil {
......@@ -212,9 +213,15 @@ func EditCoin(c *gin.Context) {
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
coin_model := coin_service.Coin{Id: coin.Id}
coin_exist, _ := coin_model.Get()
if coin.PlatformId != coin_exist.PlatformId {
handler.SendResponse(c, errno.ErrAuthCoin, nil)
return
}
if ("administrator" != group) {
coin_model := coin_service.Coin{Id: coin.Id}
coin, _ := coin_model.Get()
if coin.PlatformId != auth.PlatformId {
handler.SendResponse(c, errno.ErrUserTokenIncorrect, nil)
return
......@@ -229,6 +236,17 @@ func EditCoin(c *gin.Context) {
}
func DeleteCoin(c *gin.Context) {
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
valid := validation.Validation{}
id := com.StrTo(c.Param("id")).MustInt()
valid.Min(id, 1, "id").Message("ID必须大于0")
......@@ -250,18 +268,6 @@ func DeleteCoin(c *gin.Context) {
return
}
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
coin, _ := coinService.Get()
if coin.PlatformId != auth.PlatformId {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
}
err = coinService.Delete()
if err != nil {
handler.SendResponse(c, errno.ErrDeleteCoin, nil)
......
......@@ -51,14 +51,6 @@ func GetWalletCoinRelationCoinRelations(c *gin.Context) {
PageSize: util.GetLimit(c),
}
/*
_, err := walletCoinRelateionService.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil)
return
}
*/
coins, err := walletCoinRelateionService.GetAll()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
......
......@@ -29,13 +29,17 @@ func InitRouter() *gin.Engine {
{
//api.POST("/upload",v1.Upload)
api.GET("/coins", v1.GetWalletCoinRelationCoinRelations)
api.POST("/coin", v1.AddWalletCoinRelationCoinRelation)
api.GET("/coins", v1.GetCoins)
api.POST("/coin", v1.AddCoin)
api.GET("/coin/:id", v1.GetCoin)
api.PUT("/coin", v1.EditCoin)
api.DELETE("/coin", v1.DeleteWalletCoinRelationCoinRelation)
api.DELETE("/coin/:id", v1.DeleteCoin)
api.GET("/primary-chains", v1.GetPrimaryChains)
api.GET("/types", v1.GetTypes)
api.GET("/coin-relation", v1.GetWalletCoinRelationCoinRelations)
api.POST("/coin-relation", v1.AddWalletCoinRelationCoinRelation)
api.DELETE("/coin-relation", v1.DeleteWalletCoinRelationCoinRelation)
//api.GET("/get-platform", v1.GetCoinsPlatform)
api.GET("/wallets", v1.GetWallets)
......
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