4444
This commit is contained in:
parent
2a8869d4b2
commit
f66baa9dea
@ -7,6 +7,7 @@ import (
|
|||||||
"hepa-calc-api/api/service"
|
"hepa-calc-api/api/service"
|
||||||
"hepa-calc-api/global"
|
"hepa-calc-api/global"
|
||||||
"hepa-calc-api/utils"
|
"hepa-calc-api/utils"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Public struct{}
|
type Public struct{}
|
||||||
@ -52,7 +53,29 @@ func (b *Public) GetPhoneCode(c *gin.Context) {
|
|||||||
|
|
||||||
// GetIndex 获取首页数据
|
// GetIndex 获取首页数据
|
||||||
func (b *Public) GetIndex(c *gin.Context) {
|
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{}
|
publicService := service.PublicService{}
|
||||||
g, err := publicService.GetIndex(userId)
|
g, err := publicService.GetIndex(userId)
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package requests
|
|||||||
type PublicRequest struct {
|
type PublicRequest struct {
|
||||||
GetPhoneCode // 获取手机验证码
|
GetPhoneCode // 获取手机验证码
|
||||||
GetOssSign // 获取oss签名
|
GetOssSign // 获取oss签名
|
||||||
|
GetIndex // 获取首页数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhoneCode 获取手机验证码
|
// GetPhoneCode 获取手机验证码
|
||||||
@ -15,3 +16,8 @@ type GetPhoneCode struct {
|
|||||||
type GetOssSign struct {
|
type GetOssSign struct {
|
||||||
Scene int `json:"scene" form:"scene" validate:"required,oneof=1 2 3 4" label:"场景"` // (1:头像)
|
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:"用户标识"`
|
||||||
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"hepa-calc-api/api/dao"
|
"hepa-calc-api/api/dao"
|
||||||
"hepa-calc-api/api/model"
|
"hepa-calc-api/api/model"
|
||||||
@ -49,6 +50,7 @@ func (r *QuestionService) GetGuessUserLIkeList(userId int64) (m []*model.Questio
|
|||||||
|
|
||||||
var questions []*model.Question
|
var questions []*model.Question
|
||||||
|
|
||||||
|
fmt.Println(userId)
|
||||||
if userId != 0 {
|
if userId != 0 {
|
||||||
maps := make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
maps["user_id"] = userId
|
maps["user_id"] = userId
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user