4444
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user