This commit is contained in:
wucongxing8150 2024-09-19 14:39:18 +08:00
parent 2a8869d4b2
commit f66baa9dea
3 changed files with 32 additions and 1 deletions

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)

View File

@ -3,6 +3,7 @@ package requests
type PublicRequest struct {
GetPhoneCode // 获取手机验证码
GetOssSign // 获取oss签名
GetIndex // 获取首页数据
}
// GetPhoneCode 获取手机验证码
@ -15,3 +16,8 @@ type GetPhoneCode struct {
type GetOssSign struct {
Scene int `json:"scene" form:"scene" validate:"required,oneof=1 2 3 4" label:"场景"` // 1:头像)
}
// GetIndex 获取首页数据
type GetIndex struct {
UserId string `json:"user_id" form:"user_id" label:"用户标识"`
}

View File

@ -2,6 +2,7 @@ package service
import (
"errors"
"fmt"
"gorm.io/gorm"
"hepa-calc-api/api/dao"
"hepa-calc-api/api/model"
@ -49,6 +50,7 @@ func (r *QuestionService) GetGuessUserLIkeList(userId int64) (m []*model.Questio
var questions []*model.Question
fmt.Println(userId)
if userId != 0 {
maps := make(map[string]interface{})
maps["user_id"] = userId