Commit 3261dd3b authored by shajiaiming's avatar shajiaiming

fix bug

parent 94fa7036
...@@ -36,6 +36,7 @@ func Setup() error { ...@@ -36,6 +36,7 @@ func Setup() error {
return nil return nil
} }
//设置指定 key 的值
func Set(key string, data interface{}, time int, db int) error { func Set(key string, data interface{}, time int, db int) error {
conn := RedisConn.Get() conn := RedisConn.Get()
defer conn.Close() defer conn.Close()
...@@ -63,6 +64,24 @@ func Set(key string, data interface{}, time int, db int) error { ...@@ -63,6 +64,24 @@ func Set(key string, data interface{}, time int, db int) error {
return nil return nil
} }
//获取指定 key 的值
func Get(key string, db int) ([]byte, error) {
conn := RedisConn.Get()
defer conn.Close()
if _, err := conn.Do("SELECT", db); err != nil {
conn.Close()
return nil, err
}
reply, err := redis.Bytes(conn.Do("GET", key))
if err != nil {
return nil, err
}
return reply, nil
}
func Exists(key string, db int) bool { func Exists(key string, db int) bool {
conn := RedisConn.Get() conn := RedisConn.Get()
defer conn.Close() defer conn.Close()
...@@ -80,7 +99,31 @@ func Exists(key string, db int) bool { ...@@ -80,7 +99,31 @@ func Exists(key string, db int) bool {
return exists return exists
} }
func Get(key string, db int) ([]byte, error) { //向有序集合添加一个或多个成员,或者更新已存在成员的分数
func ZAdd(key string, score int, data interface{}, db int) error {
conn := RedisConn.Get()
defer conn.Close()
value, err := json.Marshal(data)
if err != nil {
return err
}
if _, err := conn.Do("SELECT", db); err != nil {
conn.Close()
return err
}
_, err = conn.Do("ZADD", key, score, value)
if err != nil {
return err
}
return nil
}
//通过索引区间返回有序集合指定区间内的成员
func ZRange(key string, start, stop int, db int) ([]string, error) {
conn := RedisConn.Get() conn := RedisConn.Get()
defer conn.Close() defer conn.Close()
...@@ -89,12 +132,12 @@ func Get(key string, db int) ([]byte, error) { ...@@ -89,12 +132,12 @@ func Get(key string, db int) ([]byte, error) {
return nil, err return nil, err
} }
reply, err := redis.Bytes(conn.Do("GET", key)) rep, err := redis.Strings(conn.Do("ZRANGE", key, start, stop))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return reply, nil return rep, nil
} }
func Delete(key string, db int) (bool, error) { func Delete(key string, db int) (bool, error) {
...@@ -107,4 +150,4 @@ func Delete(key string, db int) (bool, error) { ...@@ -107,4 +150,4 @@ func Delete(key string, db int) (bool, error) {
} }
return redis.Bool(conn.Do("DEL", key)) return redis.Bool(conn.Do("DEL", key))
} }
\ No newline at end of file
package app
import (
"bwallet/pkg/errno"
"bwallet/pkg/gredis"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/news_service"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
)
func GetOneNews(c *gin.Context) {
//gredis.ZAdd("sorted_set", 2020716, "二零二零零七一六", 3)
//gredis.ZAdd("sorted_set", 2020718, "二零二零零七一八", 3)
//gredis.ZAdd("sorted_set", 2020719, "二零二零零七一九", 3)
//gredis.ZAdd("sorted_set", 2020717, "二零二零零七一七", 3)
fmt.Println(gredis.ZRange("sorted_set", 1, 4, 3))
}
func GetNews(c *gin.Context) {
platform_id, _ := strconv.Atoi(c.Request.Header.Get("FZM-PLATFORM-ID"))
newsService := news_service.News{
PlatformId: platform_id,
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
}
total, err := newsService.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountNews, nil)
return
}
news, err := newsService.GetAll()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
return
}
data := make(map[string]interface{})
data["items"] = news
data["total"] = total
handler.SendResponse(c, nil, data)
}
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/app" "bwallet/pkg/app"
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"bwallet/pkg/util" "bwallet/pkg/util"
"bwallet/service/auth_service" "bwallet/service/auth_service"
"bwallet/service/coin_service" "bwallet/service/coin_service"
"bwallet/service/platform_chain_service"
"bwallet/service/recommend_coin_service" "bwallet/service/recommend_coin_service"
"bwallet/service/trusteeship_coin_service" "bwallet/service/trusteeship_coin_service"
"bwallet/validate_service" "bwallet/validate_service"
...@@ -56,55 +55,7 @@ func GetCoin(c *gin.Context) { ...@@ -56,55 +55,7 @@ func GetCoin(c *gin.Context) {
return return
} }
func GetUserChainsBak(c *gin.Context) {
data := make(map[string]interface{})
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
coinService := coin_service.Coin{}
if ("administrator" != group) {
platformChainService := platform_chain_service.PlatformChain{
PlatformId: auth.PlatformId,
IsPrimary: 1,
}
platform_chain, err := platformChainService.GetAll()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
return
}
var platform string
for _, val := range platform_chain {
if nil != val.ChainInfo {
platform = val.ChainInfo.Platform
}
}
if "" == platform {
data["items"] = nil
data["total"] = 0
handler.SendResponse(c, nil, data)
return
}
coinService.Platform = platform
}
platforms, err := coinService.GetAllPlatform()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
return
}
data["items"] = platforms
data["total"] = len(platforms)
handler.SendResponse(c, nil, data)
}
func GetCoins(c *gin.Context) { func GetCoins(c *gin.Context) {
//gredis.Set("2020716", "二零二零零七一六", 20, 1)
valid := validation.Validation{} valid := validation.Validation{}
name := "" name := ""
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
package v1 package backend
import ( import (
"bwallet/pkg/errno" "bwallet/pkg/errno"
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"bwallet/middleware/auth" "bwallet/middleware/auth"
"bwallet/pkg/upload" "bwallet/pkg/upload"
"bwallet/routers/api" "bwallet/routers/api/app"
"bwallet/routers/api/v1" "bwallet/routers/api/backend"
"net/http" "net/http"
) )
...@@ -22,77 +22,80 @@ func InitRouter() *gin.Engine { ...@@ -22,77 +22,80 @@ func InitRouter() *gin.Engine {
r.StaticFS("/upload/file", http.Dir(upload.GetFileFullPath())) r.StaticFS("/upload/file", http.Dir(upload.GetFileFullPath()))
//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath())) //r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))
r.POST("/auth", api.GetAuth) //r.POST("/auth", api.GetAuth)
r.POST("/upload", api.UploadFile) //r.POST("/upload", api.UploadFile)
//r.POST("/upload", api.UploadImage) //r.POST("/upload", api.UploadImage)
client := r.Group("/interface")
client.GET("/news", app.GetNews)
client.GET("/one-news", app.GetOneNews)
api := r.Group("/api") api := r.Group("/api")
api.Use(auth.AUTH()) api.Use(auth.AUTH())
api.POST("/log", v1.AddOperationLog) api.POST("/log", backend.AddOperationLog)
api.GET("/logs", v1.GetOperationLogs) api.GET("/logs", backend.GetOperationLogs)
api.Use(log.LogMiddleware(e.HandleTableName)) api.Use(log.LogMiddleware(e.HandleTableName))
{ {
//api.POST("/upload",v1.Upload) //api.POST("/upload",backend.Upload)
api.GET("/coins", backend.GetCoins)
api.GET("/coins", v1.GetCoins) api.POST("/coin", backend.AddCoin)
api.POST("/coin", v1.AddCoin) api.GET("/coin", backend.GetCoin)
api.GET("/coin", v1.GetCoin) api.PUT("/coin", backend.EditCoin)
api.PUT("/coin", v1.EditCoin) api.DELETE("/coin", backend.DeleteCoin)
api.DELETE("/coin", v1.DeleteCoin) api.GET("/primary-chains", backend.GetCoinChains)
api.GET("/primary-chains", v1.GetCoinChains) api.GET("/types", backend.GetTypes)
api.GET("/types", v1.GetTypes)
api.GET("/coin-relation", backend.GetWalletCoinRelationCoinRelations)
api.GET("/coin-relation", v1.GetWalletCoinRelationCoinRelations) api.POST("/coin-relation", backend.AddWalletCoinRelationCoinRelation)
api.POST("/coin-relation", v1.AddWalletCoinRelationCoinRelation) api.DELETE("/coin-relation", backend.DeleteWalletCoinRelationCoinRelation)
api.DELETE("/coin-relation", v1.DeleteWalletCoinRelationCoinRelation) //api.GET("/get-platform", backend.GetCoinsPlatform)
//api.GET("/get-platform", v1.GetCoinsPlatform)
api.GET("/wallets", backend.GetWallets)
api.GET("/wallets", v1.GetWallets) api.POST("/wallet", backend.AddWallet)
api.POST("/wallet", v1.AddWallet) api.GET("/wallet", backend.GetWallet)
api.GET("/wallet", v1.GetWallet) api.PUT("/wallet", backend.EditWallet)
api.PUT("/wallet", v1.EditWallet) api.DELETE("/wallet", backend.DeleteWallet)
api.DELETE("/wallet", v1.DeleteWallet)
api.GET("/news", backend.GetNews)
api.GET("/news", v1.GetNews) api.POST("/news", backend.AddNews)
api.POST("/news", v1.AddNews) api.GET("/one-news", backend.GetOneNews)
api.GET("/one-news", v1.GetOneNews) api.PUT("/news", backend.EditNews)
api.PUT("/news", v1.EditNews) api.DELETE("/news", backend.DeleteNews)
api.DELETE("/news", v1.DeleteNews)
api.GET("/chains", backend.GetChains)
api.GET("/chains", v1.GetChains) api.POST("/chain", backend.AddChain)
api.POST("/chain", v1.AddChain) api.GET("/chain", backend.GetChain)
api.GET("/chain", v1.GetChain) api.PUT("/chain", backend.EditChain)
api.PUT("/chain", v1.EditChain) api.DELETE("/chain", backend.DeleteChain)
api.DELETE("/chain", v1.DeleteChain) api.GET("/user-chains", backend.GetUserChains)
api.GET("/user-chains", v1.GetUserChains)
api.GET("/recommend-categories", backend.GetWalletRecommendCategories)
api.GET("/recommend-categories", v1.GetWalletRecommendCategories) api.POST("/recommend-category", backend.AddWalletRecommendCategory)
api.POST("/recommend-category", v1.AddWalletRecommendCategory) api.GET("/recommend-category", backend.GetWalletRecommendCategory)
api.GET("/recommend-category", v1.GetWalletRecommendCategory) api.DELETE("/recommend-category", backend.DeleteWalletRecommendCategory)
api.DELETE("/recommend-category", v1.DeleteWalletRecommendCategory) api.PUT("/recommend-category", backend.EditWalletRecommendCategory)
api.PUT("/recommend-category", v1.EditWalletRecommendCategory)
api.GET("/recommend-coins", backend.GetRecommendCoins)
api.GET("/recommend-coins", v1.GetRecommendCoins) api.POST("/recommend-coin", backend.AddRecommendCoin)
api.POST("/recommend-coin", v1.AddRecommendCoin) api.PUT("/recommend-coin", backend.EditRecommendCoin)
api.PUT("/recommend-coin", v1.EditRecommendCoin) api.DELETE("/recommend-coin", backend.DeleteRecommendCoin)
api.DELETE("/recommend-coin", v1.DeleteRecommendCoin)
api.GET("/trusteeship-coins", backend.GetTrusteeshipCoins)
api.GET("/trusteeship-coins", v1.GetTrusteeshipCoins) api.POST("/trusteeship-coin", backend.AddTrusteeshipCoin)
api.POST("/trusteeship-coin", v1.AddTrusteeshipCoin) api.PUT("/trusteeship-coin", backend.EditTrusteeshipCoin)
api.PUT("/trusteeship-coin", v1.EditTrusteeshipCoin) api.DELETE("/trusteeship-coin", backend.DeleteTrusteeshipCoin)
api.DELETE("/trusteeship-coin", v1.DeleteTrusteeshipCoin)
api.GET("/supported-currencies", backend.GetSupportedCurrencies)
api.GET("/supported-currencies", v1.GetSupportedCurrencies) api.POST("/supported-currency", backend.AddSupportedCurrency)
api.POST("/supported-currency", v1.AddSupportedCurrency) api.GET("/supported-currency", backend.GetSupportedCurrency)
api.GET("/supported-currency", v1.GetSupportedCurrency) api.PUT("/supported-currency", backend.EditSupportedCurrency)
api.PUT("/supported-currency", v1.EditSupportedCurrency) api.DELETE("/supported-currency", backend.DeleteSupportedCurrency)
api.DELETE("/supported-currency", v1.DeleteSupportedCurrency) api.GET("/currencies", backend.GetCurrencies)
api.GET("/currencies", v1.GetCurrencies)
api.GET("/supported-chains", backend.GetSupportedChains)
api.GET("/supported-chains", v1.GetSupportedChains) api.POST("/supported-chain", backend.AddSupportedChain)
api.POST("/supported-chain", v1.AddSupportedChain) api.DELETE("/supported-chain", backend.DeleteSupportedChain)
api.DELETE("/supported-chain", v1.DeleteSupportedChain)
} }
return r return r
......
package validate_service package validate_service
type News struct { type News struct {
Title string `json:"title" validate:"requihighlight"` Title string `json:"title" validate:"required"`
Content string `json:"content" validate:"requihighlight"` Content string `json:"content" validate:"required"`
Top uint8 `json:"top"` Top uint8 `json:"top"`
Highlight uint8 `json:"highlight"` Highlight uint8 `json:"highlight"`
Status uint8 `json:"status"` Status uint8 `json:"status"`
PlatformId int `json:"platform_id" validate:"requihighlight"` PlatformId int `json:"platform_id"`
} }
type EditNews struct { type EditNews struct {
News News
Id int `json:"id" validate:"requihighlight"` Id int `json:"id" validate:"required"`
} }
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