package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type GetBasicProfileLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetBasicProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBasicProfileLogic { return &GetBasicProfileLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GetBasicProfileLogic) GetBasicProfile() (resp *types.HealthProfile, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } var profile model.HealthProfile if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&profile).Error; err != nil { return nil, errorx.NewCodeError(errorx.CodeNotFound, "健康档案不存在") } birthDate := "" if profile.BirthDate != nil { birthDate = profile.BirthDate.Format("2006-01-02") } return &types.HealthProfile{ ID: uint(profile.ID), UserID: profile.UserID, Name: profile.Name, BirthDate: birthDate, Gender: profile.Gender, Height: profile.Height, Weight: profile.Weight, BMI: profile.BMI, BloodType: profile.BloodType, Occupation: profile.Occupation, MaritalStatus: profile.MaritalStatus, Region: profile.Region, }, nil }