Commit 2f53a119 authored by shajiaming's avatar shajiaming

fix

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