package version

import (
	"fonchain-fiee/pkg/cache"
	"fonchain-fiee/pkg/model/query"
	"fonchain-fiee/pkg/model/vo"
	"fonchain-fiee/pkg/service"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

func Version(c *gin.Context) {

	var req query.VersionQuery

	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error(c, err)
		return
	}

	val, _ := cache.RedisClient.Get("app:version:" + req.AppName).Result()
	if val == "" {
		val = "1.0.0"
		cache.RedisClient.Set("app:version:"+req.AppName, val, 0)
	}

	service.Success(c, vo.VersionVo{Version: val})
	return

}
