This commit is contained in:
2024-09-19 14:39:18 +08:00
parent 2a8869d4b2
commit f66baa9dea
3 changed files with 32 additions and 1 deletions
+24 -1
View File
@@ -7,6 +7,7 @@ import (
"hepa-calc-api/api/service"
"hepa-calc-api/global"
"hepa-calc-api/utils"
"strconv"
)
type Public struct{}
@@ -52,7 +53,29 @@ func (b *Public) GetPhoneCode(c *gin.Context) {
// GetIndex 获取首页数据
func (b *Public) GetIndex(c *gin.Context) {
userId := c.GetInt64("UserId") // 用户id
publicRequest := requests.PublicRequest{}
req := publicRequest.GetIndex
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
var userId int64
if req.UserId != "" {
// 将 id 转换为 int64 类型
var err error
userId, err = strconv.ParseInt(req.UserId, 10, 64)
if err != nil {
responses.Fail(c)
return
}
}
publicService := service.PublicService{}
g, err := publicService.GetIndex(userId)