You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetRecommendationsLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetRecommendationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommendationsLogic {
|
|
return &GetRecommendationsLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetRecommendationsLogic) GetRecommendations() (resp *types.RecommendationsResp, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
var assessment model.ConstitutionAssessment
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).Order("assessed_at DESC").First(&assessment).Error; err != nil {
|
|
return nil, errorx.NewCodeError(errorx.CodeNotFound, "暂无体质测评记录")
|
|
}
|
|
|
|
var recommendations map[string]string
|
|
json.Unmarshal([]byte(assessment.Recommendations), &recommendations)
|
|
|
|
return &types.RecommendationsResp{
|
|
Constitution: assessment.PrimaryConstitution,
|
|
Recommendations: recommendations,
|
|
}, nil
|
|
}
|
|
|